2017-06-18 2 views
1

J'ai modifié mon moteur de rendu pour utiliser des textures multi-échantillonnées, sauf que maintenant les tests de profondeur sont ignorés.Le FBO multi-échantillonné ignore les tests de profondeur

Voilà comment je crée l'OIR multiéchantillonné,

public MSAA_FBO(int WindowWidth, int WindowHeight) 
{ 
    this.width = WindowWidth; 
    this.height = WindowHeight; 

    GL.GenFramebuffers(1, out ID); 
    GL.BindFramebuffer(FramebufferTarget.Framebuffer, ID); 

    // Colour texture 
    GL.GenTextures(1, out textureColorBufferMultiSampled); 
    GL.BindTexture(TextureTarget.Texture2DMultisample, textureColorBufferMultiSampled); 
    GL.TexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, 4, PixelInternalFormat.Rgb8, WindowWidth, WindowHeight, true); 
    GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2DMultisample, textureColorBufferMultiSampled, 0); 

    // Depth render buffer 
    GL.GenRenderbuffers(1, out RBO); 
    GL.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, RBO); 
    GL.RenderbufferStorageMultisample(RenderbufferTarget.Renderbuffer, 4, RenderbufferStorage.DepthComponent, WindowWidth, WindowHeight); 
    GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0); 

    var status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); 
    Console.WriteLine("MSAA: " + status); 
    GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); 
}  

effectuer la détermination,

public void resolveToFBO(FBO outputFBO) 
{ 
    GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, outputFBO.ID); 
    GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, this.ID); 
    GL.BlitFramebuffer(0, 0, this.width, this.height, 0, 0, outputFBO.width, outputFBO.height, ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit, BlitFramebufferFilter.Nearest);  
} 

et rendu de l'image,

public void MSAAPass(Shader shader) 
{ 
    GL.UseProgram(shader.ID); 
    GL.BindFramebuffer(FramebufferTarget.Framebuffer, MSAAbuffer.ID); 
    GL.Viewport(0, 0, Width, Height); 

    GL.Enable(EnableCap.Multisample); 
    GL.ClearColor(System.Drawing.Color.Black); 
    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); 
    GL.Enable(EnableCap.DepthTest); 
    GL.Disable(EnableCap.Blend); 

    // Uniforms 
    Matrix4 viewMatrix = player.GetViewMatrix(); 
    GL.UniformMatrix4(shader.getUniformID("viewMatrix"), false, ref viewMatrix); 

    // Draw all geometry 
    DrawScene(shader); 

    GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); 
    MSAAbuffer.resolveToFBO(testBuffer); 
} 
+1

Celui qui a voté pour fermer cela comme une simple erreur typographique est un imbécile – MickyD

Répondre

4

Votre multiéchantillonné OIR n'a pas un tampon de profondeur, d'où le test de profondeur ne fonctionnera pas. Bien que vous ayez créé un renderbuffer multisamplé avec le format GL_DEPTH_COMPONENT, vous avez oublié de joindre celui-ci en tant que GL_DEPTH_ATTACHMENT de votre FBO. Vous devez ajouter un appel glFramebufferRenderbuffer() dans votre fonction MSAA_FBO().

+0

Ahh! Je vous remercie. –