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
|
||||
} mjtFramebuffer;
|
||||
|
||||
typedef enum mjtDepthMapping_ { // OpenGL depth buffer readout mapping (from znear to zfar)
|
||||
mjDM_ZEROTOONE = 0, // Legacy default, reverses reversed Z rendering, performance penalty
|
||||
mjDM_ONETOZERO // Native output of reversed Z rendering, decreases numerical error
|
||||
} mjtDepthMapping;
|
||||
typedef enum mjtDepthMap_ { // depth mapping for `mjr_readPixels`
|
||||
mjDEPTHMAP_01 = 0, // standard depth map; 0: znear, 1: zfar
|
||||
mjDEPTHMAP_10 = 1 // reversed depth map; 1: znear, 0: zfar
|
||||
} mjtDepthMap;
|
||||
|
||||
typedef enum mjtFontScale_ { // font scale, used at context creation
|
||||
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
|
||||
|
||||
// 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;
|
||||
|
||||
|
||||
+5
-5
@@ -621,13 +621,13 @@ ENUMS: Mapping[str, EnumDecl] = dict([
|
||||
('mjFB_OFFSCREEN', 1),
|
||||
]),
|
||||
)),
|
||||
('mjtDepthMapping',
|
||||
('mjtDepthMap',
|
||||
EnumDecl(
|
||||
name='mjtDepthMapping',
|
||||
declname='enum mjtDepthMapping_',
|
||||
name='mjtDepthMap',
|
||||
declname='enum mjtDepthMap_',
|
||||
values=dict([
|
||||
('mjDM_ZEROTOONE', 0),
|
||||
('mjDM_ONETOZERO', 1),
|
||||
('mjDEPTHMAP_01', 0),
|
||||
('mjDEPTHMAP_10', 1),
|
||||
]),
|
||||
)),
|
||||
('mjtFontScale',
|
||||
|
||||
@@ -7127,9 +7127,9 @@ STRUCTS: Mapping[str, StructDecl] = dict([
|
||||
doc='default color pixel format for mjr_readPixels',
|
||||
),
|
||||
StructFieldDecl(
|
||||
name='readDepthMapping',
|
||||
name='readDepthMap',
|
||||
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(currentBuffer);
|
||||
X(readPixelFormat);
|
||||
X(readDepthMapping);
|
||||
X(readDepthMap);
|
||||
#undef X
|
||||
|
||||
#define X(var) \
|
||||
|
||||
@@ -86,7 +86,7 @@ the clause:
|
||||
_render.mjr_setBuffer(
|
||||
_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.
|
||||
self._depth_rendering = False
|
||||
|
||||
@@ -1614,7 +1614,7 @@ void mjr_makeContext_offSize(const mjModel* m, mjrContext* con, int fontscale,
|
||||
con->readPixelFormat = GL_RGB;
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, con->offDepthStencil);
|
||||
if (con->offSamples) {
|
||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, con->offSamples, GL_DEPTH32F_STENCIL8,
|
||||
|
||||
@@ -115,7 +115,7 @@ void mjr_readPixels(unsigned char* rgb, float* depth,
|
||||
if (depth) {
|
||||
glReadPixels(viewport.left, viewport.bottom, viewport.width, viewport.height,
|
||||
GL_DEPTH_COMPONENT, GL_FLOAT, depth);
|
||||
if (con->readDepthMapping == mjDM_ZEROTOONE) {
|
||||
if (con->readDepthMap == mjDEPTHMAP_01) {
|
||||
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
|
||||
}
|
||||
@@ -164,7 +164,7 @@ void mjr_readPixels(unsigned char* rgb, float* depth,
|
||||
glReadPixels(viewport.left, viewport.bottom, viewport.width, viewport.height,
|
||||
GL_DEPTH_COMPONENT, GL_FLOAT, depth);
|
||||
|
||||
if (con->readDepthMapping == mjDM_ZEROTOONE) {
|
||||
if (con->readDepthMap == mjDEPTHMAP_01) {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -601,9 +601,9 @@ static void setView(int view, mjrRect viewport, const mjvScene* scn, const mjrCo
|
||||
// set projection
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
// reverse Z rendering mapping (znear, zfar) -> (1, 0)
|
||||
glTranslatef(0,0,0.5);
|
||||
glScalef(1,1,-0.5);
|
||||
// reverse Z rendering mapping [znear, zfar] -> [1, 0]
|
||||
glTranslatef(0.0f, 0.0f, 0.5f);
|
||||
glScalef(1.0f, 1.0f, -0.5f);
|
||||
glFrustum(cam.frustum_center - halfwidth,
|
||||
cam.frustum_center + halfwidth,
|
||||
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.5f, 0.5f, 0.0f, 1.0f
|
||||
};
|
||||
|
||||
float tempMatrix[16], textureMatrix[16];
|
||||
mjvGeom *thisgeom, tempgeom;
|
||||
mjvLight *thislight;
|
||||
@@ -1030,9 +1029,9 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
|
||||
// set projection: from light viewpoint
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
// reverse Z rendering mapping (znear, zfar) -> (1, 0)
|
||||
glTranslatef(0,0,0.5);
|
||||
glScalef(1,1,-0.5);
|
||||
// reverse Z rendering mapping [znear, zfar] -> [1, 0]
|
||||
glTranslatef(0.0f, 0.0f, 0.5f);
|
||||
glScalef(1.0f , 1.0f, -0.5f);
|
||||
if (thislight->directional) {
|
||||
glOrtho(-con->shadowClip, con->shadowClip,
|
||||
-con->shadowClip, con->shadowClip,
|
||||
|
||||
@@ -389,9 +389,9 @@ public enum mjtFramebuffer : int{
|
||||
mjFB_WINDOW = 0,
|
||||
mjFB_OFFSCREEN = 1,
|
||||
}
|
||||
public enum mjtDepthMapping : int{
|
||||
mjDM_ZEROTOONE = 0,
|
||||
mjDM_ONETOZERO = 1,
|
||||
public enum mjtDepthMap : int{
|
||||
mjDEPTHMAP_01 = 0,
|
||||
mjDEPTHMAP_10 = 1,
|
||||
}
|
||||
public enum mjtFontScale : int{
|
||||
mjFONTSCALE_50 = 50,
|
||||
|
||||
Reference in New Issue
Block a user