Skip to content

Commit

Permalink
Merge pull request #1455 from zenustech/no-reverse-z
Browse files Browse the repository at this point in the history
no-reverse-z
  • Loading branch information
legobadman authored Oct 10, 2023
2 parents e228987 + a8ace97 commit a6089e5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 26 deletions.
14 changes: 7 additions & 7 deletions ui/zenoedit/viewport/displaywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1247,13 +1247,13 @@ void DisplayWidget::onNodeSelected(const QModelIndex &subgIdx, const QModelIndex
auto _far = scene->camera->m_far;
auto fov = scene->camera->m_fov;
auto cz = glm::length(scene->camera->m_lodcenter);
if (depth != 0) {
// depth = depth * 2 - 1;
// cz = 2 * _near * _far / ((_far + _near) - depth * (_far - _near));
glm::vec4 ndc = {0, 0, depth, 1};
glm::vec4 clip_c = glm::inverse(scene->camera->m_proj) * ndc;
clip_c /= clip_c.w;
cz = -clip_c.z;
if (depth != 1) {
depth = depth * 2 - 1;
cz = 2 * _near * _far / ((_far + _near) - depth * (_far - _near));
// glm::vec4 ndc = {0, 0, depth, 1};
// glm::vec4 clip_c = glm::inverse(scene->camera->m_proj) * ndc;
// clip_c /= clip_c.w;
// cz = -clip_c.z;
}
auto w = scene->camera->m_nx;
auto h = scene->camera->m_ny;
Expand Down
8 changes: 4 additions & 4 deletions zenovis/src/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ void Camera::placeCamera(glm::vec3 pos, glm::vec3 front, glm::vec3 up) {
m_view = glm::lookAt(m_lodcenter, m_lodcenter + m_lodfront, m_lodup);
if (m_ortho_mode) {
auto radius = glm::length(m_lodcenter);
m_proj = glm::orthoZO(-radius * getAspect(), radius * getAspect(), -radius,
radius, m_far, m_near);
m_proj = glm::ortho(-radius * getAspect(), radius * getAspect(), -radius,
radius, m_near, m_far);
} else {
m_proj = glm::perspectiveZO(glm::radians(m_fov), getAspect(), m_far, m_near);
m_proj = glm::perspective(glm::radians(m_fov), getAspect(), m_near, m_far);
}
}

Expand All @@ -80,7 +80,7 @@ void Camera::updateMatrix() {
void Camera::setResolution(int nx, int ny) {
m_nx = nx;
m_ny = ny;
m_proj = glm::perspectiveZO(glm::radians(m_fov), getAspect(), m_far, m_near);
m_proj = glm::perspective(glm::radians(m_fov), getAspect(), m_near, m_far);
}
void Camera::setResolutionInfo(bool block, int nx, int ny)
{
Expand Down
12 changes: 0 additions & 12 deletions zenovis/src/bate/FrameBufferPicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,6 @@ struct FrameBufferPicker : IPicker {
if (scene->select_mode == PICK_MODE::PICK_OBJECT) {
pick_particle = prim->tris->empty() && prim->quads->empty() && prim->polys->empty() && prim->loops->empty();
CHECK_GL(glEnable(GL_DEPTH_TEST));
CHECK_GL(glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE));
glDepthFunc(GL_GREATER);
CHECK_GL(glClearDepth(0.0));

// shader uniform
obj_shader->use();
Expand Down Expand Up @@ -346,9 +343,6 @@ struct FrameBufferPicker : IPicker {
if (scene->select_mode == PICK_MODE::PICK_VERTEX || pick_particle) {
// ----- enable depth test -----
CHECK_GL(glEnable(GL_DEPTH_TEST));
CHECK_GL(glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE));
glDepthFunc(GL_GREATER);
CHECK_GL(glClearDepth(0.0));
// CHECK_GL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));

// ----- draw points -----
Expand All @@ -374,9 +368,6 @@ struct FrameBufferPicker : IPicker {
if (scene->select_mode == PICK_MODE::PICK_LINE) {
// ----- enable depth test -----
CHECK_GL(glEnable(GL_DEPTH_TEST));
CHECK_GL(glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE));
glDepthFunc(GL_GREATER);
CHECK_GL(glClearDepth(0.0));
// CHECK_GL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
// ----- draw lines -----
prim_shader->use();
Expand Down Expand Up @@ -425,9 +416,6 @@ struct FrameBufferPicker : IPicker {
if (scene->select_mode == PICK_MODE::PICK_MESH) {
// ----- enable depth test -----
CHECK_GL(glEnable(GL_DEPTH_TEST));
CHECK_GL(glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE));
glDepthFunc(GL_GREATER);
CHECK_GL(glClearDepth(0.0));
// CHECK_GL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
// ----- draw triangles -----
prim_shader->use();
Expand Down
3 changes: 0 additions & 3 deletions zenovis/src/bate/RenderEngineBate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ struct RenderEngineBate : RenderEngine {

void draw() override {
auto guard = setupState();
CHECK_GL(glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE));
glDepthFunc(GL_GREATER);
CHECK_GL(glClearDepth(0.0));
CHECK_GL(glClearColor(scene->drawOptions->bgcolor.r, scene->drawOptions->bgcolor.g,
scene->drawOptions->bgcolor.b, 0.0f));
CHECK_GL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
Expand Down

0 comments on commit a6089e5

Please sign in to comment.