Skip to content

Commit 37b7639

Browse files
authored
Backport of Unity-Technologies/ScriptableRenderPipeline#6376 (#197)
1 parent 273b6e3 commit 37b7639

File tree

7 files changed

+41
-28
lines changed

7 files changed

+41
-28
lines changed

com.unity.render-pipelines.universal/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this package will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
9+
### Fixed
10+
- Fixed an issue with shadows not being correctly calculated in some shaders.
11+
712
## [8.1.0] - 2020-04-21
813

914
### Added

com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313
#elif _NORMAL_DROPOFF_WS
1414
inputData.normalWS = normal;
1515
#endif
16-
16+
1717
#else
1818
inputData.normalWS = input.normalWS;
1919
#endif
2020
inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
2121
inputData.viewDirectionWS = SafeNormalize(input.viewDirectionWS);
2222

23-
#if defined(MAIN_LIGHT_CALCULATE_SHADOWS)
23+
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
24+
inputData.shadowCoord = input.shadowCoord;
25+
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
2426
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
2527
#else
2628
inputData.shadowCoord = float4(0, 0, 0, 0);
@@ -40,8 +42,8 @@ PackedVaryings vert(Attributes input)
4042
return packedOutput;
4143
}
4244

43-
half4 frag(PackedVaryings packedInput) : SV_TARGET
44-
{
45+
half4 frag(PackedVaryings packedInput) : SV_TARGET
46+
{
4547
Varyings unpacked = UnpackVaryings(packedInput);
4648
UNITY_SETUP_INSTANCE_ID(unpacked);
4749
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked);
@@ -59,7 +61,7 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET
5961
#ifdef _SPECULAR_SETUP
6062
float3 specular = surfaceDescription.Specular;
6163
float metallic = 1;
62-
#else
64+
#else
6365
float3 specular = 0;
6466
float metallic = surfaceDescription.Metallic;
6567
#endif
@@ -72,8 +74,8 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET
7274
surfaceDescription.Smoothness,
7375
surfaceDescription.Occlusion,
7476
surfaceDescription.Emission,
75-
surfaceDescription.Alpha);
77+
surfaceDescription.Alpha);
7678

77-
color.rgb = MixFog(color.rgb, inputData.fogCoord);
79+
color.rgb = MixFog(color.rgb, inputData.fogCoord);
7880
return color;
7981
}

com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/Varyings.hlsl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ Varyings BuildVaryings(Attributes input)
1414
// Evaluate Vertex Graph
1515
VertexDescriptionInputs vertexDescriptionInputs = BuildVertexDescriptionInputs(input);
1616
VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
17-
17+
1818
// Assign modified vertex attributes
1919
input.positionOS = vertexDescription.VertexPosition;
2020
#if defined(VARYINGS_NEED_NORMAL_WS)
2121
input.normalOS = vertexDescription.VertexNormal;
22-
#endif //FEATURES_GRAPH_NORMAL
22+
#endif //FEATURES_GRAPH_NORMAL
2323
#if defined(VARYINGS_NEED_TANGENT_WS)
2424
input.tangentOS.xyz = vertexDescription.VertexTangent.xyz;
2525
#endif //FEATURES GRAPH TANGENT
@@ -51,7 +51,7 @@ Varyings BuildVaryings(Attributes input)
5151
#ifdef VARYINGS_NEED_POSITION_WS
5252
output.positionWS = positionWS;
5353
#endif
54-
54+
5555
#ifdef VARYINGS_NEED_NORMAL_WS
5656
output.normalWS = normalWS; // normalized in TransformObjectToWorldNormal()
5757
#endif
@@ -110,9 +110,9 @@ Varyings BuildVaryings(Attributes input)
110110
output.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
111111
#endif
112112

113-
#ifdef _MAIN_LIGHT_SHADOWS
113+
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
114114
output.shadowCoord = GetShadowCoord(vertexInput);
115115
#endif
116116

117117
return output;
118-
}
118+
}

com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7BillboardPasses.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ SpeedTreeVertexOutput SpeedTree7Vert(SpeedTreeVertexInput input)
100100

101101
output.clipPos = vertexInput.positionCS;
102102

103-
#ifdef _MAIN_LIGHT_SHADOWS
104-
output.shadowCoord = GetShadowCoord(vertexInput);
105-
#endif
103+
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
104+
output.shadowCoord = GetShadowCoord(vertexInput);
105+
#endif
106106

107107
return output;
108108
}

com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7CommonPasses.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct SpeedTreeVertexOutput
4444
half3 viewDirWS : TEXCOORD4;
4545
#endif
4646

47-
#ifdef _MAIN_LIGHT_SHADOWS
47+
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
4848
float4 shadowCoord : TEXCOORD6;
4949
#endif
5050

com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8Passes.hlsl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct SpeedTreeVertexOutput
3333
half3 viewDirWS : TEXCOORD4;
3434
#endif
3535

36-
#ifdef _MAIN_LIGHT_SHADOWS
36+
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
3737
float4 shadowCoord : TEXCOORD6;
3838
#endif
3939

@@ -230,11 +230,12 @@ SpeedTreeVertexOutput SpeedTree8Vert(SpeedTreeVertexInput input)
230230
output.viewDirWS = viewDirWS;
231231
#endif
232232

233-
#ifdef _MAIN_LIGHT_SHADOWS
233+
output.positionWS = vertexInput.positionWS;
234+
235+
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
234236
output.shadowCoord = GetShadowCoord(vertexInput);
235237
#endif
236238

237-
output.positionWS = vertexInput.positionWS;
238239
output.clipPos = vertexInput.positionCS;
239240

240241
return output;
@@ -282,11 +283,13 @@ void InitializeInputData(SpeedTreeFragmentInput input, half3 normalTS, out Input
282283
inputData.viewDirectionWS = SafeNormalize(inputData.viewDirectionWS);
283284
#endif
284285

285-
#ifdef _MAIN_LIGHT_SHADOWS
286-
inputData.shadowCoord = input.interpolated.shadowCoord;
287-
#else
288-
inputData.shadowCoord = float4(0, 0, 0, 0);
289-
#endif
286+
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
287+
inputData.shadowCoord = input.interpolated.shadowCoord;
288+
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
289+
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
290+
#else
291+
inputData.shadowCoord = float4(0, 0, 0, 0);
292+
#endif
290293

291294
inputData.fogCoord = input.interpolated.fogFactorAndVertexLight.x;
292295
inputData.vertexLighting = input.interpolated.fogFactorAndVertexLight.yzw;

com.unity.render-pipelines.universal/Shaders/Terrain/WavingGrassPasses.hlsl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct GrassVertexOutput
2626

2727
half4 fogFactorAndVertexLight : TEXCOORD5; // x: fogFactor, yzw: vertex light
2828

29-
#ifdef _MAIN_LIGHT_SHADOWS
29+
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
3030
float4 shadowCoord : TEXCOORD6;
3131
#endif
3232
half4 color : TEXCOORD7;
@@ -46,13 +46,16 @@ void InitializeInputData(GrassVertexOutput input, out InputData inputData)
4646
#endif
4747

4848
inputData.normalWS = NormalizeNormalPerPixel(input.normal);
49-
5049
inputData.viewDirectionWS = viewDirWS;
51-
#ifdef _MAIN_LIGHT_SHADOWS
50+
51+
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
5252
inputData.shadowCoord = input.shadowCoord;
53+
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
54+
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
5355
#else
5456
inputData.shadowCoord = float4(0, 0, 0, 0);
5557
#endif
58+
5659
inputData.fogCoord = input.fogFactorAndVertexLight.x;
5760
inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
5861
inputData.bakedGI = SAMPLE_GI(input.lightmapUV, input.vertexSH, inputData.normalWS);
@@ -86,7 +89,7 @@ void InitializeVertData(GrassVertexInput input, inout GrassVertexOutput vertData
8689
half fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
8790
vertData.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
8891

89-
#ifdef _MAIN_LIGHT_SHADOWS
92+
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
9093
vertData.shadowCoord = GetShadowCoord(vertexInput);
9194
#endif
9295
}

0 commit comments

Comments
 (0)