Light2D-Shape-Volumetric.shader 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. Shader "Hidden/Light2D-Shape-Volumetric"
  2. {
  3. SubShader
  4. {
  5. Tags { "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" }
  6. Pass
  7. {
  8. Blend SrcAlpha One
  9. ZWrite Off
  10. ZTest Off
  11. Cull Off
  12. HLSLPROGRAM
  13. #pragma vertex vert
  14. #pragma fragment frag
  15. #pragma multi_compile_local SPRITE_LIGHT __
  16. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  17. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/LightingUtility.hlsl"
  18. struct Attributes
  19. {
  20. float3 positionOS : POSITION;
  21. float4 color : COLOR;
  22. half2 uv : TEXCOORD0;
  23. };
  24. struct Varyings
  25. {
  26. float4 positionCS : SV_POSITION;
  27. half4 color : COLOR;
  28. half2 uv : TEXCOORD0;
  29. SHADOW_COORDS(TEXCOORD1)
  30. };
  31. half4 _LightColor;
  32. half _FalloffDistance;
  33. half _VolumeOpacity;
  34. half _InverseHDREmulationScale;
  35. #ifdef SPRITE_LIGHT
  36. TEXTURE2D(_CookieTex); // This can either be a sprite texture uv or a falloff texture
  37. SAMPLER(sampler_CookieTex);
  38. #else
  39. uniform half _FalloffIntensity;
  40. TEXTURE2D(_FalloffLookup);
  41. SAMPLER(sampler_FalloffLookup);
  42. #endif
  43. SHADOW_VARIABLES
  44. Varyings vert(Attributes attributes)
  45. {
  46. Varyings o = (Varyings)0;
  47. float3 positionOS = attributes.positionOS;
  48. positionOS.x = positionOS.x + _FalloffDistance * attributes.color.r;
  49. positionOS.y = positionOS.y + _FalloffDistance * attributes.color.g;
  50. o.positionCS = TransformObjectToHClip(positionOS);
  51. o.color = _LightColor * _InverseHDREmulationScale;
  52. o.color.a = _LightColor.a * _VolumeOpacity;
  53. #ifdef SPRITE_LIGHT
  54. o.uv = attributes.uv;
  55. #else
  56. o.uv = float2(attributes.color.a, _FalloffIntensity);
  57. #endif
  58. TRANSFER_SHADOWS(o)
  59. return o;
  60. }
  61. half4 frag(Varyings i) : SV_Target
  62. {
  63. half4 color = i.color;
  64. #if SPRITE_LIGHT
  65. color *= SAMPLE_TEXTURE2D(_CookieTex, sampler_CookieTex, i.uv);
  66. #else
  67. color.a = i.color.a * SAMPLE_TEXTURE2D(_FalloffLookup, sampler_FalloffLookup, i.uv).r;
  68. #endif
  69. APPLY_SHADOWS(i, color, _ShadowVolumeIntensity);
  70. return color;
  71. }
  72. ENDHLSL
  73. }
  74. }
  75. }