Support reversed Z rendering and float32 offscreen depth buffer

Combined, both options greatly improve camera depth accuracy compared to
OpenGL default Z mapping and int24 depth buffer.

Requires GL_ARB_clip_control and ARB_depth_buffer_float extensions
This commit is contained in:
Levi Burner
2023-06-14 14:42:42 -04:00
parent e1549376f6
commit fc7b212369
10 changed files with 193 additions and 17 deletions
+15
View File
@@ -39,6 +39,15 @@ typedef enum mjtFramebuffer_ { // OpenGL framebuffer option
mjFB_OFFSCREEN // offscreen buffer
} mjtFramebuffer;
typedef enum mjtDepthMapping_ { // OpenGL depth buffer mapping (from znear to zfar)
mjDB_NEGONETOONE = 0, // Negative one to one (OpenGL default)
mjDB_ONETOZERO // Reversed Z buffer (decreases numerical error)
} mjtDepthMapping;
typedef enum mjtDepthPrecision_ { // OpenGL depth buffer precision
mjDB_INT24 = 0, // 24 bit integer buffer (OpenGL default)
mjDB_FLOAT32 // 32 bit float buffer
} mjtDepthPrecision;
typedef enum mjtFontScale_ { // font scale, used at context creation
mjFONTSCALE_50 = 50, // 50% scale, suitable for low-res rendering
@@ -151,6 +160,12 @@ struct mjrContext_ { // custom OpenGL context
// pixel output format
int readPixelFormat; // default color pixel format for mjr_readPixels
// depth buffer mode
int depthMapping; // depth buffer mapping from [znear zfar] to normalized device coordinates: mjDB_NEGONETOONE or mjDB_ONETOZERO
// depth buffer precision
int depthPrecision; // depth buffer precision: mjDB_INT24 or mjDB_FLOAT32
};
typedef struct mjrContext_ mjrContext;