Light type attribute

Started by Thomas., June 15, 2012, 04:35:07 PM

Previous topic - Next topic

Thomas.

Please, could you add attribute for type of light, that will be sent to shader? Something like this...

uniform lowp int lightTypes[8];

For me is impossible to solve this problem in another way...

I wrote per-pixel spotlight, but I can't use point light and spotlight together...



edit: oh, and of course it's needs next attribute like light direction, spot cut off and spot exp... so maybe add some user variable?

EgonOlsen

You can already add as many user variables as you like. Just use one of the setUniform(...)-methods in GLSLShader. If you want to do it on a per object base, just extend GLSLShader and set the uniforms in setCurrentObject3D() of your implementations.

As for detecting which light is of which type...can't you simply define the first light as spot light and all others as point lights? That's what i did in my RPG in the dungeons. The first light is the light that influences the parallax mapping, all others use simple gouraud shading. The remaining problem is to ensure that the first light is always the same light, but you can do this with http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Light.html#setDistanceOverride(float) set to 0.

Thomas.

But, what if I want 2 lights as spotlight? there isn't any other solution for this?

EgonOlsen

Set both to 0...i know that it's a little kludgy, but you don't want to use a shader that bases this decision on a loop and some if(type==xxx)s in the fragment shader anyway, because it will be too slow on current devices (and will most likely render crap on Adreno...). The best solution is to use a specific shader for a specific situation. And if you already know the number of spot lights beforehand, you can easily make sure that they come first this way and greatly simplify your shader code.

Thomas.

But I can't use different parameters for individual lights...? Any idea why is compare integer number so slow? Ok, I try do it this way... excellent, so now I have 16 vertex, 16 fragment shaders for lights, 16 and 16 for particles and other billboard planes ;D ...

EgonOlsen

Every kind of dynamic branching stalls the pipeline if no branch prediction is being used. It's not the integer compare that is slow, it's the jump that might or might not happen. Some gpus even execute the code inside the if-block in all cases to avoid the pipeline stall and simplify the chip itself and only trash the result of the operation afterwards. ifs in the vertex shader are fine but they should be avoided in the fragment shader if possible. It not always is, of course.

Thomas.

Thank you for the explanation :)

Thomas.

After several hours of work everything running. I dynamically generate shaders depending on what is needed. For now working point and spot lights (but I need array of SimpleVector) in any number of. Direction light will be also added  :)