ParticlesLitInput.hlsl 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef UNIVERSAL_PARTICLES_LIT_INPUT_INCLUDED
  2. #define UNIVERSAL_PARTICLES_LIT_INPUT_INCLUDED
  3. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Particles.hlsl"
  4. CBUFFER_START(UnityPerMaterial)
  5. float4 _SoftParticleFadeParams;
  6. float4 _CameraFadeParams;
  7. float4 _BaseMap_ST;
  8. half4 _BaseColor;
  9. half4 _EmissionColor;
  10. half4 _BaseColorAddSubDiff;
  11. half _Cutoff;
  12. half _Metallic;
  13. half _Smoothness;
  14. half _BumpScale;
  15. half _DistortionStrengthScaled;
  16. half _DistortionBlend;
  17. CBUFFER_END
  18. TEXTURE2D(_MetallicGlossMap); SAMPLER(sampler_MetallicGlossMap);
  19. #define SOFT_PARTICLE_NEAR_FADE _SoftParticleFadeParams.x
  20. #define SOFT_PARTICLE_INV_FADE_DISTANCE _SoftParticleFadeParams.y
  21. #define CAMERA_NEAR_FADE _CameraFadeParams.x
  22. #define CAMERA_INV_FADE_DISTANCE _CameraFadeParams.y
  23. // Pre-multiplied alpha helper
  24. #if defined(_ALPHAPREMULTIPLY_ON)
  25. #define ALBEDO_MUL albedo
  26. #else
  27. #define ALBEDO_MUL albedo.a
  28. #endif
  29. half4 SampleAlbedo(float2 uv, float3 blendUv, half4 color, float4 particleColor, float4 projectedPosition, TEXTURE2D_PARAM(albedoMap, sampler_albedoMap))
  30. {
  31. half4 albedo = BlendTexture(TEXTURE2D_ARGS(albedoMap, sampler_albedoMap), uv, blendUv) * color;
  32. half4 colorAddSubDiff = half4(0, 0, 0, 0);
  33. #if defined (_COLORADDSUBDIFF_ON)
  34. colorAddSubDiff = _BaseColorAddSubDiff;
  35. #endif
  36. // No distortion Support
  37. albedo = MixParticleColor(albedo, particleColor, colorAddSubDiff);
  38. AlphaDiscard(albedo.a, _Cutoff);
  39. #if defined(_SOFTPARTICLES_ON)
  40. ALBEDO_MUL *= SoftParticles(SOFT_PARTICLE_NEAR_FADE, SOFT_PARTICLE_INV_FADE_DISTANCE, projectedPosition);
  41. #endif
  42. #if defined(_FADING_ON)
  43. ALBEDO_MUL *= CameraFade(CAMERA_NEAR_FADE, CAMERA_INV_FADE_DISTANCE, projectedPosition);
  44. #endif
  45. return albedo;
  46. }
  47. inline void InitializeParticleLitSurfaceData(float2 uv, float3 blendUv, float4 particleColor, float4 projectedPosition, out SurfaceData outSurfaceData)
  48. {
  49. half4 albedo = SampleAlbedo(uv, blendUv, _BaseColor, particleColor, projectedPosition, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
  50. #if defined(_METALLICSPECGLOSSMAP)
  51. half2 metallicGloss = BlendTexture(TEXTURE2D_ARGS(_MetallicGlossMap, sampler_MetallicGlossMap), uv, blendUv).ra * half2(1.0, _Smoothness);
  52. #else
  53. half2 metallicGloss = half2(_Metallic, _Smoothness);
  54. #endif
  55. half3 normalTS = SampleNormalTS(uv, blendUv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap), _BumpScale);
  56. #if defined(_EMISSION)
  57. half3 emission = BlendTexture(TEXTURE2D_ARGS(_EmissionMap, sampler_EmissionMap), uv, blendUv).rgb * _EmissionColor.rgb;
  58. #else
  59. half3 emission = half3(0, 0, 0);
  60. #endif
  61. #if defined(_DISTORTION_ON)
  62. albedo.rgb = Distortion(albedo, normalTS, _DistortionStrengthScaled, _DistortionBlend, projectedPosition);
  63. #endif
  64. outSurfaceData.albedo = albedo.rgb;
  65. outSurfaceData.specular = half3(0.0h, 0.0h, 0.0h);
  66. outSurfaceData.normalTS = normalTS;
  67. outSurfaceData.emission = emission;
  68. outSurfaceData.metallic = metallicGloss.r;
  69. outSurfaceData.smoothness = metallicGloss.g;
  70. outSurfaceData.occlusion = 1.0;
  71. outSurfaceData.albedo = AlphaModulate(outSurfaceData.albedo, albedo.a);
  72. outSurfaceData.alpha = albedo.a;
  73. }
  74. #endif // UNIVERSAL_PARTICLES_LIT_INPUT_INCLUDED