|
|
@@ -1,5 +1,4 @@
|
|
|
import NodeMaterial from './NodeMaterial.js';
|
|
|
-import { uniform } from '../../nodes/core/UniformNode.js';
|
|
|
import { cameraProjectionMatrix } from '../../nodes/accessors/Camera.js';
|
|
|
import { materialRotation } from '../../nodes/accessors/MaterialNode.js';
|
|
|
import { modelViewMatrix, modelWorldMatrix } from '../../nodes/accessors/ModelNode.js';
|
|
|
@@ -8,6 +7,7 @@ import { rotate } from '../../nodes/utils/RotateNode.js';
|
|
|
import { float, vec2, vec3, vec4 } from '../../nodes/tsl/TSLBase.js';
|
|
|
|
|
|
import { SpriteMaterial } from '../SpriteMaterial.js';
|
|
|
+import { reference } from '../../nodes/accessors/ReferenceBaseNode.js';
|
|
|
|
|
|
const _defaultValues = /*@__PURE__*/ new SpriteMaterial();
|
|
|
|
|
|
@@ -26,6 +26,7 @@ class SpriteNodeMaterial extends NodeMaterial {
|
|
|
this.isSpriteNodeMaterial = true;
|
|
|
|
|
|
this.lights = false;
|
|
|
+ this._useSizeAttenuation = true;
|
|
|
|
|
|
this.positionNode = null;
|
|
|
this.rotationNode = null;
|
|
|
@@ -37,7 +38,9 @@ class SpriteNodeMaterial extends NodeMaterial {
|
|
|
|
|
|
}
|
|
|
|
|
|
- setupPosition( { object, context } ) {
|
|
|
+ setupPosition( { object, camera, context } ) {
|
|
|
+
|
|
|
+ const sizeAttenuation = this.sizeAttenuation;
|
|
|
|
|
|
// < VERTEX STAGE >
|
|
|
|
|
|
@@ -55,11 +58,20 @@ class SpriteNodeMaterial extends NodeMaterial {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ if ( ! sizeAttenuation && camera.isPerspectiveCamera ) {
|
|
|
+
|
|
|
+ scale = scale.mul( mvPosition.z.negate() );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
let alignedPosition = vertex.xy;
|
|
|
|
|
|
if ( object.center && object.center.isVector2 === true ) {
|
|
|
|
|
|
- alignedPosition = alignedPosition.sub( uniform( object.center ).sub( 0.5 ) );
|
|
|
+ const center = reference( 'center', 'vec2' );
|
|
|
+
|
|
|
+ alignedPosition = alignedPosition.sub( center.sub( 0.5 ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -89,6 +101,23 @@ class SpriteNodeMaterial extends NodeMaterial {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ get sizeAttenuation() {
|
|
|
+
|
|
|
+ return this._useSizeAttenuation;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ set sizeAttenuation( value ) {
|
|
|
+
|
|
|
+ if ( this._useSizeAttenuation !== value ) {
|
|
|
+
|
|
|
+ this._useSizeAttenuation = value;
|
|
|
+ this.needsUpdate = true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
export default SpriteNodeMaterial;
|