0

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)?

logain
  • 1,475
  • 1
  • 12
  • 18
Harry
  • 144
  • 2
  • 9
  • "*with stencil pass*" What's the stencil for? – Nicol Bolas Aug 17 '13 at 13:13
  • It is used to discard pixels which shouldn't included in lighting calculations. It also fix some problems for example when camera enters in light volume. Because of face culling light dissapear in this situation. [Here](http://ogldev.atspace.co.uk/www/tutorial37/tutorial37.html) it is explained better. I think that this problem doesn't exist when I do light calculations on full-screen quad, but when I do them using bounding sphere. Unfortunately I can't test it because of problem which I mentioned above. – Harry Aug 17 '13 at 13:37
  • Light power? You usually use a combination of quadratic, linear and constant attenuation. You solve for the distance (d) that gives zero using the traditional attenuation equation (1/(kc+kl+kq*d^2)) to compute your light's minimum radius. A general overview can be found here: http://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/ – Andon M. Coleman Aug 17 '13 at 23:06
  • Thanks, I also found [here](http://framebunker.com/blog/lighting-2-attenuation/) some interesting attenuation equation which works pretty well. – Harry Aug 18 '13 at 14:15

0 Answers0