Skip to content

WebGLRenderer: Auto-correct reversed projection matrix #31410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import { WebGLUtils } from './webgl/WebGLUtils.js';
import { WebXRManager } from './webxr/WebXRManager.js';
import { WebGLMaterials } from './webgl/WebGLMaterials.js';
import { WebGLUniformsGroups } from './webgl/WebGLUniformsGroups.js';
import { createCanvasElement, probeAsync, toNormalizedProjectionMatrix, toReversedProjectionMatrix, warnOnce } from '../utils.js';
import { createCanvasElement, probeAsync, warnOnce } from '../utils.js';
import { ColorManagement } from '../math/ColorManagement.js';

/**
Expand Down Expand Up @@ -313,7 +313,6 @@ class WebGLRenderer {

// camera matrices cache

const _currentProjectionMatrix = new Matrix4();
const _projScreenMatrix = new Matrix4();

const _vector3 = new Vector3();
Expand Down Expand Up @@ -2384,22 +2383,13 @@ class WebGLRenderer {

if ( reversedDepthBuffer && camera.reversedDepth !== true ) {

// @deprecated, r179
warnOnce( 'THREE.WebGLRenderer: reversedDepthBuffer must be used with "camera.reversedDepth = true;" for correct results. Automatic conversion will be removed in r189.' );

_currentProjectionMatrix.copy( camera.projectionMatrix );

toNormalizedProjectionMatrix( _currentProjectionMatrix );
toReversedProjectionMatrix( _currentProjectionMatrix );

p_uniforms.setValue( _gl, 'projectionMatrix', _currentProjectionMatrix );

} else {

p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
camera.reversedDepth = true;
camera.updateProjectionMatrix();

}

p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );

p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );

const uCamPos = p_uniforms.map.cameraPosition;
Expand Down