Currently I'm trying to implement deferred shading in my engine. I mostly based on one tutorial founded in web (I don't paste link here due to links limitation :)) but I also use another sources and I know how deferred shading works. My current implementation base on calculating lights on full-screen quads for all light types. To get more speed I'd like to use bounding sphere for point light with stencil pass, but I have some problems with it.
The first and the biggest one is when I want render sphere in light pass to calculate only this pixels which will be affected by light. When I draw sphere in stencil pass and then calculate light on full-screen quad I think that everything works as it should (I only have bad sphere size, but its only for tests): image
But when I'm trying to render it on the same sphere which I used in stencil pass I've got weird results which are caused probably because of textures coordinates. When I don't use them I have everything black. When I use them I've got this.
In tutorials I saw that people just render sphere which contains only vertices positions and everything works ok so I don't know what's wrong.
I also have to make a little change in codes presented in tutorials from
glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR, GL_KEEP);
glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR, GL_KEEP);
to
glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR_WRAP, GL_KEEP);
glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR_WRAP, GL_KEEP);
and I also would like to know why this change helps mi with problem another when I'm outside sphere (I believe that you know what the problem is and I don't need to explain it).
The last question which I want ask you is what is the best formula to calculate sphere size and light attenuation based on for example only light power (which is floating number)?