Skip to content

Fix refraction tile artifacts near reflection probe edges #4727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 13, 2021
Merged
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed Dof and MSAA. DoF is now using the min depth of the per-pixel MSAA samples when MSAA is enabled. This removes 1-pixel ringing from in focus objects (case 1347291).
- Fixed objects disappearing from Lookdev window when entering playmode (case 1309368).
- Fixed rendering of objects just after the TAA pass (before post process injection point).
- Fixed tiled artifacts in refraction at borders between two reflection probes.

### Changed
- Changed Window/Render Pipeline/HD Render Pipeline Wizard to Window/Rendering/HDRP Wizard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,21 +349,46 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BS
}
#endif

EnvLightData envLightData;
if (envLightCount > 0)
{
envLightData = FetchEnvLight(envLightStart, 0);
}
else
{
envLightData = InitSkyEnvLightData(0);
}
#if HAS_REFRACTION

// For refraction to be stable, we should reuse the same refraction probe for the whole object.
// Otherwise as if the object span different tiles it could produce a different refraction probe picking and thus have visual artifacts.
// For this we need to find the tile that is at the center of the object that is being rendered.
// And then select the first refraction probe of this list.
if ((featureFlags & LIGHTFEATUREFLAGS_SSREFRACTION) && (_EnableSSRefraction > 0))
{
// grab current object position and retrieve in which tile it belongs too
float4x4 modelMat = GetObjectToWorldMatrix();
float3 objPos = modelMat._m03_m13_m23;
float4 posClip = TransformWorldToHClip(objPos);
posClip.xyz = posClip.xyz / posClip.w;

uint2 tileObj = (saturate(posClip.xy * 0.5f + 0.5f) * _ScreenSize.xy) / GetTileSize();

uint envLightStart, envLightCount;

// Fetch first env light to provide the scene proxy for screen space refraction computation
PositionInputs localInput;
ZERO_INITIALIZE(PositionInputs, localInput);
localInput.tileCoord = tileObj.xy;
localInput.linearDepth = posClip.w;

GetCountAndStart(localInput, LIGHTCATEGORY_ENV, envLightStart, envLightCount);

EnvLightData envLightData;
if (envLightCount > 0)
{
envLightData = FetchEnvLight(FetchIndex(envLightStart, 0));
}
else // If no refraction probe, use sky
{
envLightData = InitSkyEnvLightData(0);
}

IndirectLighting lighting = EvaluateBSDF_ScreenspaceRefraction(context, V, posInput, preLightData, bsdfData, envLightData, refractionHierarchyWeight);
AccumulateIndirectLighting(lighting, aggregateLighting);
}
#endif

// Reflection probes are sorted by volume (in the increasing order).
if (featureFlags & LIGHTFEATUREFLAGS_ENV)
Expand Down