Brak opisu
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.

Deferred.hlsl 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef UNIVERSAL_DEFERRED_INCLUDED
  2. #define UNIVERSAL_DEFERRED_INCLUDED
  3. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  4. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
  5. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityGBuffer.hlsl"
  6. // This structure is used in StructuredBuffer.
  7. // TODO move some of the properties to half storage (color, attenuation, spotDirection, flag to 16bits, occlusionProbeInfo)
  8. struct PunctualLightData
  9. {
  10. float3 posWS;
  11. float radius2; // squared radius
  12. float4 color;
  13. float4 attenuation; // .xy are used by DistanceAttenuation - .zw are used by AngleAttenuation (for SpotLights)
  14. float3 spotDirection; // spotLights support
  15. int flags; // Light flags (enum kLightFlags and LightFlag in C# code)
  16. float4 occlusionProbeInfo;
  17. uint layerMask; // Optional light layer mask
  18. };
  19. Light UnityLightFromPunctualLightDataAndWorldSpacePosition(PunctualLightData punctualLightData, float3 positionWS, half4 shadowMask, int shadowLightIndex, bool materialFlagReceiveShadowsOff)
  20. {
  21. // Keep in sync with GetAdditionalPerObjectLight in Lighting.hlsl
  22. half4 probesOcclusion = shadowMask;
  23. Light light;
  24. float3 lightVector = punctualLightData.posWS - positionWS.xyz;
  25. float distanceSqr = max(dot(lightVector, lightVector), HALF_MIN);
  26. half3 lightDirection = half3(lightVector * rsqrt(distanceSqr));
  27. // full-float precision required on some platforms
  28. float attenuation = DistanceAttenuation(distanceSqr, punctualLightData.attenuation.xy) * AngleAttenuation(punctualLightData.spotDirection.xyz, lightDirection, punctualLightData.attenuation.zw);
  29. light.direction = lightDirection;
  30. light.color = punctualLightData.color.rgb;
  31. light.distanceAttenuation = attenuation;
  32. [branch] if (materialFlagReceiveShadowsOff)
  33. light.shadowAttenuation = 1.0;
  34. else
  35. {
  36. light.shadowAttenuation = AdditionalLightShadow(shadowLightIndex, positionWS, lightDirection, shadowMask, punctualLightData.occlusionProbeInfo);
  37. }
  38. light.layerMask = punctualLightData.layerMask;
  39. return light;
  40. }
  41. #endif