Lux URP Particles Simple Lit Inputs.hlsl 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Only needed to define our own CBUFFER
  2. #ifndef LIGHTWEIGHT_PARTICLES_SIMPLE_LIT_INPUT_INCLUDED
  3. #define LIGHTWEIGHT_PARTICLES_SIMPLE_LIT_INPUT_INCLUDED
  4. //#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
  5. #include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesInput.hlsl"
  6. CBUFFER_START(UnityPerMaterial)
  7. float4 _SoftParticleFadeParams;
  8. float4 _CameraFadeParams;
  9. float4 _BaseMap_ST;
  10. half4 _BaseColor;
  11. half4 _EmissionColor;
  12. half4 _BaseColorAddSubDiff;
  13. // needed...
  14. half _Cutoff;
  15. half4 _SpecColor;
  16. //half _Smoothness;
  17. half _DistortionStrengthScaled;
  18. half _DistortionBlend;
  19. // Custom inputs
  20. float _SampleOffset;
  21. half _Transmission;
  22. half _TransmissionDistortion;
  23. #if defined(_USESTESSELLATION)
  24. float _Tess;
  25. float2 _TessRange;
  26. #endif
  27. CBUFFER_END
  28. TEXTURE2D(_SpecGlossMap); SAMPLER(sampler_SpecGlossMap);
  29. float4 _CameraDepthTexture_TexelSize;
  30. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Particles.hlsl"
  31. #define SOFT_PARTICLE_NEAR_FADE _SoftParticleFadeParams.x
  32. #define SOFT_PARTICLE_INV_FADE_DISTANCE _SoftParticleFadeParams.y
  33. #define CAMERA_NEAR_FADE _CameraFadeParams.x
  34. #define CAMERA_INV_FADE_DISTANCE _CameraFadeParams.y
  35. // ----------------------------------------------------------------------------------
  36. // Fixed soft particles single pass instanced
  37. // Soft particles - returns alpha value for fading particles based on the depth to the background pixel
  38. float Lux_SoftParticles(float near, float far, float4 projection)
  39. {
  40. float fade = 1;
  41. if (near > 0.0 || far > 0.0)
  42. {
  43. //float sceneZ = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, projection.xy / projection.w), _ZBufferParams);
  44. float sceneDepth = LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture, _CameraDepthTexture_TexelSize.zw * (projection.xy / projection.w), 0).x;
  45. float sceneZ = LinearEyeDepth(sceneDepth, _ZBufferParams);
  46. float thisZ = LinearEyeDepth(projection.z / projection.w, _ZBufferParams);
  47. fade = saturate (far * ((sceneZ - near) - thisZ));
  48. }
  49. return fade;
  50. }
  51. half4 Lux_SampleAlbedo(float2 uv, float3 blendUv, half4 color, float4 particleColor, float4 projectedPosition, TEXTURE2D_PARAM(albedoMap, sampler_albedoMap))
  52. {
  53. half4 albedo = BlendTexture(TEXTURE2D_ARGS(albedoMap, sampler_albedoMap), uv, blendUv) * color;
  54. half4 colorAddSubDiff = half4(0, 0, 0, 0);
  55. #if defined (_COLORADDSUBDIFF_ON)
  56. colorAddSubDiff = _BaseColorAddSubDiff;
  57. #endif
  58. // No distortion Support
  59. albedo = MixParticleColor(albedo, particleColor, colorAddSubDiff);
  60. AlphaDiscard(albedo.a, _Cutoff);
  61. #if defined(_SOFTPARTICLES_ON)
  62. ALBEDO_MUL *= Lux_SoftParticles(SOFT_PARTICLE_NEAR_FADE, SOFT_PARTICLE_INV_FADE_DISTANCE, projectedPosition);
  63. #endif
  64. #if defined(_FADING_ON)
  65. ALBEDO_MUL *= CameraFade(CAMERA_NEAR_FADE, CAMERA_INV_FADE_DISTANCE, projectedPosition);
  66. #endif
  67. return albedo;
  68. }
  69. half4 SampleAlbedo(float2 uv, float3 blendUv, half4 color, float4 particleColor, float4 projectedPosition, TEXTURE2D_PARAM(albedoMap, sampler_albedoMap))
  70. {
  71. half4 albedo = BlendTexture(TEXTURE2D_ARGS(albedoMap, sampler_albedoMap), uv, blendUv) * color;
  72. half4 colorAddSubDiff = half4(0, 0, 0, 0);
  73. #if defined (_COLORADDSUBDIFF_ON)
  74. colorAddSubDiff = _BaseColorAddSubDiff;
  75. #endif
  76. albedo = MixParticleColor(albedo, particleColor, colorAddSubDiff);
  77. AlphaDiscard(albedo.a, _Cutoff);
  78. #if defined(_SOFTPARTICLES_ON)
  79. ALBEDO_MUL *= SoftParticles(SOFT_PARTICLE_NEAR_FADE, SOFT_PARTICLE_INV_FADE_DISTANCE, projectedPosition);
  80. #endif
  81. #if defined(_FADING_ON)
  82. ALBEDO_MUL *= CameraFade(CAMERA_NEAR_FADE, CAMERA_INV_FADE_DISTANCE, projectedPosition);
  83. #endif
  84. return albedo;
  85. }
  86. half4 SampleSpecularSmoothness(float2 uv, float3 blendUv, half alpha, half4 specColor, TEXTURE2D_PARAM(specGlossMap, sampler_specGlossMap))
  87. {
  88. half4 specularGloss = half4(0.0h, 0.0h, 0.0h, 1.0h);
  89. #ifdef _SPECGLOSSMAP
  90. specularGloss = BlendTexture(TEXTURE2D_ARGS(specGlossMap, sampler_specGlossMap), uv, blendUv);
  91. #elif defined(_SPECULAR_COLOR)
  92. specularGloss = specColor;
  93. #endif
  94. #ifdef _GLOSSINESS_FROM_BASE_ALPHA
  95. specularGloss.a = alpha;
  96. #endif
  97. specularGloss.a = exp2(10 * specularGloss.a + 1);
  98. return specularGloss;
  99. }
  100. #endif // LIGHTWEIGHT_PARTICLES_SIMPLE_LIT_INPUT_INCLUDED