Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Light2D-Point.shader 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. Shader "Hidden/Light2D-Point"
  2. {
  3. Properties
  4. {
  5. [HideInInspector] _SrcBlend("__src", Float) = 1.0
  6. [HideInInspector] _DstBlend("__dst", Float) = 0.0
  7. [Enum(UnityEngine.Rendering.CompareFunction)] _HandleZTest ("_HandleZTest", Int) = 4
  8. }
  9. SubShader
  10. {
  11. Tags { "Queue" = "Transparent" "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" }
  12. Pass
  13. {
  14. Blend [_SrcBlend][_DstBlend]
  15. ZWrite Off
  16. ZTest [_HandleZTest]
  17. Cull Off
  18. HLSLPROGRAM
  19. #pragma vertex vert
  20. #pragma fragment frag
  21. #pragma multi_compile_local USE_POINT_LIGHT_COOKIES __
  22. #pragma multi_compile_local LIGHT_QUALITY_FAST __
  23. #pragma multi_compile_local USE_NORMAL_MAP __
  24. #pragma multi_compile_local USE_ADDITIVE_BLENDING __
  25. #pragma multi_compile_local USE_VOLUMETRIC __
  26. #pragma multi_compile USE_SHAPE_LIGHT_TYPE_0 __
  27. #pragma multi_compile USE_SHAPE_LIGHT_TYPE_1 __
  28. #pragma multi_compile USE_SHAPE_LIGHT_TYPE_2 __
  29. #pragma multi_compile USE_SHAPE_LIGHT_TYPE_3 __
  30. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  31. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/LightingUtility.hlsl"
  32. struct Attributes
  33. {
  34. float3 positionOS : POSITION;
  35. float4 color : COLOR;
  36. float2 texcoord : TEXCOORD0;
  37. };
  38. struct Varyings
  39. {
  40. float4 positionCS : SV_POSITION;
  41. half2 uv : TEXCOORD0;
  42. half2 lookupUV : TEXCOORD1; // This is used for light relative direction
  43. NORMALS_LIGHTING_COORDS(TEXCOORD2, TEXCOORD3)
  44. SHADOW_COORDS(TEXCOORD4)
  45. LIGHT_OFFSET(TEXCOORD5)
  46. };
  47. UNITY_LIGHT2D_DATA
  48. #if USE_POINT_LIGHT_COOKIES
  49. TEXTURE2D(_PointLightCookieTex);
  50. SAMPLER(sampler_PointLightCookieTex);
  51. #endif
  52. TEXTURE2D(_FalloffLookup);
  53. SAMPLER(sampler_FalloffLookup);
  54. TEXTURE2D(_LightLookup);
  55. SAMPLER(sampler_LightLookup);
  56. half4 _LightLookup_TexelSize;
  57. NORMALS_LIGHTING_VARIABLES
  58. SHADOW_VARIABLES
  59. half _IsFullSpotlight;
  60. half _InverseHDREmulationScale;
  61. Varyings vert(Attributes a)
  62. {
  63. Varyings output = (Varyings)0;
  64. output.positionCS = TransformObjectToHClip(a.positionOS);
  65. output.uv = a.texcoord;
  66. output.lightOffset = a.color;
  67. #if USE_STRUCTURED_BUFFER_FOR_LIGHT2D_DATA
  68. PerLight2D light = GetPerLight2D(output.lightOffset);
  69. #endif
  70. float4 worldSpacePos;
  71. worldSpacePos.xyz = TransformObjectToWorld(a.positionOS);
  72. worldSpacePos.w = 1;
  73. float4 lightSpacePos = mul(_L2D_INVMATRIX, worldSpacePos);
  74. float halfTexelOffset = 0.5 * _LightLookup_TexelSize.x;
  75. output.lookupUV = 0.5 * (lightSpacePos.xy + 1) + halfTexelOffset;
  76. TRANSFER_NORMALS_LIGHTING(output, worldSpacePos, _L2D_POSITION.xyz, _L2D_POSITION.w)
  77. TRANSFER_SHADOWS(output)
  78. return output;
  79. }
  80. FragmentOutput frag(Varyings i)
  81. {
  82. #if USE_STRUCTURED_BUFFER_FOR_LIGHT2D_DATA
  83. PerLight2D light = GetPerLight2D(i.lightOffset);
  84. #endif
  85. half4 lookupValue = SAMPLE_TEXTURE2D(_LightLookup, sampler_LightLookup, i.lookupUV); // r = distance, g = angle, b = x direction, a = y direction
  86. // Inner Radius
  87. half attenuation = saturate(_L2D_INNER_RADIUS_MULT * lookupValue.r); // This is the code to take care of our inner radius
  88. // Spotlight
  89. half isFullSpotlight = _L2D_INNER_ANGLE == 1.0f;
  90. half spotAttenuation = saturate((_L2D_OUTER_ANGLE - lookupValue.g + _IsFullSpotlight) * (1.0f / (_L2D_OUTER_ANGLE - _L2D_INNER_ANGLE)));
  91. attenuation = attenuation * spotAttenuation;
  92. half2 mappedUV;
  93. mappedUV.x = attenuation;
  94. mappedUV.y = _L2D_FALLOFF_INTENSITY;
  95. attenuation = SAMPLE_TEXTURE2D(_FalloffLookup, sampler_FalloffLookup, mappedUV).r;
  96. #if USE_POINT_LIGHT_COOKIES
  97. half4 cookieColor = SAMPLE_TEXTURE2D(_PointLightCookieTex, sampler_PointLightCookieTex, i.lookupUV);
  98. half4 lightColor = cookieColor * _L2D_COLOR;
  99. #else
  100. half4 lightColor = _L2D_COLOR;
  101. #endif
  102. #if USE_ADDITIVE_BLENDING || USE_VOLUMETRIC
  103. lightColor *= attenuation;
  104. #else
  105. lightColor.a = attenuation;
  106. #endif
  107. APPLY_NORMALS_LIGHTING(i, lightColor, _L2D_POSITION.xyz, _L2D_POSITION.w);
  108. APPLY_SHADOWS(i, lightColor, _L2D_SHADOW_INTENSITY);
  109. #if USE_VOLUMETRIC
  110. lightColor *= _L2D_VOLUME_OPACITY;
  111. #endif
  112. return ToFragmentOutput(lightColor * _InverseHDREmulationScale);
  113. }
  114. ENDHLSL
  115. }
  116. }
  117. }