Skip to content

Commit 89b6cd1

Browse files
authored
TSL: Refactor positionViewDirection to handle orthographic camera cases (#32088)
* WebGPU: Refactor positionViewDirection to handle orthographic camera cases * Update WebGPU screenshots after positionViewDirection fix * Review comment: #32088 (comment)
1 parent 4bd6e36 commit 89b6cd1

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/nodes/accessors/Position.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { attribute } from '../core/AttributeNode.js';
22
import { Fn } from '../tsl/TSLCore.js';
3+
import { vec3 } from '../tsl/TSLBase.js';
34
import { modelWorldMatrix } from './ModelNode.js';
45

56
/**
@@ -71,4 +72,20 @@ export const positionView = /*@__PURE__*/ ( Fn( ( builder ) => {
7172
* @tsl
7273
* @type {VaryingNode<vec3>}
7374
*/
74-
export const positionViewDirection = /*@__PURE__*/ positionView.negate().toVarying( 'v_positionViewDirection' ).normalize().toVar( 'positionViewDirection' );
75+
export const positionViewDirection = /*@__PURE__*/ ( Fn( ( builder ) => {
76+
77+
let output;
78+
79+
if ( builder.camera.isOrthographicCamera ) {
80+
81+
output = vec3( 0, 0, 1 );
82+
83+
} else {
84+
85+
output = positionView.negate().toVarying( 'v_positionViewDirection' ).normalize();
86+
87+
}
88+
89+
return output.toVar( 'positionViewDirection' );
90+
91+
}, 'vec3' ).once( [ 'POSITION' ] ) )();

0 commit comments

Comments
 (0)