Refactor light calculations into LightStrength.hlsl include

Moved light type calculation logic from BlendinShader.shader to a new include file, LightStrength.hlsl, for better modularity and maintainability. Updated the shader to use the new macro for light calculations, improving code clarity and reducing duplication.
This commit is contained in:
DeMuenu
2025-09-24 17:51:23 +02:00
parent 8f0fb9ab7c
commit b9bfd0b559
2 changed files with 30 additions and 25 deletions

View File

@@ -0,0 +1,23 @@
#ifndef LightTypeCalculations
#define LightTypeCalculations(_LightColors ,LightCounter, i, NdotL, dIntensity, radius, Lightposition) \
if(_LightType[LightCounter] == 0) \
{ \
contrib = _LightColors[LightCounter].a / max(1e-4, max(0, max(1, distanceFromLight - radius) * invSqMul) * max(0, max(1, distanceFromLight - radius) * invSqMul)); \
\
dIntensity += contrib * NdotL; \
} \
else if (_LightType[LightCounter] == 1) \
{ \
float invSq = _LightColors[LightCounter].a / max(1e-4, (distanceFromLight * invSqMul) * (distanceFromLight * invSqMul)); \
float threshold = (-1 + _LightDirections[LightCounter].w / 180); \
\
contrib = min(dot(normalize(i.worldPos - Lightposition), -normalize(_LightDirections[LightCounter].xyz)), 0); \
contrib= 1 - step(threshold, contrib); \
\
contrib = contrib * invSq; \
dIntensity += contrib * NdotL; \
} \
float3 LightColor = _LightColors[LightCounter].xyz; \
#endif