   Deferred lighting - skybox, objects without light ...
  Hello,i would like to ask few questions, because It's not clear for me.(native DirectX9, c++)I have classic deferred lighting in my application, i clear gbuffer, render scene to gbuffer, render lights and combine effect.but ! what if i want to render objects, which doesn't recieve light ? how to render skybox ? i tried to render another object, but there is problem with zbuffer, because i can see object though everything in scene.How to apply different materials ? custom shaders to objects ?Thank you very much for opinions, answers :)   
  You can use the stencil buffer to mark areas of the screen that don't want to be lit. A very simple implementation could set the stencil buffer to "1" everywhere you've rendered your G-Buffer. Then for lighting you just set your stencil test to only pass if the stencil value is 1, and you'll effectively ignore all of the pixels where you didn't render to G-Buffer. Then after your lighting pass, you can just render your skybox with the stencil set to pass for a value of 1 and you'll fill in the rest of the screen.Custom materials is a complex and open-ended problem for deferred rendering. Here are some possible approaches:-Put a material ID in your G-Buffer, and then branch on that value in your lighting pixel shader to choose your BRDF. -Use the ID to index into 3D lookup texture (more info on that here). -Instead of a material ID in the G-Buffer, set special stencil values for custom materials. Then you can fill in those pixels later by re-rendering that geometry, or you could render a set of special lights that only affect those pixels.-You can use a light pre-pass renderer, which gives you a little more flexibility with your materials since you re-render your geometry a second time.   ;  thank you for answer.about stencil buffer, how can i set it only for object, i don't what to have them lit ? I am thinking about this way: before object render, i set a parameter to shader, something like lit=0 and all pixels will be only diffuse + some effect ? is it possible ? i hope, my thought is right, how shader works :Di don't know, how to set stencil only for specified objects, so that's a reason, why i am thinking to try it this way.;  Draw the lit objects using deferred lighting, then draw skybox, etc using forward rendering without setting a light.   ;  The sky would just be rendered to the g-buffer with a shader which only wrote values to the emmissive/self-illuminating channel. The channel which is presented directly to the target buffer when doing the lighting pass.You'd use this for drawing lights such as neon signs and computer screens.   ;  great, skybox is working :)by the way, how can i pass material ID in texture ?? because value from texture is from 0.0 to 1.0 and :) we know a basic rule :) don't compare floats !so, how can i get number 0 - 255 like unsigned char for example ?   ;Quote:Original post by wh1sp3rikthank you for answer.about stencil buffer, how can i set it only for object, i don't what to have them lit ? I am thinking about this way: before object render, i set a parameter to shader, something like lit=0 and all pixels will be only diffuse + some effect ? is it possible ? i hope, my thought is right, how shader works :Di don't know, how to set stencil only for specified objects, so that's a reason, why i am thinking to try it this way.Before rendering your object, call SetRenderState and set D3DRS_STENCILENABLE to TRUE, and D3DRS_STENCILPASS to D3DSTENCILOP_REPLACE. Then set D3DRS_STENCILREF to 1, or whatever value you'd like to use for objects that shouldn't be lit.   