How to draw from the inside of the light geometry in deferred shading

余生颓废 提交于 2019-12-01 08:30:42

问题


I'm trying to implement a deferred shader with OpenGL and GLSL and I'm having trouble with the light geometry. These are the steps I'm taking:

Bind multitarget framebuffer
Render color, position, normal and depth
Unbind framebuffer
Enable blend
Disable depth testing
Render every light
Enable depth testing
Disable blend
Render to screen

But since I'm only rendering the front face, when I'm inside a light it disappears completely, rendering the back face does not work, since I would get double the light power (And when inside, half [or the normal amount]).

How can I render the same light value from inside and outside the light geometry?


回答1:


If i remember correctly, in my deferred renderer i just render only the backfaces of the light volume. The drawback is you cannot depth test, you will only know if a light is behind a geometry after the light calculation is done and discard the pixel. As another answer explained, you can do depth testing. Test for greater or equal to see if the backface is behind or on a geometry, therefore intersects with the surface of the geometry.

Alternatively you could check if you are inside the light volume when rendering and switch front faces accordingly.




回答2:


well in my case, i do it like that:

Bind gbuffer framebuffer
Render color, position, normal
Unbind framebuffer

Enable blend
Enable depth testing

glDepthMask(0);
glCullFace(GL_FRONT);   //to render only backfaces
glDepthFunc(GL_GEQUAL); //to test if light fragment is "behind geometry", or it shouldn't affect it
Bind light framebuffer
Blit depth from gbuffer to light framebuffer //so you can depth-test light volumes against geometry
Render every light


来源:https://stackoverflow.com/questions/14413094/how-to-draw-from-the-inside-of-the-light-geometry-in-deferred-shading

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!