gpt4 book ai didi

c# - 多重采样 FBO 忽略深度测试

转载 作者:太空宇宙 更新时间:2023-11-03 21:02:01 25 4
gpt4 key购买 nike

我修改了我的渲染引擎以使用多重采样纹理,除了现在深度测试被忽略。

这是我创建多重采样 FBO 的方式,

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);
}

执行决议,

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);
}

并渲染图像,

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);
}

最佳答案

您的多重采样 FBO 没有深度缓冲区,因此深度测试将不起作用。尽管您实际上创建了一个具有 GL_DEPTH_COMPONENT 格式的多重采样渲染缓冲区,但您忘记将其附加为 FBO 的 GL_DEPTH_ATTACHMENT。您需要添加一个 glFramebufferRenderbuffer()调用您的 MSAA_FBO() 函数。

关于c# - 多重采样 FBO 忽略深度测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44610694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com