Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Deferred shading

Started by fatima Jun 18, 2010 at 12:54 PM 4 replies 1.9k views
Original Post
fatima
fatima
Hi
some questions about Deferred shading:
for each frame we have to create G-Buffer that contains material and normal info. So I think we have to do this:
Pass 1 :
vs : transform position to homogeneous clip space;
ps : render diffuse color to first render target;
Pass 2 :
vs : transform position to homogeneous clip space and normal to view space;
ps : render normals to second render target;
Pass 3:
Do same if needed;
Pass n:
Do lighting;
…
1 – Is this the true way?
2 - Is it possible to transform positions only once and reuse it for next passes? What’s multi target?
3 – Lighting is done in screen space, how can we detect which lights in scene must used for lighting?
sorry for my great English, I’m sure I will never learn it completely.
link3333
link3333
You can use Multiple Render Targets (DirectX) or OpenGL's equivalent. This way you only need one pass to output to the normal, position, and material buffers. At least with HLSL, you can specify an output to be COLOR0, COLOR1, etc. to put it on a particular render target.

You could always do frustum culling with the light position and radius to see what lights get applied. There's an article on Flipcode with a nice tutorial and a method for plane extraction from your view-projection matrix.

You may also want to check out Guerrilla Games's presentation on deferred shading. There's a nice optimization for medium to large sizes lights (in screen space) that helps removing rendering unlit pixels from going to the pixel shader.
shultays
shultays
for directional lights, you must render a full screen quad. for each pixel ps wil calculate angle between normal of pixel and direction of light and calculate the final color of the pixel using that value

for point lights you can use full screen quads but it is more inefficent. a better apprach is using a light volume (for example a sphere centered at ight postion and has radius of light range). this is like shadow volumes if you know about them. basically it finds the which part of the screen will be illuminated by light. there are 3 different cases while rendering light volume

if front face of model passes the depth test while back face does not, than it means that that pixel is affected by light.

if both sides fails at depth test than light is completly behind of an object so it does not illuminate anything

if both sides passes the depth test than light is floating in air and does not affect scene again.

you need to use stencil buffers. first render backside of light volume and set stencil buffer to some specific value if depth test fails (make sure that depth write is false). you will not render anything on color buffer in this pass. in the second pass render front face of light volume but this time enable stencil test and render object if stencil buffer is equal to what we set previous pass and depth test passes. in this second pass you should render the effect of light on color buffer.
taytay
fatima
fatima
ok, thanks.
for my 2nd question, please tell me how to setup multi render targets in HLSL.
and about lighting: I understand your answer completely. just some little questions:
1- what exactly do you mean about backside of light volume? dose it mean to draw back faces of light volume?
2 - about directional lights, I think I must create a small quad with normals parallel to light direction, and transform it to screen, is this ok?
thanks again.
IvicaKolic
IvicaKolic
On this page http://free-zg.t-com.hr/cssm/ you can find great sample of a deferred rendering system.

Every light type is supported + shadows.

There you'll find everything you need.

Cheers
fatima
fatima
thank you.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.