PDA

View Full Version : 32 bit floating point depth precision on default framebuffer



uros3D
02-10-2016, 02:23 PM
Greetings,

Recently I started working on existing rendering engine and took upon myself to resolve some z-fighting issues occurring when moving camera away from objects. The scene can get quite large and the camera's near and far must cover pretty big range. Moving the near plane is kinda out of the question (it's 0.1 atm). Using some shader trickery is also far fetched as it will require a MAJOR engine rewrite.

I managed to get 32bit floating point depth buffer enabled when rendering to FBO (eg making a screenshot) and did the inverted z-buffer trick, the results were amazing.

The question is, is it at all possible to get 32bit FP depth buffer on default framebuffer (Windows)? I tried setting it up with instructions from

here: https://www.opengl.org/wiki/Creating_an_OpenGL_Context_(WGL)

and here: https://www.opengl.org/registry/specs/ARB/color_buffer_float.txt

My attrib list:


int attribList[] =
{
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_FLOAT_ARB, //Instead of WGL_TYPE_RGBA_ARB
WGL_COLOR_BITS_ARB, 32,
WGL_DEPTH_BITS_ARB, 32,
WGL_STENCIL_BITS_ARB, 0,
0, //End
};

but I get no matching pixelformats returned by wglChoosePixelFormatARB although all required extensions are supported by my card(GTX 765m). Is it some Windows limitation? I'm on Windows 10 64bit with the latest nVidia drivers.

How much of a performance hit would be to always render everything to FBO and then just draw textured quad fullscreen using default framebuffer? Or is that a "no-no" way to go around default framebuffer limitations? :)

mhagain
02-10-2016, 02:59 PM
This isn't a Windows limitation because you can do it in D3D.

Alfonse Reinheart
02-10-2016, 04:53 PM
How much of a performance hit would be to always render everything to FBO and then just draw textured quad fullscreen using default framebuffer? Or is that a "no-no" way to go around default framebuffer limitations?

With deferred rendering being commonplace in many real applications, this is a common way to render.

However, you should not expect merely rendering to a floating-point framebuffer to do anything about your z-fighting issues. See this blog post for details on why (http://outerra.blogspot.de/2012/11/maximizing-depth-buffer-range-and.html). You'll need to employ GL 4.5 or ARB_clip_control to actually take advantage of that. Or restrict yourself to NVIDIA hardware.

uros3D
02-11-2016, 01:15 AM
Yeah I've stumbled upon that article. As I said, I managed to get the FP z-buffer on FBO using GL_NV_depth_buffer_float extension using guidelines from here: https://www.opengl.org/discussion_boards/showthread.php/185674-How-to-setup-projectionMatrix-worldMatrix-for-use-with-inverted-float-depth-buffer

But I can't seem to get the FP mode on default window's framebuffer, the best pixelformat match I've got is 32bit integer depth (WGL_TYPE_RGBA_ARB as WGL_PIXEL_TYPE_ARB value).

The wglGetExtensionsStringARB says that WGL_ARB_pixel_format_float is supported so I don't see what's the problem here.

GClements
02-11-2016, 03:02 AM
The wglGetExtensionsStringARB says that WGL_ARB_pixel_format_float is supported so I don't see what's the problem here.

WGL_ARB_pixel_format_float gives you floating-point colour buffers. You need WGL_EXT_depth_float to get a floating-point depth buffer.

uros3D
02-11-2016, 03:43 AM
WGL_ARB_pixel_format_float gives you floating-point colour buffers. You need WGL_EXT_depth_float to get a floating-point depth buffer.

Aaah, well, that settles it then. My card has no support for such extension. But it is still weird that even WGL_TYPE_RGBA_FLOAT_ARB yields no supported pixelformat for DC.

I will give a shot to FBO rendering then.

Thanks to everyone who pitched in, any other suggestions are welcome :)