Skip to content

Commit

Permalink
[2021.2] Fixing a shadow artefact on Terrain Detail objects (#4447)
Browse files Browse the repository at this point in the history
* Fixing a shadow artefact on Terrain Detail objects

* Removing extra code that got accidentally added

* Variable name fix
  • Loading branch information
ellioman committed May 27, 2021
1 parent 1780d03 commit 5267385
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
1 change: 1 addition & 0 deletions com.unity.render-pipelines.universal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed shaderGraph shaders to render into correct depthNormals passes when deferred rendering mode and SSAO are enabled.
- Fixed ordering of subshaders in the Unlit Shader Graph, such that shader target 4.5 takes priority over 2.0. [case 1328636](https://issuetracker.unity3d.com/product/unity/issues/guid/1328636/)
- Fixed issue where it will clear camera color if post processing is happening on XR [case 1324451]
- Fixed an issue where shadow artefacts appeared between cascades on Terrain Detail objects.

### Changed
- Change Asset/Create/Shader/Universal Render Pipeline/Lit Shader Graph to Asset/Create/Shader Graph/URP/Lit Shader Graph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ struct Varyings
DECLARE_LIGHTMAP_OR_SH(staticLightmapUV, vertexSH, 1);
half4 Color : TEXCOORD2; // Vertex Color
half4 LightingFog : TEXCOORD3; // Vertex Lighting, Fog Factor
#if defined(MAIN_LIGHT_CALCULATE_SHADOWS)
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
float4 ShadowCoords : TEXCOORD4; // Shadow UVs
#endif
half4 NormalWS : TEXCOORD5;
#if defined(DEBUG_DISPLAY)
float3 positionWS : TEXCOORD6;
#endif
float3 PositionWS : TEXCOORD6;
float4 PositionCS : SV_POSITION; // Clip Position

UNITY_VERTEX_INPUT_INSTANCE_ID
Expand All @@ -39,19 +37,23 @@ void InitializeInputData(Varyings input, out InputData inputData)
inputData.positionCS = input.PositionCS;
inputData.normalWS = half3(0, 1, 0);
inputData.viewDirectionWS = half3(0, 0, 1);
#if defined(MAIN_LIGHT_CALCULATE_SHADOWS)
inputData.shadowCoord = input.ShadowCoords;

#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
inputData.shadowCoord = input.shadowCoord;
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
inputData.shadowCoord = TransformWorldToShadowCoord(input.PositionWS);
#else
inputData.shadowCoord = float4(0, 0, 0, 0);
inputData.shadowCoord = float4(0, 0, 0, 0);
#endif

inputData.fogCoord = input.LightingFog.a;
inputData.vertexLighting = input.LightingFog.rgb;
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.vertexSH, input.NormalWS.xyz);
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.PositionCS);
inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
inputData.positionWS = input.PositionWS;

#if defined(DEBUG_DISPLAY)
inputData.positionWS = input.positionWS;
inputData.uv = input.UV01;
#endif
}
Expand Down Expand Up @@ -123,8 +125,8 @@ Varyings TerrainLitVertex(Attributes input)
output.PositionCS = vertexInput.positionCS;

// Shadow Coords
#if defined(MAIN_LIGHT_CALCULATE_SHADOWS)
output.ShadowCoords = GetShadowCoord(vertexInput);
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
output.ShadowCoords = GetShadowCoord(vertexInput);
#endif

// Vertex Lighting
Expand Down Expand Up @@ -158,10 +160,7 @@ Varyings TerrainLitVertex(Attributes input)
output.LightingFog.w = ComputeFogFactor(output.PositionCS.z);

output.NormalWS.xyz = NormalWS;

#if defined(DEBUG_DISPLAY)
output.positionWS = vertexInput.positionWS;
#endif
output.PositionWS = vertexInput.positionWS;

return output;
}
Expand Down

0 comments on commit 5267385

Please sign in to comment.