Skip to content

Commit def7feb

Browse files
authored
Merge pull request #20283 from Mugen87/dev35
WebGPU: Fix computation of projection matrices.
2 parents 1a1fd16 + 089739f commit def7feb

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

examples/jsm/renderers/webgpu/WebGPURenderer.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,49 @@ import WebGPUBackground from './WebGPUBackground.js';
1212

1313
import { Frustum, Matrix4, Vector3, Color } from '../../../../build/three.module.js';
1414

15+
console.warn( 'THREE.WebGPURenderer: Modified Matrix4.makePerspective and Matrix4.makeOrtographic to work with WebGPU.' ); // #20276
16+
17+
Matrix4.prototype.makePerspective = function ( left, right, top, bottom, near, far ) {
18+
19+
const te = this.elements;
20+
const x = 2 * near / ( right - left );
21+
const y = 2 * near / ( top - bottom );
22+
23+
const a = ( right + left ) / ( right - left );
24+
const b = ( top + bottom ) / ( top - bottom );
25+
const c = - far / ( far - near );
26+
const d = - far * near / ( far - near );
27+
28+
te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
29+
te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
30+
te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
31+
te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
32+
33+
return this;
34+
35+
};
36+
37+
Matrix4.prototype.makeOrthographic = function ( left, right, top, bottom, near, far ) {
38+
39+
const te = this.elements;
40+
const w = 1.0 / ( right - left );
41+
const h = 1.0 / ( top - bottom );
42+
const p = 1.0 / ( far - near );
43+
44+
const x = ( right + left ) * w;
45+
const y = ( top + bottom ) * h;
46+
const z = near * p;
47+
48+
te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
49+
te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
50+
te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 1 * p; te[ 14 ] = - z;
51+
te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
52+
53+
return this;
54+
55+
};
56+
57+
1558
const _frustum = new Frustum();
1659
const _projScreenMatrix = new Matrix4();
1760
const _vector3 = new Vector3();

0 commit comments

Comments
 (0)