Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411275 Posts in 69323 Topics- by 58380 Members - Latest Member: bob1029

March 28, 2024, 07:20:48 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Lighting with deferred rendering
Pages: [1]
Print
Author Topic: Lighting with deferred rendering  (Read 843 times)
FTLRalph
Level 1
*

What?


View Profile
« on: March 13, 2015, 02:43:28 PM »

Hey all, still working on my 2D-deferred-rendering-with-lighting implementation, question time again!

So for those of you familiar with deferred rendering, I already have my geometry FBO populated with a diffuse buffer and a normal buffer.

I'm now currently at the stage where I need to add some lights to a "light accumulation buffer" and I have no idea what that means.


I take it I need a new FBO to render in - okay I got that. I also have an array full of light data objects (x, y, rgb, intensity, radius) - only dealing with point lights at the moment.

I'm assuming I need to for-loop through my lights, set the appropriate uniforms of a shader per light, draw the diffuseBuffer texture to the new light FBO while the shader does its lighting magic, and repeat.

However, I don't understand how that would work. Wouldn't I just overwrite the previous light after I draw over it in the next light pass? And the next one, and so on? What if lights overlap?

I believe looking at a standard normal-lighting GLSL shader for this type of implementation would really help. Or any advice, really.

Appreciate any help!
Logged
JakobProgsch
Level 1
*



View Profile
« Reply #1 on: March 14, 2015, 05:12:05 AM »

You typically use additive blending to accumulate the lights "glBlendFunc(GL_ONE, GL_ONE)" that way the light just gets added on top of the existing instead of replacing. Also if the lights are global (affect more than just a part of the screen) it's often preferable to pass a light array to the shader and loop over them in the shader since that reduces fill rate requirements/drawcalls.

The light shader itself in the 3d case usually involves reconstructing the fragment position from the depth buffer (requires the inverse projection matrix) and then using that position + normal to do the typical point light calculation. I'm not sure how exactly your 2d case looks since I'm not aware of a "standard 2d lighting" method. But the gist is hat you just do what you would do in the non deferred case... except that you now have to first reconstruct the required info from your deferred buffers.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic