1- import { WebGLCoordinateSystem , WebGPUCoordinateSystem , ReversedCoordinateSystem } from '../constants.js' ;
1+ import { WebGLCoordinateSystem , WebGPUCoordinateSystem } from '../constants.js' ;
22import { Vector3 } from './Vector3.js' ;
33
44/**
@@ -1103,9 +1103,10 @@ class Matrix4 {
11031103 * @param {number } near - The distance from the camera to the near plane.
11041104 * @param {number } far - The distance from the camera to the far plane.
11051105 * @param {(WebGLCoordinateSystem|WebGPUCoordinateSystem) } [coordinateSystem=WebGLCoordinateSystem] - The coordinate system.
1106+ * @param {boolean } [reversedDepth=false] - Whether to use a reversed depth.
11061107 * @return {Matrix4 } A reference to this matrix.
11071108 */
1108- makePerspective ( left , right , top , bottom , near , far , coordinateSystem = WebGLCoordinateSystem ) {
1109+ makePerspective ( left , right , top , bottom , near , far , coordinateSystem = WebGLCoordinateSystem , reversedDepth = false ) {
11091110
11101111 const te = this . elements ;
11111112 const x = 2 * near / ( right - left ) ;
@@ -1116,24 +1117,28 @@ class Matrix4 {
11161117
11171118 let c , d ;
11181119
1119- if ( coordinateSystem === WebGLCoordinateSystem ) {
1120+ if ( reversedDepth ) {
11201121
1121- c = - ( far + near ) / ( far - near ) ;
1122- d = ( - 2 * far * near ) / ( far - near ) ;
1122+ c = far / ( far - near ) - 1 ;
1123+ d = ( far * near ) / ( far - near ) ;
11231124
1124- } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
1125+ } else {
11251126
1126- c = - far / ( far - near ) ;
1127- d = ( - far * near ) / ( far - near ) ;
1127+ if ( coordinateSystem === WebGLCoordinateSystem ) {
11281128
1129- } else if ( coordinateSystem === ReversedCoordinateSystem ) {
1129+ c = - ( far + near ) / ( far - near ) ;
1130+ d = ( - 2 * far * near ) / ( far - near ) ;
11301131
1131- c = far / ( far - near ) - 1 ;
1132- d = ( far * near ) / ( far - near ) ;
1132+ } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
11331133
1134- } else {
1134+ c = - far / ( far - near ) ;
1135+ d = ( - far * near ) / ( far - near ) ;
1136+
1137+ } else {
11351138
1136- throw new Error ( 'THREE.Matrix4.makePerspective(): Invalid coordinate system: ' + coordinateSystem ) ;
1139+ throw new Error ( 'THREE.Matrix4.makePerspective(): Invalid coordinate system: ' + coordinateSystem ) ;
1140+
1141+ }
11371142
11381143 }
11391144
@@ -1157,9 +1162,10 @@ class Matrix4 {
11571162 * @param {number } near - The distance from the camera to the near plane.
11581163 * @param {number } far - The distance from the camera to the far plane.
11591164 * @param {(WebGLCoordinateSystem|WebGPUCoordinateSystem) } [coordinateSystem=WebGLCoordinateSystem] - The coordinate system.
1165+ * @param {boolean } [reversedDepth=false] - Whether to use a reversed depth.
11601166 * @return {Matrix4 } A reference to this matrix.
11611167 */
1162- makeOrthographic ( left , right , top , bottom , near , far , coordinateSystem = WebGLCoordinateSystem ) {
1168+ makeOrthographic ( left , right , top , bottom , near , far , coordinateSystem = WebGLCoordinateSystem , reversedDepth = false ) {
11631169
11641170 const te = this . elements ;
11651171 const w = 1.0 / ( right - left ) ;
@@ -1171,24 +1177,28 @@ class Matrix4 {
11711177
11721178 let z , zInv ;
11731179
1174- if ( coordinateSystem === WebGLCoordinateSystem ) {
1180+ if ( reversedDepth ) {
11751181
1176- z = ( far + near ) * p ;
1177- zInv = - 2 * p ;
1182+ z = - near * p - 1 ;
1183+ zInv = 1 * p ;
11781184
1179- } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
1185+ } else {
11801186
1181- z = near * p ;
1182- zInv = - 1 * p ;
1187+ if ( coordinateSystem === WebGLCoordinateSystem ) {
11831188
1184- } else if ( coordinateSystem === ReversedCoordinateSystem ) {
1189+ z = ( far + near ) * p ;
1190+ zInv = - 2 * p ;
11851191
1186- z = - near * p - 1 ;
1187- zInv = 1 * p ;
1192+ } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
11881193
1189- } else {
1194+ z = near * p ;
1195+ zInv = - 1 * p ;
1196+
1197+ } else {
11901198
1191- throw new Error ( 'THREE.Matrix4.makeOrthographic(): Invalid coordinate system: ' + coordinateSystem ) ;
1199+ throw new Error ( 'THREE.Matrix4.makeOrthographic(): Invalid coordinate system: ' + coordinateSystem ) ;
1200+
1201+ }
11921202
11931203 }
11941204
0 commit comments