Ingen beskrivning
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.

ParticlesSimpleLitForwardPass.hlsl 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #ifndef UNIVERSAL_PARTICLES_FORWARD_SIMPLE_LIT_PASS_INCLUDED
  2. #define UNIVERSAL_PARTICLES_FORWARD_SIMPLE_LIT_PASS_INCLUDED
  3. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  4. #include_with_pragmas "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;
  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. #ifdef _NORMALMAP
  59. output.normalWS = half4(normalInput.normalWS, viewDirWS.x);
  60. output.tangentWS = half4(normalInput.tangentWS, viewDirWS.y);
  61. output.bitangentWS = half4(normalInput.bitangentWS, viewDirWS.z);
  62. #else
  63. output.normalWS = half3(normalInput.normalWS);
  64. output.viewDirWS = viewDirWS;
  65. #endif
  66. OUTPUT_SH4(vertexInput.positionWS, output.normalWS.xyz, GetWorldSpaceNormalizeViewDir(vertexInput.positionWS), output.vertexSH, output.probeOcclusion);
  67. half fogFactor = 0.0;
  68. #if !defined(_FOG_FRAGMENT)
  69. fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
  70. #endif
  71. output.positionWS.xyz = vertexInput.positionWS.xyz;
  72. output.positionWS.w = fogFactor;
  73. output.clipPos = vertexInput.positionCS;
  74. output.color = GetParticleColor(input.color);
  75. #if defined(_FLIPBOOKBLENDING_ON)
  76. #if defined(UNITY_PARTICLE_INSTANCING_ENABLED)
  77. GetParticleTexcoords(output.texcoord, output.texcoord2AndBlend, input.texcoords.xyxy, 0.0);
  78. #else
  79. GetParticleTexcoords(output.texcoord, output.texcoord2AndBlend, input.texcoords, input.texcoordBlend);
  80. #endif
  81. #else
  82. GetParticleTexcoords(output.texcoord, input.texcoords.xy);
  83. #endif
  84. #if defined(_SOFTPARTICLES_ON) || defined(_FADING_ON) || defined(_DISTORTION_ON)
  85. output.projectedPosition = vertexInput.positionNDC;
  86. #endif
  87. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  88. output.shadowCoord = GetShadowCoord(vertexInput);
  89. #endif
  90. return output;
  91. }
  92. half4 ParticlesLitFragment(VaryingsParticle input) : SV_Target
  93. {
  94. UNITY_SETUP_INSTANCE_ID(input);
  95. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  96. ParticleParams particleParams;
  97. InitParticleParams(input, particleParams);
  98. half3 normalTS = SampleNormalTS(particleParams.uv, particleParams.blendUv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap));
  99. half4 albedo = SampleAlbedo(TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap), particleParams);
  100. half3 diffuse = AlphaModulate(albedo.rgb, albedo.a);
  101. half alpha = albedo.a;
  102. #if defined(_EMISSION)
  103. half3 emission = BlendTexture(TEXTURE2D_ARGS(_EmissionMap, sampler_EmissionMap), particleParams.uv, particleParams.blendUv).rgb * _EmissionColor.rgb;
  104. #else
  105. half3 emission = half3(0, 0, 0);
  106. #endif
  107. half4 specularGloss = SampleSpecularSmoothness(particleParams.uv, particleParams.blendUv, albedo.a, _SpecColor, TEXTURE2D_ARGS(_SpecGlossMap, sampler_SpecGlossMap));
  108. #if defined(_DISTORTION_ON)
  109. diffuse = Distortion(half4(diffuse, alpha), normalTS, _DistortionStrengthScaled, _DistortionBlend, particleParams.projectedPosition);
  110. #endif
  111. InputData inputData;
  112. InitializeInputData(input, normalTS, inputData);
  113. half4 color = UniversalFragmentBlinnPhong(inputData, diffuse, specularGloss, specularGloss.a, emission, alpha, normalTS);
  114. color.rgb = MixFog(color.rgb, inputData.fogCoord);
  115. color.a = OutputAlpha(color.a, IsSurfaceTypeTransparent(_Surface));
  116. return color;
  117. }
  118. #endif // UNIVERSAL_PARTICLES_FORWARD_SIMPLE_LIT_PASS_INCLUDED