optimisations from gemini (not tested)

This commit is contained in:
DeMuenu
2026-03-24 15:45:31 +01:00
parent 9f986c3eb1
commit a1e808ad92
12 changed files with 231 additions and 117 deletions

View File

@@ -1,24 +1,26 @@
#ifndef LightTypeCalculations
#define LightTypeCalculations(_Udon_LightColors ,LightCounter, i, NdotL, dIntensity, radius, Lightposition) \
float invSqMul = max(1e-4, _InverseSqareMultiplier); \
half typeId = _Udon_LightType[LightCounter]; \
\
if(_Udon_LightType[LightCounter] == 0) \
if(typeId == 0) \
{ \
contrib = _Udon_LightColors[LightCounter].a / max(1e-4, max(0, max(1, distanceFromLight - radius) * invSqMul) * max(0, max(1, distanceFromLight - radius) * invSqMul)); \
float distAtten = max(1.0, distanceFromLight - radius) * invSqMul; \
contrib = _Udon_LightColors[LightCounter].a / max(1e-4, distAtten * distAtten); \
\
dIntensity += contrib; \
} \
else if (_Udon_LightType[LightCounter] == 1) \
else if (typeId == 1) \
{ \
float invSq = _Udon_LightColors[LightCounter].a / max(1e-4, (distanceFromLight * invSqMul) * (distanceFromLight * invSqMul)); \
float distAtten = distanceFromLight * invSqMul; \
float invSq = _Udon_LightColors[LightCounter].a / max(1e-4, distAtten * distAtten); \
\
contrib = dot(normalize(i.worldPos - Lightposition), normalize(_Udon_LightDirections[LightCounter].xyz)); \
contrib = dot(-L, normalize(_Udon_LightDirections[LightCounter].xyz)); \
contrib = smoothstep(radius,_Udon_LightDirections[LightCounter].w, contrib); \
\
contrib = contrib * invSq; \
dIntensity += contrib; \
} \
float3 LightColor = _Udon_LightColors[LightCounter].xyz; \
half3 LightColor = _Udon_LightColors[LightCounter].xyz; \
#endif