Fixups to comments and flags for reversed Z rendering
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user