Fixups to comments and flags for reversed Z rendering
This commit is contained in:
@@ -39,10 +39,10 @@ typedef enum mjtFramebuffer_ { // OpenGL framebuffer option
|
|||||||
mjFB_OFFSCREEN // offscreen buffer
|
mjFB_OFFSCREEN // offscreen buffer
|
||||||
} mjtFramebuffer;
|
} mjtFramebuffer;
|
||||||
|
|
||||||
typedef enum mjtDepthMapping_ { // OpenGL depth buffer readout mapping (from znear to zfar)
|
typedef enum mjtDepthMap_ { // depth mapping for `mjr_readPixels`
|
||||||
mjDM_ZEROTOONE = 0, // Legacy default, reverses reversed Z rendering, performance penalty
|
mjDEPTHMAP_01 = 0, // standard depth map; 0: znear, 1: zfar
|
||||||
mjDM_ONETOZERO // Native output of reversed Z rendering, decreases numerical error
|
mjDEPTHMAP_10 = 1 // reversed depth map; 1: znear, 0: zfar
|
||||||
} mjtDepthMapping;
|
} mjtDepthMap;
|
||||||
|
|
||||||
typedef enum mjtFontScale_ { // font scale, used at context creation
|
typedef enum mjtFontScale_ { // font scale, used at context creation
|
||||||
mjFONTSCALE_50 = 50, // 50% scale, suitable for low-res rendering
|
mjFONTSCALE_50 = 50, // 50% scale, suitable for low-res rendering
|
||||||
@@ -157,7 +157,7 @@ struct mjrContext_ { // custom OpenGL context
|
|||||||
int readPixelFormat; // default color pixel format for mjr_readPixels
|
int readPixelFormat; // default color pixel format for mjr_readPixels
|
||||||
|
|
||||||
// depth output format
|
// depth output format
|
||||||
int readDepthMapping; // depth mapping, 0 to 1 (default, legacy), or 1 to 0 (reversed, native)
|
int readDepthMap; // depth mapping: mjDEPTHMAP_01 or mjDEPTHMAP_10
|
||||||
};
|
};
|
||||||
typedef struct mjrContext_ mjrContext;
|
typedef struct mjrContext_ mjrContext;
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -621,13 +621,13 @@ ENUMS: Mapping[str, EnumDecl] = dict([
|
|||||||
('mjFB_OFFSCREEN', 1),
|
('mjFB_OFFSCREEN', 1),
|
||||||
]),
|
]),
|
||||||
)),
|
)),
|
||||||
('mjtDepthMapping',
|
('mjtDepthMap',
|
||||||
EnumDecl(
|
EnumDecl(
|
||||||
name='mjtDepthMapping',
|
name='mjtDepthMap',
|
||||||
declname='enum mjtDepthMapping_',
|
declname='enum mjtDepthMap_',
|
||||||
values=dict([
|
values=dict([
|
||||||
('mjDM_ZEROTOONE', 0),
|
('mjDEPTHMAP_01', 0),
|
||||||
('mjDM_ONETOZERO', 1),
|
('mjDEPTHMAP_10', 1),
|
||||||
]),
|
]),
|
||||||
)),
|
)),
|
||||||
('mjtFontScale',
|
('mjtFontScale',
|
||||||
|
|||||||
@@ -7127,9 +7127,9 @@ STRUCTS: Mapping[str, StructDecl] = dict([
|
|||||||
doc='default color pixel format for mjr_readPixels',
|
doc='default color pixel format for mjr_readPixels',
|
||||||
),
|
),
|
||||||
StructFieldDecl(
|
StructFieldDecl(
|
||||||
name='readDepthMapping',
|
name='readDepthMap',
|
||||||
type=ValueType(name='int'),
|
type=ValueType(name='int'),
|
||||||
doc='depth mapping, 0 to 1 (default, legacy), or 1 to 0 (reversed, native)', # pylint: disable=line-too-long
|
doc='depth mapping: mjDEPTHMAP_01 or mjDEPTHMAP_10',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ PYBIND11_MODULE(_render, pymodule) {
|
|||||||
X(windowDoublebuffer);
|
X(windowDoublebuffer);
|
||||||
X(currentBuffer);
|
X(currentBuffer);
|
||||||
X(readPixelFormat);
|
X(readPixelFormat);
|
||||||
X(readDepthMapping);
|
X(readDepthMap);
|
||||||
#undef X
|
#undef X
|
||||||
|
|
||||||
#define X(var) \
|
#define X(var) \
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ the clause:
|
|||||||
_render.mjr_setBuffer(
|
_render.mjr_setBuffer(
|
||||||
_enums.mjtFramebuffer.mjFB_OFFSCREEN.value, self._mjr_context
|
_enums.mjtFramebuffer.mjFB_OFFSCREEN.value, self._mjr_context
|
||||||
)
|
)
|
||||||
self._mjr_context.readDepthMapping = _enums.mjtDepthMapping.mjDM_ONETOZERO
|
self._mjr_context.readDepthMap = _enums.mjtDepthMap.mjDEPTHMAP_10
|
||||||
|
|
||||||
# Default render flags.
|
# Default render flags.
|
||||||
self._depth_rendering = False
|
self._depth_rendering = False
|
||||||
|
|||||||
@@ -1614,7 +1614,7 @@ void mjr_makeContext_offSize(const mjModel* m, mjrContext* con, int fontscale,
|
|||||||
con->readPixelFormat = GL_RGB;
|
con->readPixelFormat = GL_RGB;
|
||||||
|
|
||||||
// set default depth mapping for mjr_readPixels
|
// set default depth mapping for mjr_readPixels
|
||||||
con->readDepthMapping = mjDM_ZEROTOONE;
|
con->readDepthMap = mjDEPTHMAP_01;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1836,7 +1836,6 @@ MJAPI void mjr_resizeOffscreen(int width, int height, mjrContext* con) {
|
|||||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, con->offWidth, con->offHeight);
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, con->offWidth, con->offHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, con->offDepthStencil);
|
glBindRenderbuffer(GL_RENDERBUFFER, con->offDepthStencil);
|
||||||
if (con->offSamples) {
|
if (con->offSamples) {
|
||||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, con->offSamples, GL_DEPTH32F_STENCIL8,
|
glRenderbufferStorageMultisample(GL_RENDERBUFFER, con->offSamples, GL_DEPTH32F_STENCIL8,
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ void mjr_readPixels(unsigned char* rgb, float* depth,
|
|||||||
if (depth) {
|
if (depth) {
|
||||||
glReadPixels(viewport.left, viewport.bottom, viewport.width, viewport.height,
|
glReadPixels(viewport.left, viewport.bottom, viewport.width, viewport.height,
|
||||||
GL_DEPTH_COMPONENT, GL_FLOAT, depth);
|
GL_DEPTH_COMPONENT, GL_FLOAT, depth);
|
||||||
if (con->readDepthMapping == mjDM_ZEROTOONE) {
|
if (con->readDepthMap == mjDEPTHMAP_01) {
|
||||||
int N_pixels = viewport.width * viewport.height;
|
int N_pixels = viewport.width * viewport.height;
|
||||||
for (int i = 0; i < N_pixels; i++) depth[i] = 1.0 - depth[i]; // Reverse the reversed Z buffer
|
for (int i = 0; i < N_pixels; i++) depth[i] = 1.0 - depth[i]; // Reverse the reversed Z buffer
|
||||||
}
|
}
|
||||||
@@ -164,7 +164,7 @@ void mjr_readPixels(unsigned char* rgb, float* depth,
|
|||||||
glReadPixels(viewport.left, viewport.bottom, viewport.width, viewport.height,
|
glReadPixels(viewport.left, viewport.bottom, viewport.width, viewport.height,
|
||||||
GL_DEPTH_COMPONENT, GL_FLOAT, depth);
|
GL_DEPTH_COMPONENT, GL_FLOAT, depth);
|
||||||
|
|
||||||
if (con->readDepthMapping == mjDM_ZEROTOONE) {
|
if (con->readDepthMap == mjDEPTHMAP_01) {
|
||||||
int N_pixels = viewport.width * viewport.height;
|
int N_pixels = viewport.width * viewport.height;
|
||||||
for (int i = 0; i < N_pixels; i++) depth[i] = 1.0 - depth[i]; // Reverse the reversed Z buffer
|
for (int i = 0; i < N_pixels; i++) depth[i] = 1.0 - depth[i]; // Reverse the reversed Z buffer
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -601,9 +601,9 @@ static void setView(int view, mjrRect viewport, const mjvScene* scn, const mjrCo
|
|||||||
// set projection
|
// set projection
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
// reverse Z rendering mapping (znear, zfar) -> (1, 0)
|
// reverse Z rendering mapping [znear, zfar] -> [1, 0]
|
||||||
glTranslatef(0,0,0.5);
|
glTranslatef(0.0f, 0.0f, 0.5f);
|
||||||
glScalef(1,1,-0.5);
|
glScalef(1.0f, 1.0f, -0.5f);
|
||||||
glFrustum(cam.frustum_center - halfwidth,
|
glFrustum(cam.frustum_center - halfwidth,
|
||||||
cam.frustum_center + halfwidth,
|
cam.frustum_center + halfwidth,
|
||||||
cam.frustum_bottom,
|
cam.frustum_bottom,
|
||||||
@@ -682,7 +682,6 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
|
|||||||
0.0f, 0.0f, 1.0f, 0.0f,
|
0.0f, 0.0f, 1.0f, 0.0f,
|
||||||
0.5f, 0.5f, 0.0f, 1.0f
|
0.5f, 0.5f, 0.0f, 1.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
float tempMatrix[16], textureMatrix[16];
|
float tempMatrix[16], textureMatrix[16];
|
||||||
mjvGeom *thisgeom, tempgeom;
|
mjvGeom *thisgeom, tempgeom;
|
||||||
mjvLight *thislight;
|
mjvLight *thislight;
|
||||||
@@ -1030,9 +1029,9 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
|
|||||||
// set projection: from light viewpoint
|
// set projection: from light viewpoint
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
// reverse Z rendering mapping (znear, zfar) -> (1, 0)
|
// reverse Z rendering mapping [znear, zfar] -> [1, 0]
|
||||||
glTranslatef(0,0,0.5);
|
glTranslatef(0.0f, 0.0f, 0.5f);
|
||||||
glScalef(1,1,-0.5);
|
glScalef(1.0f , 1.0f, -0.5f);
|
||||||
if (thislight->directional) {
|
if (thislight->directional) {
|
||||||
glOrtho(-con->shadowClip, con->shadowClip,
|
glOrtho(-con->shadowClip, con->shadowClip,
|
||||||
-con->shadowClip, con->shadowClip,
|
-con->shadowClip, con->shadowClip,
|
||||||
|
|||||||
@@ -389,9 +389,9 @@ public enum mjtFramebuffer : int{
|
|||||||
mjFB_WINDOW = 0,
|
mjFB_WINDOW = 0,
|
||||||
mjFB_OFFSCREEN = 1,
|
mjFB_OFFSCREEN = 1,
|
||||||
}
|
}
|
||||||
public enum mjtDepthMapping : int{
|
public enum mjtDepthMap : int{
|
||||||
mjDM_ZEROTOONE = 0,
|
mjDEPTHMAP_01 = 0,
|
||||||
mjDM_ONETOZERO = 1,
|
mjDEPTHMAP_10 = 1,
|
||||||
}
|
}
|
||||||
public enum mjtFontScale : int{
|
public enum mjtFontScale : int{
|
||||||
mjFONTSCALE_50 = 50,
|
mjFONTSCALE_50 = 50,
|
||||||
|
|||||||
Reference in New Issue
Block a user