Skip to content

Weird If statement #19

Description

@ypiadyk

Hello Benny.
As in video #31 of Java Game Engine Development Tutorial I add line in the fragment shader inside the for loop over the point lights:
if(pointLights[i].base.intensity > 0)
But instead of FPS growth I get no point light drawn in the scene. After the whole day of experiments I've noticed:

  • if I compare with some negative constant instead of 0 then all lights are back but if statement seems to be ignored
  • if I assign all three attenuation coefficient to non-zero values lights are back as in previous case. If statement is still not working
  • out of range check in calcPointLight function works just fine (if(distanceToPoint > pointLight.range) return vec4(0,0,0,0);), so I tried to do the same but with pointLight.base.intensity - no success. If I set some intensity threshold that only one of the lights can pass I still get no lights or all lights drawn.

I can't believe that if statement is not working and not to have this kind of optimization is also not a case. The same is observed in c++ version (Initial Commit). Any ideas?
And some more questions: don't we need to specify in/out/inout parameters for input parameters of the functions as in http://www.opengl.org/wiki/GLSL_:_common_mistakes
And second one: is there any better than:
if (textureColor != vec4(0, 0, 0, 0))
way to check inside the shader if some texture was bound? Because current one can cause artefacts if texture contains black pixels with alpha value equal zero.
Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions