🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Deffered Shaing sending multiple source of light to shader

Started by
3 comments, last by Jihodg 4 years, 1 month ago

I wrote a simple deferred shading shader for my engine, and I send light-sources to the shader like this:

struct Light {
    vec3 Position;
    vec4 Color;

    float Linear;
    float Quadratic;
    float Radius;
};

const int NR_LIGHTS = 4;
uniform Light lights[NR_LIGHTS];

well this works when I have fixed number of lights, but this wouldn't be a good idea with many light sources as we do have limits with number of uniforms and when the number of lights are dynamic.

I am using OpenGL 3.3, what is the best way of sending several light-sources to a shader.

Advertisement

Multipassing. You set up your shader for 1 light, then draw each light separately with additive blending enabled.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Alternatively, you can use a texture as input for the light data.

There are different ups and downs for using multipass vs. singlepass. Singlepass I belive can achieve the higher light count with the better performance, but you have to invest a bit more into setup. Other upsides of being single-pass is that accumulation of all light-data happens inside registers and is thus more precise, even when using a low-precision render-target.

If you are interested in single-pass, you might want to look at “clustered defered” shading (http://www.humus.name/Articles/PracticalClusteredShading.pdf).​ Not sure how much overhead something like this would be for you, just putting it out there.

or just use a uniform buffer and check for GL_MAX_UNIFORM_BLOCK_SIZE… I think it is always at least 16384 bytes, and for most vendors and drivers 65536+ bytes… so you can easily fit hundreds of lights

https://opengl.gpuinfo.org/displaycapability.php?name=GL_MAX_UNIFORM_BLOCK_SIZE

This topic is closed to new replies.

Advertisement