CTI URP Leaves DepthNormal Pass VFACE.hlsl 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. struct Attributes
  2. {
  3. float3 positionOS : POSITION;
  4. float3 normalOS : NORMAL; // Bending also
  5. #if defined (_NORMALMAP) && defined(_NORMALINDEPTHNORMALPASS)
  6. float4 tangentOS : TANGENT;
  7. #endif
  8. float2 uv : TEXCOORD0;
  9. float2 texcoord1 : TEXCOORD1; // Bending
  10. half4 color : COLOR; // Bending
  11. float3 texcoord2 : TEXCOORD2; // Leaves only: Pivot
  12. UNITY_VERTEX_INPUT_INSTANCE_ID
  13. };
  14. struct Varyings
  15. {
  16. float4 positionCS : SV_POSITION;
  17. float2 uv : TEXCOORD0;
  18. float3 normalWS : TEXCOORD4;
  19. #if defined (_NORMALMAP) && defined(_NORMALINDEPTHNORMALPASS)
  20. half4 tangentWS : TEXCOORD5;
  21. #endif
  22. // #if defined(SHADER_STAGE_FRAGMENT)
  23. // FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
  24. // #endif
  25. UNITY_VERTEX_INPUT_INSTANCE_ID
  26. UNITY_VERTEX_OUTPUT_STEREO
  27. };
  28. //--------------------------------------
  29. // Vertex shader
  30. #include "Includes/CTI URP Bending.hlsl"
  31. Varyings DepthNormalsVertex(Attributes input)
  32. {
  33. Varyings output = (Varyings)0;
  34. UNITY_SETUP_INSTANCE_ID(input);
  35. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  36. CTI_AnimateVertex(
  37. input,
  38. #if defined (_BENDINGCOLRSONLY)
  39. float4(input.color.rg, input.color.ab), // animParams,
  40. #else
  41. float4(input.color.rg, input.texcoord1.xy), // animParams,
  42. #endif
  43. _BaseWindMultipliers
  44. );
  45. output.uv = input.uv;
  46. VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
  47. #if defined (_NORMALMAP) && defined(_NORMALINDEPTHNORMALPASS)
  48. VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
  49. #else
  50. VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, float4(1,1,1,1));
  51. #endif
  52. output.normalWS = normalInput.normalWS;
  53. #if defined (_NORMALMAP) && defined(_NORMALINDEPTHNORMALPASS)
  54. real sign = input.tangentOS.w * GetOddNegativeScale();
  55. output.tangentWS = half4(normalInput.tangentWS.xyz, sign);
  56. #endif
  57. output.positionCS = vertexInput.positionCS;
  58. return output;
  59. }
  60. half4 DepthNormalsFragment(Varyings input, half facing : VFACE) : SV_TARGET
  61. {
  62. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  63. #if defined(LOD_FADE_CROSSFADE) && !defined(SHADER_API_GLES)
  64. LODDitheringTransition(input.positionCS.xyz, unity_LODFade.x);
  65. #endif
  66. half alpha = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv).a;
  67. clip(alpha - _Cutoff);
  68. #if defined(SHADER_STAGE_FRAGMENT)
  69. //input.cullFace = IS_FRONT_VFACE(frontFace, true, false);
  70. #endif
  71. // URP 12
  72. #if defined(_NORMALMAP) && defined(_NORMALINDEPTHNORMALPASS)
  73. half3 normalTS;
  74. half4 sampleNormal = SAMPLE_TEXTURE2D(_BumpSpecMap, sampler_BumpSpecMap, input.uv);
  75. half3 tangentNormal;
  76. normalTS.xy = sampleNormal.ag * 2 - 1;
  77. normalTS.z = sqrt(1.0 - dot(normalTS.xy, normalTS.xy));
  78. #if defined(SHADER_STAGE_FRAGMENT)
  79. normalTS.z *= facing; //input.cullFace ? 1 : -1;
  80. #endif
  81. float sgn = input.tangentWS.w; // should be either +1 or -1
  82. float3 bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz);
  83. input.normalWS = TransformTangentToWorld(normalTS, half3x3(input.tangentWS.xyz, bitangent, input.normalWS.xyz));
  84. #else
  85. input.normalWS *= facing; //input.cullFace ? 1 : -1;
  86. #endif
  87. #if defined(_GBUFFER_NORMALS_OCT)
  88. float3 normalWS = normalize(input.normalWS);
  89. float2 octNormalWS = PackNormalOctQuadEncode(normalWS); // values between [-1, +1], must use fp32 on some platforms.
  90. float2 remappedOctNormalWS = saturate(octNormalWS * 0.5 + 0.5); // values between [ 0, 1]
  91. half3 packedNormalWS = PackFloat2To888(remappedOctNormalWS); // values between [ 0, 1]
  92. return half4(packedNormalWS, 0.0);
  93. #else
  94. float3 normalWS = NormalizeNormalPerPixel(input.normalWS);
  95. return half4(normalWS, 0.0);
  96. #endif
  97. }