Skip to content

Add sizeAttenuation to SpriteNodeMaterial #29269

@ghost

Description

Description

SpriteMaterial (and others such as PointsMaterial) has a sizeAttenuation flag which can be set to false to make sure the sprite maintains the same size on screen no matter where the camera is placed. This is very convenient to display cursors etc. in Three.js.
When switching to node materials, this option is unfortunately missing from SpriteNodeMaterial.
I wonder whether this could be added?

Solution

Add a sizeAttenuation variable on SpriteNodeMaterial that works like sizeAttenuation on SpriteMaterial. Here's an example of how it could be used: jsfiddle-latest-release WebGPURenderer

Alternatives

const baseSize = uniform(0.02);
const distanceToCamera = length(sub(cameraPosition, positionWorld));
const scale = mul(baseSize, distanceToCamera);
material.scaleNode = vec2(scale);

The problem with this approach is that there's a difference between the displayed sprite size in a PerspectiveCamera vs an OrthographicCamera, which wasn't a problem with sizeAttenuation: false in SpriteMaterial.

Additional context

No response

Metadata

Metadata

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions