我無法將我的shadow mapping實現從正向呈現轉換爲延遲呈現。我找到了這個問題,並且它沒有被髮送到着色器。我懷疑這是因爲我的「GBuffer」FBO綁定而不是立方體貼圖FBO。OpenGL - 在綁定不同的FBO時訪問立方體貼圖
如果GLSL可以在一次繪製調用中訪問來自兩個不同FBO的彩色附件,我想要走這條路線,這可能嗎?
下面,工作轉發渲染代碼。
public void NormalPass(Shader shader)
{
// Reset state
GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
GL.BindTexture(TextureTarget.Texture2D, 0);
GL.UseProgram(shader.ID);
GL.Viewport(0, 0, Width, Height);
GL.CullFace(CullFaceMode.Back);
GL.ClearColor(0.5f, 0.5f, 0.5f, 1f);
// Uniforms
Matrix4 viewMatrix = player.GetViewMatrix();
Matrix4 projectionMatrix;
Matrix4.CreatePerspectiveFieldOfView((float)Math.PI/4, (float)Width/(float)Height, 0.1f, 100.0f, out projectionMatrix);
GL.UniformMatrix4(shader.viewMatrixLocation, false, ref viewMatrix);
GL.UniformMatrix4(shader.projectionMatrixLocation, false, ref projectionMatrix);
GL.Uniform3(shader.lightPositionLocation, lightPos);
GL.BindTexture(TextureTarget.TextureCubeMap, cubeTex);
DrawScene(shader, false); // False = Not shadowpass
GL.BindTexture(TextureTarget.TextureCubeMap, 0);
}
這裏,失敗的延遲渲染修改
public void Composite(Shader shader)
{
//Set up FBO reading/writing
GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0);
GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, gBuffer.FBO);
// Bind textures
GL.ActiveTexture(TextureUnit.Texture2);
GL.BindTexture(TextureTarget.Texture2D, gBuffer.positionTexture);
GL.ActiveTexture(TextureUnit.Texture1);
GL.BindTexture(TextureTarget.Texture2D, gBuffer.normalTexture);
GL.UseProgram(shader.ID);
GL.Disable(EnableCap.DepthTest);
GL.Viewport(0, 0, Width, Height);
GL.CullFace(CullFaceMode.Back);
GL.ClearColor(0.5f, 0.5f, 0.5f, 1f);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
// Uniforms
Matrix4 viewMatrix = player.GetViewMatrix();
GL.UniformMatrix4(shader.viewMatrixLocation, false, ref viewMatrix);
GL.Uniform3(shader.lightPositionLocation, lightPos);
GL.BindTexture(TextureTarget.TextureCubeMap, cubeTex);
Quad2D.drawScreenSizedQuad(); // Draw the combined lighting and diffuse to screen
GL.BindTexture(TextureTarget.TextureCubeMap, 0);
}
快樂按要求提供任何信息。
這清除了我的許多誤解,肯定會讓我在賽道上節省很多時間,非常感謝Jason。順便說一下,它現在也在工作。 –