暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ParticlesLitForwardPass.hlsl 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifndef UNIVERSAL_PARTICLES_FORWARD_LIT_PASS_INCLUDED
  2. #define UNIVERSAL_PARTICLES_FORWARD_LIT_PASS_INCLUDED
  3. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  4. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Particles.hlsl"
  5. void InitializeInputData(VaryingsParticle input, half3 normalTS, out InputData inputData)
  6. {
  7. inputData = (InputData)0;
  8. inputData.positionWS = input.positionWS.xyz;
  9. #ifdef _NORMALMAP
  10. half3 viewDirWS = half3(input.normalWS.w, input.tangentWS.w, input.bitangentWS.w);
  11. inputData.tangentToWorld = half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz);
  12. inputData.normalWS = TransformTangentToWorld(normalTS, inputData.tangentToWorld);
  13. #else
  14. half3 viewDirWS = input.viewDirWS;
  15. inputData.normalWS = input.normalWS;
  16. #endif
  17. inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
  18. viewDirWS = SafeNormalize(viewDirWS);
  19. inputData.viewDirectionWS = viewDirWS;
  20. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  21. inputData.shadowCoord = input.shadowCoord;
  22. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  23. inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
  24. #else
  25. inputData.shadowCoord = float4(0, 0, 0, 0);
  26. #endif
  27. inputData.fogCoord = InitializeInputDataFog(float4(input.positionWS.xyz, 1.0), input.positionWS.w);
  28. inputData.vertexLighting = half3(0.0h, 0.0h, 0.0h);
  29. #if !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
  30. inputData.bakedGI = SAMPLE_GI(input.vertexSH,
  31. GetAbsolutePositionWS(inputData.positionWS),
  32. inputData.normalWS,
  33. inputData.viewDirectionWS,
  34. input.clipPos.xy,
  35. input.probeOcclusion,
  36. inputData.shadowMask);
  37. #else
  38. inputData.bakedGI = SampleSHPixel(input.vertexSH, inputData.normalWS);
  39. #endif
  40. inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.clipPos);
  41. inputData.shadowMask = half4(1, 1, 1, 1);
  42. #if defined(DEBUG_DISPLAY) && !defined(PARTICLES_EDITOR_META_PASS)
  43. inputData.vertexSH = input.vertexSH;
  44. #endif
  45. }
  46. ///////////////////////////////////////////////////////////////////////////////
  47. // Vertex and Fragment functions //
  48. ///////////////////////////////////////////////////////////////////////////////
  49. VaryingsParticle ParticlesLitVertex(AttributesParticle input)
  50. {
  51. VaryingsParticle output = (VaryingsParticle)0;
  52. UNITY_SETUP_INSTANCE_ID(input);
  53. UNITY_TRANSFER_INSTANCE_ID(input, output);
  54. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  55. VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
  56. VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
  57. half3 viewDirWS = GetWorldSpaceNormalizeViewDir(vertexInput.positionWS);
  58. half3 vertexLight = VertexLighting(vertexInput.positionWS, half3(normalInput.normalWS));
  59. half fogFactor = 0.0;
  60. #if !defined(_FOG_FRAGMENT)
  61. fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
  62. #endif
  63. #ifdef _NORMALMAP
  64. output.normalWS = half4(normalInput.normalWS, viewDirWS.x);
  65. output.tangentWS = half4(normalInput.tangentWS, viewDirWS.y);
  66. output.bitangentWS = half4(normalInput.bitangentWS, viewDirWS.z);
  67. #else
  68. output.normalWS = half3(normalInput.normalWS);
  69. output.viewDirWS = viewDirWS;
  70. #endif
  71. OUTPUT_SH4(vertexInput.positionWS, output.normalWS.xyz, GetWorldSpaceNormalizeViewDir(vertexInput.positionWS), output.vertexSH, output.probeOcclusion);
  72. output.positionWS.xyz = vertexInput.positionWS;
  73. output.positionWS.w = fogFactor;
  74. output.clipPos = vertexInput.positionCS;
  75. output.color = GetParticleColor(input.color);
  76. #if defined(_FLIPBOOKBLENDING_ON)
  77. #if defined(UNITY_PARTICLE_INSTANCING_ENABLED)
  78. GetParticleTexcoords(output.texcoord, output.texcoord2AndBlend, input.texcoords.xyxy, 0.0);
  79. #else
  80. GetParticleTexcoords(output.texcoord, output.texcoord2AndBlend, input.texcoords, input.texcoordBlend);
  81. #endif
  82. #else
  83. GetParticleTexcoords(output.texcoord, input.texcoords.xy);
  84. #endif
  85. #if defined(_SOFTPARTICLES_ON) || defined(_FADING_ON) || defined(_DISTORTION_ON)
  86. output.projectedPosition = vertexInput.positionNDC;
  87. #endif
  88. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  89. output.shadowCoord = GetShadowCoord(vertexInput);
  90. #endif
  91. return output;
  92. }
  93. half4 ParticlesLitFragment(VaryingsParticle input) : SV_Target
  94. {
  95. UNITY_SETUP_INSTANCE_ID(input);
  96. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  97. ParticleParams particleParams;
  98. InitParticleParams(input, particleParams);
  99. SurfaceData surfaceData;
  100. InitializeParticleLitSurfaceData(particleParams, surfaceData);
  101. InputData inputData;
  102. InitializeInputData(input, surfaceData.normalTS, inputData);
  103. SETUP_DEBUG_TEXTURE_DATA_FOR_TEX(inputData, input.texcoord, _BaseMap);
  104. half4 color = UniversalFragmentPBR(inputData, surfaceData);
  105. color.rgb = MixFog(color.rgb, inputData.fogCoord);
  106. color.a = OutputAlpha(color.a, IsSurfaceTypeTransparent(_Surface));
  107. return color;
  108. }
  109. #endif // UNIVERSAL_PARTICLES_FORWARD_LIT_PASS_INCLUDED