Skip to content

Commit

Permalink
Merge pull request #18 from Tokeiburu/light-shader
Browse files Browse the repository at this point in the history
Fixed the rsm/gnd shaders for the light.
  • Loading branch information
Borf committed Dec 19, 2023
2 parents 76fd886 + e038d25 commit 61e67db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 5 additions & 1 deletion data/shaders/gnd.fs
Expand Up @@ -37,7 +37,11 @@ void main()
discard;

float NL = clamp(dot(normalize(normal), vec3(1,-1,1)*lightDirection),0.0,1.0);
texture.rgb *= max((NL * min(lightDiffuse, 1.0 - lightAmbient) * lightDiffuse + lightAmbient), lightToggle);
vec3 ambientFactor = (1.0 - lightAmbient) * lightAmbient;
vec3 ambient = lightAmbient - ambientFactor + ambientFactor * lightDiffuse;
vec3 diffuseFactor = (1.0 - lightDiffuse) * lightDiffuse;
vec3 diffuse = lightDiffuse - diffuseFactor + diffuseFactor * lightAmbient;
texture.rgb *= min((NL * diffuse + ambient), 1.0);
texture.rgb *= max(color, colorToggle).rgb;
texture.rgb *= max(texture2D(s_lighting, texCoord2).a, shadowMapToggle);
texture.rgb += clamp(texture2D(s_lighting, texCoord2).rgb, 0.0, 1.0) * lightColorToggle;
Expand Down
17 changes: 10 additions & 7 deletions data/shaders/rsm.fs
Expand Up @@ -31,14 +31,17 @@ void main()
discard;

if (lightToggle) {
if (shadeType == 0)
color.rgb *= min(lightDiffuse, 1.0 - lightAmbient) * lightDiffuse + lightAmbient;
else if (shadeType == 1 || shadeType == 2) {
float NL = clamp(dot(normalize(normal), lightDirection),0.0,1.0);
color.rgb *= NL * min(lightDiffuse, 1.0 - lightAmbient) * lightDiffuse + lightAmbient;
}
else if (shadeType == 4) // only for editor
if (shadeType == 4) { // only for editor
color.rgb *= lightDiffuse;
}
else {
float NL = shadeType == 0 ? 1.0 : clamp(dot(normalize(normal), lightDirection),0.0,1.0);
vec3 ambientFactor = (1.0 - lightAmbient) * lightAmbient;
vec3 ambient = lightAmbient - ambientFactor + ambientFactor * lightDiffuse;
vec3 diffuseFactor = (1.0 - lightDiffuse) * lightDiffuse;
vec3 diffuse = lightDiffuse - diffuseFactor + diffuseFactor * lightAmbient;
color.rgb *= min((NL * diffuse + ambient), 1.0);
}
}

if(fogEnabled)
Expand Down

0 comments on commit 61e67db

Please sign in to comment.