ParticlesDepthNormalsPass.hlsl 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef UNIVERSAL_PARTICLES_LIT_DEPTH_NORMALS_PASS_INCLUDED
  2. #define UNIVERSAL_PARTICLES_LIT_DEPTH_NORMALS_PASS_INCLUDED
  3. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  4. VaryingsDepthNormalsParticle DepthNormalsVertex(AttributesDepthNormalsParticle input)
  5. {
  6. VaryingsDepthNormalsParticle output = (VaryingsDepthNormalsParticle)0;
  7. UNITY_SETUP_INSTANCE_ID(input);
  8. UNITY_TRANSFER_INSTANCE_ID(input, output);
  9. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  10. VertexPositionInputs vertexInput = GetVertexPositionInputs(input.vertex.xyz);
  11. VertexNormalInputs normalInput = GetVertexNormalInputs(input.normal, input.tangent);
  12. half3 viewDirWS = GetWorldSpaceNormalizeViewDir(vertexInput.positionWS);
  13. #if defined(_NORMALMAP)
  14. output.normalWS = half4(normalInput.normalWS, viewDirWS.x);
  15. output.tangentWS = half4(normalInput.tangentWS, viewDirWS.y);
  16. output.bitangentWS = half4(normalInput.bitangentWS, viewDirWS.z);
  17. #else
  18. output.normalWS = normalInput.normalWS;
  19. output.viewDirWS = viewDirWS;
  20. #endif
  21. output.clipPos = vertexInput.positionCS;
  22. #if defined(_ALPHATEST_ON)
  23. output.color = GetParticleColor(input.color);
  24. #endif
  25. #if defined(_ALPHATEST_ON) || defined(_NORMALMAP)
  26. #if defined(_FLIPBOOKBLENDING_ON)
  27. #if defined(UNITY_PARTICLE_INSTANCING_ENABLED)
  28. GetParticleTexcoords(output.texcoord, output.texcoord2AndBlend, input.texcoords.xyxy, 0.0);
  29. #else
  30. GetParticleTexcoords(output.texcoord, output.texcoord2AndBlend, input.texcoords, input.texcoordBlend);
  31. #endif
  32. #else
  33. GetParticleTexcoords(output.texcoord, input.texcoords.xy);
  34. #endif
  35. #endif
  36. return output;
  37. }
  38. half4 DepthNormalsFragment(VaryingsDepthNormalsParticle input) : SV_TARGET
  39. {
  40. UNITY_SETUP_INSTANCE_ID(input);
  41. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  42. // Inputs...
  43. #if defined(_ALPHATEST_ON) || defined(_NORMALMAP)
  44. float2 uv = input.texcoord;
  45. #if defined(_FLIPBOOKBLENDING_ON)
  46. float3 blendUv = input.texcoord2AndBlend;
  47. #else
  48. float3 blendUv = float3(0,0,0);
  49. #endif
  50. #endif
  51. // Check if we need to discard...
  52. #if defined(_ALPHATEST_ON)
  53. half4 vertexColor = input.color;
  54. half4 baseColor = _BaseColor;
  55. half4 albedo = BlendTexture(TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap), uv, blendUv) * baseColor;
  56. half4 colorAddSubDiff = half4(0, 0, 0, 0);
  57. #if defined(_COLORADDSUBDIFF_ON)
  58. colorAddSubDiff = _BaseColorAddSubDiff;
  59. #endif
  60. albedo = MixParticleColor(albedo, vertexColor, colorAddSubDiff);
  61. AlphaDiscard(albedo.a, _Cutoff);
  62. #endif
  63. // Normals...
  64. #ifdef _NORMALMAP
  65. half3 normalTS = SampleNormalTS(uv, blendUv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap), _BumpScale);
  66. float3 normalWS = TransformTangentToWorld(normalTS, half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz));
  67. #else
  68. float3 normalWS = input.normalWS;
  69. #endif
  70. // Output...
  71. #if defined(_GBUFFER_NORMALS_OCT)
  72. float2 octNormalWS = PackNormalOctQuadEncode(normalWS); // values between [-1, +1], must use fp32 on some platforms
  73. float2 remappedOctNormalWS = saturate(octNormalWS * 0.5 + 0.5); // values between [ 0, 1]
  74. half3 packedNormalWS = PackFloat2To888(remappedOctNormalWS); // values between [ 0, 1]
  75. return half4(packedNormalWS, 0.0);
  76. #else
  77. return half4(NormalizeNormalPerPixel(normalWS), 0.0);
  78. #endif
  79. }
  80. #endif // UNIVERSAL_PARTICLES_LIT_DEPTH_NORMALS_PASS_INCLUDED