Regrding defrred rendring wth 2 shders [SOLVED]

Hi all,
I am trying to do deferred rendering whereby i first store the normals into a texture and then I use this texture in the second pass to shade. My setup (fbo and attachments is fine). This I have tested by outputting the intermediate result before shading however in the second deferred shader, the intemediate result does not appear (all black pixels). What may be causing this? A high level pseudocode is something along these lines.


bind first fbo1  
use normals output shader
   drawMesh();
unbind fbo1

bind normals texture to TEXTURE1

bind second fbo2
use deferred shader
bind mesh texture to TEXTURE0 
   render fullscreen quad
unbind fbo2


EDIT: As is normally the case, I have the problem sorted already. It was always working fine. For some reason I was breaking from the shader before the texture function was called and so the texture was never sampled.

OK i have one more thing to ask, I want to get the current depth from the first pass. I am currently doing it this way but it does not return anything.


void main()
{ 		
   vFragColor = vec4(out_normal,gl_FragDepth);  	
}

What are you going to use the depth information for? Are you sure you don’t want the linear depth?

Hi Thokra,
Yeah I just realized I dont need depth at all. Just somethings mixing up here. It solved now though thanks for dropping by.

When implementing a deferred shading or lighting approach I think this is highly unlikely in the long term. :slight_smile:

HI Thokra,
I want to ask how to do shadows with deferred rendering. Can I work with shadow maps? Is there a reference on this?

Yes you can. The lighting computation isn’t the biggest problem with classic deferred shading. In its most naive version it’s using multiple materials.

Usually you’ll render all necessary attributes to a fat framebuffer. The only thing you need is some positional information so you can transform vertices to lightspace.

In my light pre-pass renderer this is almost equal to your code snippet above. Only difference is that I store the actual distance from the camera in the alpha component of the normal buffer. With this you can easily reconstruct the world space position of any visible fragment, transform it to light space and do the lookup.

One question is, how do you currently handle multiple light sources?

There are a number of ways to do this. Here are a few:

[ol][li]After rasterizing your G-Buffer, when doing the lighting pass to apply the light(s) that cast shadows, do standard shadow map lookups as you’d normally do for the light(s) being applied), and use that to attenuate the lit diffuse and specular intensities when you’re computing the total radiance/color.[*]During or after rasterizing your G-buffer, you can rasterize your shadows into an intensity-based channel of the G-buffer using standard shadow map lookups as normal. This channel can be applied later in your lighting pass(es) by attenuating diffuse/specular. Some call this technique Deferred Shadowing or the Shadow Collector approach.[/ol][/li]The first approach obviously scales better if you’re going to have more than 1 light source casting shadows. And there aren’t any useless shadow map lookups for occluded opaque geometry, since you only do lookups for geometry that’s made it to the G-buffer.

However what some folks like about #2 is being able to do “screen space blurs” (often edge-discontinuity sensitive filtering) on the shadow G-buffer channel after rasterizing it but before applying it) to try and hide shadow mapping artifacts.

In either case as thokra said, you need a way to generate a position in some canonical space (EYE-SPACE, in my case) from the data stored in your G-buffer to pass to your shadow map lookup code.

And of course, lighting/shadowing of translucents are handled specially, typically via Forward Shading, though there are other options.

A few links on #2, though I know there are more out there on this:

#1 is an easy first step. Then you can stack on #2 if you feel motivated to.

In addition to Dark Photon’s links you may also want to look at this GDC presentation:

http://developer.amd.com/gpu_assets/Deferred%20Shading%20Optimizations.pps

Deferred Shadowing is also briefly mentioned there.

Thanks for the links guys thats a lot of stuff to digest for a couple of days :slight_smile: