deferred shading question
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 :pNot 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 )Now I havn't done much in OpenGL, so Im not familiar with the syntaxes of this.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;}
Hope this helps.
-MIGI0027
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.
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?
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.
(The color is weird because its red channel ONLY!)