Skip to content

Commit

Permalink
Fix for LOD crossfade in URP when using BatchRendererGroup
Browse files Browse the repository at this point in the history
Shader fixes to the DOTS instancing variants so that URP LOD crossfade works correctly when using BatchRendererGroup.

In this variant, the cross-fade value is read from a per-instance parameter, so the shader variant needs to propagate the instance ID to the pixel shader.  Most of the changes are to fix some missing macros to pass the instance ID.
  • Loading branch information
simonb-unity authored and Evergreen committed Mar 9, 2023
1 parent e155689 commit 5d3d0bb
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 3 deletions.
Expand Up @@ -11,8 +11,6 @@
UNITY_DOTS_INSTANCING_START(BuiltinPropertyMetadata)
UNITY_DOTS_INSTANCED_PROP(float3x4, unity_ObjectToWorld)
UNITY_DOTS_INSTANCED_PROP(float3x4, unity_WorldToObject)
UNITY_DOTS_INSTANCED_PROP(float4, unity_LODFade)
UNITY_DOTS_INSTANCED_PROP(float4, unity_RenderingLayer)
UNITY_DOTS_INSTANCED_PROP(float4, unity_SpecCube0_HDR)
UNITY_DOTS_INSTANCED_PROP(float4, unity_LightmapST)
UNITY_DOTS_INSTANCED_PROP(float4, unity_LightmapIndex)
Expand All @@ -23,7 +21,7 @@ UNITY_DOTS_INSTANCING_START(BuiltinPropertyMetadata)
UNITY_DOTS_INSTANCED_PROP(uint2, unity_EntityId)
UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata)

#define unity_LODFade UNITY_ACCESS_DOTS_INSTANCED_PROP(float4, unity_LODFade)
#define unity_LODFade LoadDOTSInstancedData_LODFade()
#define unity_SpecCube0_HDR UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_CUSTOM_DEFAULT(float4, unity_SpecCube0_HDR, unity_DOTS_SpecCube0_HDR)
#define unity_LightmapST UNITY_ACCESS_DOTS_INSTANCED_PROP(float4, unity_LightmapST)
#define unity_LightmapIndex UNITY_ACCESS_DOTS_INSTANCED_PROP(float4, unity_LightmapIndex)
Expand Down
Expand Up @@ -34,6 +34,7 @@ Varyings DepthNormalsVertex(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);

VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
Expand Down
Expand Up @@ -30,6 +30,7 @@ Varyings DepthNormalsVertex(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);

output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
Expand All @@ -49,6 +50,7 @@ void DepthNormalsFragment(
#endif
)
{
UNITY_SETUP_INSTANCE_ID(input);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);

Alpha(SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _BaseColor, _Cutoff);
Expand Down
Expand Up @@ -25,6 +25,7 @@ Varyings DepthOnlyVertex(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);

output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
Expand All @@ -34,6 +35,7 @@ Varyings DepthOnlyVertex(Attributes input)

half DepthOnlyFragment(Varyings input) : SV_TARGET
{
UNITY_SETUP_INSTANCE_ID(input);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);

Alpha(SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _BaseColor, _Cutoff);
Expand Down
Expand Up @@ -52,6 +52,7 @@ Varyings DepthNormalsVertex(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);

output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
Expand Down Expand Up @@ -87,6 +88,7 @@ void DepthNormalsFragment(
#endif
)
{
UNITY_SETUP_INSTANCE_ID(input);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);

Alpha(SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _BaseColor, _Cutoff);
Expand Down
Expand Up @@ -25,6 +25,7 @@ struct Varyings
{
float2 uv : TEXCOORD0;
float4 positionCS : SV_POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
};

float4 GetShadowPositionHClip(Attributes input)
Expand Down Expand Up @@ -53,6 +54,7 @@ Varyings ShadowPassVertex(Attributes input)
{
Varyings output;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);

output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
output.positionCS = GetShadowPositionHClip(input);
Expand All @@ -61,6 +63,8 @@ Varyings ShadowPassVertex(Attributes input)

half4 ShadowPassFragment(Varyings input) : SV_TARGET
{
UNITY_SETUP_INSTANCE_ID(input);

Alpha(SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _BaseColor, _Cutoff);

#ifdef LOD_FADE_CROSSFADE
Expand Down
Expand Up @@ -38,6 +38,7 @@ Varyings DepthNormalsVertex(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);

output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
Expand Down Expand Up @@ -66,6 +67,7 @@ void DepthNormalsFragment(
#endif
)
{
UNITY_SETUP_INSTANCE_ID(input);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);

Alpha(SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _BaseColor, _Cutoff);
Expand Down
Expand Up @@ -29,6 +29,7 @@ Varyings DepthNormalsVertex(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);

output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
Expand All @@ -48,6 +49,7 @@ void DepthNormalsFragment(
#endif
)
{
UNITY_SETUP_INSTANCE_ID(input);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);

Alpha(SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _BaseColor, _Cutoff);
Expand Down

0 comments on commit 5d3d0bb

Please sign in to comment.