Skip to content

Commit

Permalink
TSL: Vertex shader revision 2 (#30147)
Browse files Browse the repository at this point in the history
* sprite revision

* cleanup
  • Loading branch information
sunag authored Dec 17, 2024
1 parent e060f3a commit 94ad822
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
9 changes: 8 additions & 1 deletion src/materials/nodes/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import AONode from '../../nodes/lighting/AONode.js';
import { lightingContext } from '../../nodes/lighting/LightingContextNode.js';
import IrradianceNode from '../../nodes/lighting/IrradianceNode.js';
import { depth, viewZToLogarithmicDepth, viewZToOrthographicDepth } from '../../nodes/display/ViewportDepthNode.js';
import { cameraFar, cameraNear } from '../../nodes/accessors/Camera.js';
import { cameraFar, cameraNear, cameraProjectionMatrix } from '../../nodes/accessors/Camera.js';
import { clipping, clippingAlpha, hardwareClipping } from '../../nodes/accessors/ClippingNode.js';
import NodeMaterialObserver from './manager/NodeMaterialObserver.js';
import getAlphaHashThreshold from '../../nodes/functions/material/getAlphaHashThreshold.js';
Expand Down Expand Up @@ -102,6 +102,7 @@ class NodeMaterial extends Material {

builder.context.setupNormal = () => this.setupNormal( builder );
builder.context.setupPositionView = () => this.setupPositionView( builder );
builder.context.setupModelViewProjection = () => this.setupModelViewProjection( builder );

const renderer = builder.renderer;
const renderTarget = renderer.getRenderTarget();
Expand Down Expand Up @@ -317,6 +318,12 @@ class NodeMaterial extends Material {

}

setupModelViewProjection() {

return cameraProjectionMatrix.mul( positionView );

}

setupVertex( builder ) {

builder.addStack();
Expand Down
7 changes: 3 additions & 4 deletions src/materials/nodes/SpriteNodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { materialRotation } from '../../nodes/accessors/MaterialNode.js';
import { modelViewMatrix, modelWorldMatrix } from '../../nodes/accessors/ModelNode.js';
import { positionGeometry } from '../../nodes/accessors/Position.js';
import { rotate } from '../../nodes/utils/RotateNode.js';
import { float, vec2, vec4 } from '../../nodes/tsl/TSLBase.js';
import { float, vec2, vec3, vec4 } from '../../nodes/tsl/TSLBase.js';

import { SpriteMaterial } from '../SpriteMaterial.js';
import { reference } from '../../nodes/accessors/ReferenceBaseNode.js';
Expand Down Expand Up @@ -46,9 +46,9 @@ class SpriteNodeMaterial extends NodeMaterial {

// < VERTEX STAGE >

const { rotationNode, scaleNode } = this;
const { positionNode, rotationNode, scaleNode } = this;

const mvPosition = modelViewMatrix.mul( positionLocal );
const mvPosition = modelViewMatrix.mul( vec3( positionNode || 0 ) );

let scale = vec2( modelWorldMatrix[ 0 ].xyz.length(), modelWorldMatrix[ 1 ].xyz.length() );

Expand All @@ -58,7 +58,6 @@ class SpriteNodeMaterial extends NodeMaterial {

}


if ( ! sizeAttenuation ) {

if ( camera.isPerspectiveCamera ) {
Expand Down
11 changes: 7 additions & 4 deletions src/nodes/accessors/ModelViewProjectionNode.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { cameraProjectionMatrix } from './Camera.js';
import { positionView } from './Position.js';
import { Fn } from '../tsl/TSLCore.js';

/** @module ModelViewProjectionNode **/

/**
* TSL object that represents the position in clip space after the model-view-projection transform of the current rendered object.
*
* @type {VaryingNode<vec3>}
* @type {VaryingNode<vec4>}
*/
export const modelViewProjection = /*@__PURE__*/ cameraProjectionMatrix.mul( positionView ).varying( 'v_modelViewProjection' );
export const modelViewProjection = /*@__PURE__*/ ( Fn( ( builder ) => {

return builder.context.setupModelViewProjection();

}, 'vec4' ).once() )().varying( 'v_modelViewProjection' );

0 comments on commit 94ad822

Please sign in to comment.