|
|
@@ -54,7 +54,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, warnOnce } from '../utils.js';
|
|
|
+import { createCanvasElement, probeAsync, toNormalizedProjectionMatrix, toReversedProjectionMatrix, warnOnce } from '../utils.js';
|
|
|
import { ColorManagement } from '../math/ColorManagement.js';
|
|
|
|
|
|
class WebGLRenderer {
|
|
|
@@ -196,6 +196,7 @@ class WebGLRenderer {
|
|
|
|
|
|
// camera matrices cache
|
|
|
|
|
|
+ const _currentProjectionMatrix = new Matrix4();
|
|
|
const _projScreenMatrix = new Matrix4();
|
|
|
|
|
|
const _vector3 = new Vector3();
|
|
|
@@ -291,6 +292,8 @@ class WebGLRenderer {
|
|
|
|
|
|
state = new WebGLState( _gl );
|
|
|
|
|
|
+ if ( capabilities.reverseDepthBuffer ) state.buffers.depth.setReversed( true );
|
|
|
+
|
|
|
info = new WebGLInfo( _gl );
|
|
|
properties = new WebGLProperties();
|
|
|
textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
|
|
|
@@ -590,7 +593,13 @@ class WebGLRenderer {
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( depth ) bits |= _gl.DEPTH_BUFFER_BIT;
|
|
|
+ if ( depth ) {
|
|
|
+
|
|
|
+ bits |= _gl.DEPTH_BUFFER_BIT;
|
|
|
+ _gl.clearDepth( this.capabilities.reverseDepthBuffer ? 0 : 1 );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
if ( stencil ) {
|
|
|
|
|
|
bits |= _gl.STENCIL_BUFFER_BIT;
|
|
|
@@ -1971,7 +1980,21 @@ class WebGLRenderer {
|
|
|
|
|
|
// common camera uniforms
|
|
|
|
|
|
- p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
|
|
|
+ if ( capabilities.reverseDepthBuffer ) {
|
|
|
+
|
|
|
+ _currentProjectionMatrix.copy( camera.projectionMatrix );
|
|
|
+
|
|
|
+ toNormalizedProjectionMatrix( _currentProjectionMatrix );
|
|
|
+ toReversedProjectionMatrix( _currentProjectionMatrix );
|
|
|
+
|
|
|
+ p_uniforms.setValue( _gl, 'projectionMatrix', _currentProjectionMatrix );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
|
|
|
|
|
|
const uCamPos = p_uniforms.map.cameraPosition;
|