deferred shading question

Started by
15 comments, last by phil_t 9 years, 11 months ago
Do I have to render scene twice in deferred shading ? I.e one for normal buffer and one for color buffer?
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

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

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?

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.

You may find this presentation useful: The Rendering Technology of Killzone 2

SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

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.

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

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.

Thanks, I've started implementing deferred shading.

7gTUVzl.png

(The color is weird because its red channel ONLY!)

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?

This topic is closed to new replies.

Advertisement