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

@@ -2,16 +2,20 @@
#define InLoopSetup(_Udon_LightPositions, LightCounter, count, i) \
if (LightCounter >= count) break; \
\
float distanceFromLight = length(i.worldPos - _Udon_LightPositions[LightCounter].xyz); \
float3 lightVec = _Udon_LightPositions[LightCounter].xyz - i.worldPos; \
float distanceFromLight = length(lightVec); \
if (distanceFromLight > _LightCutoffDistance) continue; \
\
float contrib = 0.0;
float contrib = 0.0; \
float3 L = lightVec / max(distanceFromLight, 1e-4);
#endif
#ifndef OutLoopSetup
#define OutLoopSetup(i, _Udon_PlayerCount) \
int count = (int)_Udon_PlayerCount; \
float invSqMul = max(1e-4, _InverseSqareMultiplier); \
bool shadowCastingEnabled = _EnableShadowCasting > 0.5; \
\
float4 dmax = float4(0,0,0,1); \
float dIntensity = 0;

View File

@@ -1,7 +1,7 @@
#ifndef Lambert
#define Lambert(q ,i, N) \
float3 L = normalize(q - i.worldPos); /* q = light position */ \
float NdotL = saturate(dot(N, L) * 0.5 + 0.5); /* one-sided Lambert */ \
/* 'L' is inherited from InLoopSetup, avoiding an expensive normalize() */ \
half NdotL = saturate(dot(N, L) * 0.5 + 0.5); /* one-sided Lambert */ \
if (NdotL <= 0) continue; \
#endif

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