Skip to content
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

[7.x.x Backport] Fixing defines and calculations for shadow coordinates #112

Merged
merged 1 commit into from Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.universal/CHANGELOG.md
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed an issue where particles using Sprite Shader Graph shaders were invisible.
- Fixed an issue where Scene objects might be incorrectly affected by 2D Lights from a previous Sorting Layer.
- Fixed an issue where errors would appear in the Console when entering Play Mode with a 2D Light selected in the Hierarchy. [Case 1226918](https://issuetracker.unity3d.com/issues/errors-appear-in-the-console-when-global-2d-light-is-selected-in-hierarchy)
- Fixed an issue with shadows not being correctly calculated in some shaders.

## [7.3.0] - 2020-03-11

Expand Down
Expand Up @@ -13,14 +13,16 @@
#elif _NORMAL_DROPOFF_WS
inputData.normalWS = normal;
#endif

#else
inputData.normalWS = input.normalWS;
#endif
inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
inputData.viewDirectionWS = SafeNormalize(input.viewDirectionWS);

#if defined(MAIN_LIGHT_CALCULATE_SHADOWS)
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
inputData.shadowCoord = input.shadowCoord;
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
#else
inputData.shadowCoord = float4(0, 0, 0, 0);
Expand All @@ -40,8 +42,8 @@ PackedVaryings vert(Attributes input)
return packedOutput;
}

half4 frag(PackedVaryings packedInput) : SV_TARGET
{
half4 frag(PackedVaryings packedInput) : SV_TARGET
{
Varyings unpacked = UnpackVaryings(packedInput);
UNITY_SETUP_INSTANCE_ID(unpacked);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked);
Expand All @@ -59,7 +61,7 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET
#ifdef _SPECULAR_SETUP
float3 specular = surfaceDescription.Specular;
float metallic = 1;
#else
#else
float3 specular = 0;
float metallic = surfaceDescription.Metallic;
#endif
Expand All @@ -72,8 +74,8 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET
surfaceDescription.Smoothness,
surfaceDescription.Occlusion,
surfaceDescription.Emission,
surfaceDescription.Alpha);
surfaceDescription.Alpha);

color.rgb = MixFog(color.rgb, inputData.fogCoord);
color.rgb = MixFog(color.rgb, inputData.fogCoord);
return color;
}
Expand Up @@ -14,12 +14,12 @@ Varyings BuildVaryings(Attributes input)
// Evaluate Vertex Graph
VertexDescriptionInputs vertexDescriptionInputs = BuildVertexDescriptionInputs(input);
VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);

// Assign modified vertex attributes
input.positionOS = vertexDescription.VertexPosition;
#if defined(VARYINGS_NEED_NORMAL_WS)
input.normalOS = vertexDescription.VertexNormal;
#endif //FEATURES_GRAPH_NORMAL
#endif //FEATURES_GRAPH_NORMAL
#if defined(VARYINGS_NEED_TANGENT_WS)
input.tangentOS.xyz = vertexDescription.VertexTangent.xyz;
#endif //FEATURES GRAPH TANGENT
Expand Down Expand Up @@ -51,7 +51,7 @@ Varyings BuildVaryings(Attributes input)
#ifdef VARYINGS_NEED_POSITION_WS
output.positionWS = positionWS;
#endif

#ifdef VARYINGS_NEED_NORMAL_WS
output.normalWS = normalWS; // normalized in TransformObjectToWorldNormal()
#endif
Expand Down Expand Up @@ -110,9 +110,9 @@ Varyings BuildVaryings(Attributes input)
output.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
#endif

#ifdef _MAIN_LIGHT_SHADOWS
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
output.shadowCoord = GetShadowCoord(vertexInput);
#endif

return output;
}
}
Expand Up @@ -99,7 +99,7 @@ SpeedTreeVertexOutput SpeedTree7Vert(SpeedTreeVertexInput input)

output.clipPos = vertexInput.positionCS;

#ifdef _MAIN_LIGHT_SHADOWS
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
output.shadowCoord = GetShadowCoord(vertexInput);
#endif

Expand Down
Expand Up @@ -40,7 +40,7 @@ struct SpeedTreeVertexOutput
half3 viewDirWS : TEXCOORD4;
#endif

#ifdef _MAIN_LIGHT_SHADOWS
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
float4 shadowCoord : TEXCOORD6;
#endif

Expand Down
Expand Up @@ -33,7 +33,7 @@ struct SpeedTreeVertexOutput
half3 viewDirWS : TEXCOORD4;
#endif

#ifdef _MAIN_LIGHT_SHADOWS
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
float4 shadowCoord : TEXCOORD6;
#endif

Expand Down Expand Up @@ -230,11 +230,12 @@ SpeedTreeVertexOutput SpeedTree8Vert(SpeedTreeVertexInput input)
output.viewDirWS = viewDirWS;
#endif

#ifdef _MAIN_LIGHT_SHADOWS
output.positionWS = vertexInput.positionWS;

#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
output.shadowCoord = GetShadowCoord(vertexInput);
#endif

output.positionWS = vertexInput.positionWS;
output.clipPos = vertexInput.positionCS;

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

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

inputData.fogCoord = input.interpolated.fogFactorAndVertexLight.x;
inputData.vertexLighting = input.interpolated.fogFactorAndVertexLight.yzw;
Expand Down
Expand Up @@ -26,7 +26,7 @@ struct GrassVertexOutput

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

#ifdef _MAIN_LIGHT_SHADOWS
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
float4 shadowCoord : TEXCOORD6;
#endif
half4 color : TEXCOORD7;
Expand All @@ -46,13 +46,16 @@ void InitializeInputData(GrassVertexOutput input, out InputData inputData)
#endif

inputData.normalWS = NormalizeNormalPerPixel(input.normal);

inputData.viewDirectionWS = viewDirWS;
#ifdef _MAIN_LIGHT_SHADOWS

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

inputData.fogCoord = input.fogFactorAndVertexLight.x;
inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
inputData.bakedGI = SAMPLE_GI(input.lightmapUV, input.vertexSH, inputData.normalWS);
Expand Down Expand Up @@ -86,7 +89,7 @@ void InitializeVertData(GrassVertexInput input, inout GrassVertexOutput vertData
half fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
vertData.fogFactorAndVertexLight = half4(fogFactor, vertexLight);

#ifdef _MAIN_LIGHT_SHADOWS
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
vertData.shadowCoord = GetShadowCoord(vertexInput);
#endif
}
Expand Down