Jump to content
  • Advertisement
Sign in to follow this  
newtechnology

deferred shading question

This topic is 1576 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

Not at all, actually it happens that you can output multiple colors (i.e. write to multiple render targets ) at the same time. 

 

As an example, in DirectX, when you set the render targets, you have the choice of passing an array of render target pointers, and then in the pixel shader, you would do the following: ( Top of my head, so there may be small mistakes )

struct PixelOut
{
    float4 Color : SV_Target0;
    float4 Normal : SV_Target1;
};

PixelOut PS(...)
{
    PixelOut out = (PixelOut)0;

    .. do the usual stuff, and fill out.Color and out.Normal ..

   return out;
}

Now I havn't done much in OpenGL, so Im not familiar with the syntaxes of this.

 

Hope this helps.

-MIGI0027

Share this post


Link to post
Share on other sites

Not at all, actually it happens that you can output multiple colors (i.e. write to multiple render targets ) at the same time.

As an example, in DirectX, when you set the render targets, you have the choice of passing an array of render target pointers, and then in the pixel shader, you would do the following: ( Top of my head, so there may be small mistakes )

struct PixelOut{    float4 Color : SV_Target0;    float4 Normal : SV_Target1;};PixelOut PS(...){    PixelOut out = (PixelOut)0;    .. do the usual stuff, and fill out.Color and out.Normal ..   return out;}
Now I havn't done much in OpenGL, so Im not familiar with the syntaxes of this.

Hope this helps.
-MIGI0027
Thanks. Also I use directs 11 not opengl :p
Edit: how does normal mapping fit into deferred shading?

Share this post


Link to post
Share on other sites

Normal mapping works perfectly fine with deferred shading. You may output an interpolated vertex normal or a normal from a texture to the render target. Only thing that you'll need to define is the common space where you want to do your lighting (typically either in view space or world space). That means that you'll have to transform the normal from tangent space to the desired space.

 

Cheers!

 

[edit]

 

typically you'd use more than 2 render targets to store more variables needed for lighting calculations such as roughness / shininess, specular factor, metalness ... what ever is required by your lighting system. 

Edited by kauna

Share this post


Link to post
Share on other sites

Do I have to render scene twice in deferred shading ?

There are two similar techniques, deferred shading and deferred lighting.

 

deferred rendering:

1. render geometry(scene) to multiple buffers (color, material, normals,depth). the buffer holding the normal/depth is called g-buffer (for geometry), because you can reconstruct the visible 3d scene from it.

2. render multiple post processing passes on-top of the g-buffer (remember, you can reconstruct the 3d world from it), one of the most important post-processsing pass it the lighting pass.

 

deferred lighting

1. render geometry to mulitple buffers, but do not render color or material informations (only normal/depth).

2. render a lighting post-processing pass, this will write all lighting informationen to a new buffer.

3. render the geometry a second time, this time combine the color/material of your models with the lightbuffer

4. render some post-processing passes

 

The deferred rendering only needs one geometry pass,whereas deferred lighting needs two. On the other hand, deferred lighting has better lighting performance (you combine light/color/material only in the last step) and less material limitations.

Edited by Ashaman73

Share this post


Link to post
Share on other sites

Thanks for all this, i've another question. Will i still have to render objects twice? One foe gbuffers and one normally?

 

No, under the deferred rendering system described by Ashaman73, you render your objects once to fill the gbuffers, then the post-processing steps are all done as 2D passes.

Share this post


Link to post
Share on other sites
Now i have implemented deferred shading but where do i store material and light properties like diffuse, specular, ambient, reflect, specular power? Also how do i use multiple lights with deferred shading?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!