我从深度纹理重建片段位置以有效地执行照明计算。
问题在于,在没有几何形状的区域(例如下图中的地板,天花板和窗口),由于光照计算,片段输出颜色为黑色。我需要这些区域是白色的,以便可以看到天空盒。
如果像素片段在该位置没有原始几何体,我如何从着色器中检测?
void main(void)
{
// Calculate texture co-ordinate
vec2 gScreenSize = vec2(screenWidth, screenHeight);
vec2 TexCoord = gl_FragCoord.xy / gScreenSize;
// Get the Fragment Z position (from the depth buffer)
float z = texture(MyTexture2, vec2(TexCoord.s, TexCoord.t)).x * 2.0f - 1.0f;
vec4 clipSpacePosition = vec4(vec2(TexCoord.s, TexCoord.t) * 2.0 - 1.0, z, 1.0);
vec4 viewSpacePosition = inverseProjectionMatrix * clipSpacePosition;
// Get the Fragment XYZ position (perspective division, via it's depth value)
viewSpacePosition /= viewSpacePosition.w;
vec4 worldSpacePosition = inverseViewMatrix * viewSpacePosition;
vec3 fragPosition = worldSpacePosition.xyz;
// Lighting calulations
......
}