Skip to content

Commit

Permalink
sprite revision
Browse files Browse the repository at this point in the history
  • Loading branch information
sunag committed Dec 17, 2024
1 parent 42795bf commit 4a09dd8
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, positionLocal } from '../../nodes/accessors/Position.js';

Check warning on line 5 in src/materials/nodes/SpriteNodeMaterial.js

View workflow job for this annotation

GitHub Actions / Lint testing

'positionLocal' is defined but never used
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 4a09dd8

Please sign in to comment.