Skip to content

Commit

Permalink
Try to simplify. numlights 0??
Browse files Browse the repository at this point in the history
  • Loading branch information
kristiker committed Dec 10, 2023
1 parent 4688c66 commit 869b01d
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions GUI/Types/Renderer/Shaders/common/lighting.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -248,29 +248,45 @@ float attenuate_cusp(float s, float falloff)
// This should contain our direct lighting loop
void CalculateDirectLighting(inout LightingTerms_t lighting, inout MaterialProperties_t mat)
{
const uint StaticLightCount = 4;
for(uint uLightIndex = 0; uLightIndex < StaticLightCount; ++uLightIndex)
//const uint StaticLightCount = 4;
//for(uint uLightIndex = 0; uLightIndex < StaticLightCount; ++uLightIndex)

vec3 vPositionWs = mat.PositionWS;

#if (D_BAKED_LIGHTING_FROM_LIGHTMAP == 1)
vec4 vLightShadow = GetLightmappedLightShadow();
#else
vec4 vLightShadow = vec4(1.0);
#endif

uint numLightsFixUp = uint(max(g_nNumLights[0], max(g_nNumLights[1], max(g_nNumLights[2], g_nNumLights[3]))));

for(uint uLightIndex = 0; uLightIndex < 4; uLightIndex++)
{
Light light = GetStaticLight(mat.PositionWS, uLightIndex);
int localIndex = uLightIndex <= g_nNumLights[0] ? 0 : uLightIndex <= g_nNumLights[1] ? 1 : uLightIndex <= g_nNumLights[2] ? 2 : 3;
float shadow = vLightShadow[localIndex];
float visibility = 1.0 - shadow;
float attenuation = 1.0;

if (light.Visibility > 0.0)
if (visibility > 0.0)
{
vec3 lightColor = GetLightColor(uLightIndex);
vec3 lightPosition = g_vLightPosition_Type[uLightIndex].xyz;
vec3 lightVector = normalize(lightPosition - mat.PositionWS);
vec3 direction = normalize(lightPosition - vPositionWs);

// directional light
if (g_vLightPosition_Type[uLightIndex].a == 0.0)
{
lightVector = GetEnvLightDirection(uLightIndex);
direction = GetEnvLightDirection(uLightIndex);
}

float attenuation = light.Visibility;
attenuation = visibility - .001;

if (g_vLightPosition_Type[uLightIndex].a == 1.0 || g_vLightPosition_Type[uLightIndex].a == 2.0)
{
float flInvRange = GetLightRangeInverse(uLightIndex);
float d = length(lightPosition - mat.PositionWS);
float s = d / 200;
float d = length(lightPosition - vPositionWs);
float s = d * flInvRange;
float falloff = g_vLightFallOff[uLightIndex].x;
attenuation *= attenuate_cusp(s, falloff);

Expand All @@ -281,10 +297,11 @@ void CalculateDirectLighting(inout LightingTerms_t lighting, inout MaterialPrope
}
}

CalculateShading(lighting, lightVector, attenuation * light.Color, mat);
if (attenuation > 0.0)
{
CalculateShading(lighting, direction, attenuation * lightColor, mat);
}
}

//break; // todo
}
}

Expand Down

0 comments on commit 869b01d

Please sign in to comment.