I already posted this on gamedev.stackexchange but its my third post about openGL stuff without any attention so I would like to try here.
I’m trying to implement Multisampled Antialiasing with 4 samples. This also works for the color attachment when I resolve it. The depth buffer doesnt seem to work with multisampled textures, but exactly the same scenario works if I use default 2D textures without multisampling. Here is how it looks like when I draw with enabled Depth Maskand Depth Test. (Antialiasing works, but depth testing doesnt…)
[ATTACH=CONFIG]1527[/ATTACH][ATTACH=CONFIG]1528[/ATTACH]
I created a few multisampled textures for Color, Position, TexCoord, Normal and Depth for now. This is an abstract example of how I created these textures:
GLXTexture2DMultisample finalImageColor = new GLXTexture2DMultisample(GBufferWidth, GBufferHeight, 4);
finalImageColor.CreateMutable(PixelInternalFormat.Rgba8);
finalImageColor.GetError(false);
// A few more textures will follow...
None of them throws an error. Now I will pass them to the Framebuffer, but for simplicity I only show my depth attachment line because everything else is working well.
GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthStencilAttachment, Depth24Stencil8, depthTexture.ID, 0);
Note that I’m not using a renderbuffer. Is this a problem? I’m doint this because I want to use the depth texture later. (As I said, it works good without multisampled textures)
Here is how I resolve the color texture:
#version 330
uniform sampler2DMS finalImage;
uniform vec2 samplerResolution;
uniform int samples;
in vec2 texCoords;
out vec4 fragColor;
void main(){
vec4 color = vec4(0.0);
ivec2 coords = ivec2(texCoords.x * samplerResolution.x, samplerResolution.y - texCoords.y * samplerResolution.y);
for(int i = 0; i < 4; i++)
color += texelFetch(finalImage, coords, i);
fragColor = color / samples;
}
I searched for that issue at google but I didnt even find an image which looks like a depth test issue caused by multisampled textures. Is there anything to keep in mind when using Multisampled Textures as a render target?