Skip to content

Commit

Permalink
Revert "- eliminate an unexpected slow path in the fragment shader."
Browse files Browse the repository at this point in the history
This reverts commit cd5aa65.

This does not work as expected, needs more investigation.
  • Loading branch information
coelckers committed Aug 9, 2021
1 parent cd5aa65 commit 39513cf
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion wadsrc/static/shaders/glsl/main.fp
Expand Up @@ -595,7 +595,7 @@ vec4 getLightColor(Material material, float fogdist, float fogfactor)
{
vec4 color = vColor;

if ((uPalLightLevels >> 16) >= 5) // gl_lightmode >= 5 are software lighting modes.
if (uLightLevel >= 0.0)
{
float newlightlevel = 1.0 - R_DoomLightingEquation(uLightLevel);
color.rgb *= newlightlevel;
Expand Down

2 comments on commit 39513cf

@Talon1024
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shaders have to run in constant time, so every code path is executed, and the results are discarded if the conditions are not met. It's best to avoid "if"s as much as possible when writing shaders.

@coelckers
Copy link
Member Author

@coelckers coelckers commented on 39513cf Aug 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's absolutely not correct with modern hardware anymore. If a condition is uniformly true or false the conditional path will be skipped entirely. The majority of 'if's in this shader is based on uniforms (i.e. constant per primitive and often even per scene) And this are provably faster than switching shaders depending on what path is needed.

With this one there seem to be some weird things going on. I reverted this because there's places in the code where this was causing render glitches. It also seems to be a bit random when the shader starts to hit a slow path. This is not consistent but seems to mainly depend on the lighting stuff.

Please sign in to comment.