Skip to content

NgtsPointMaterial

NgtsPointMaterial is a port of Drei’s PointMaterial that renders point clouds with consistent size regardless of distance. It extends THREE.PointsMaterial with additional shader modifications for improved point rendering with size attenuation control.

Usage

import { NgtsPointMaterial } from 'angular-three-soba/materials';
<ngt-points>
<ngt-buffer-geometry>
<ngt-buffer-attribute attach="attributes.position" [args]="[positions, 3]" />
</ngt-buffer-geometry>
<ngts-point-material [options]="{ size: 0.1, color: 'orange', sizeAttenuation: true }" />
</ngt-points>

Starfield Example

@Component({
template: `
<ngt-points>
<ngt-buffer-geometry>
<ngt-buffer-attribute attach="attributes.position" [args]="[positions, 3]" />
</ngt-buffer-geometry>
<ngts-point-material
[options]="{
size: 0.02,
color: 'white',
sizeAttenuation: true,
transparent: true,
opacity: 0.8
}"
/>
</ngt-points>
`
})
export class Starfield {
positions = new Float32Array(
Array.from({ length: 5000 }, () => (Math.random() - 0.5) * 50).flat()
);
}

With Texture

@Component({
template: `
@if (texture(); as map) {
<ngt-points>
<ngt-buffer-geometry>
<ngt-buffer-attribute attach="attributes.position" [args]="[positions, 3]" />
</ngt-buffer-geometry>
<ngts-point-material
[options]="{
size: 0.5,
map: map,
transparent: true,
alphaTest: 0.5
}"
/>
</ngt-points>
}
`
})
export class TexturedPoints {
texture = textureResource(() => 'particle.png');
positions = new Float32Array([/* ... */]);
}

The NgtsPointMaterial is particularly useful for particle systems, star fields, and other point-based visualizations where you need fine control over point appearance.

Options

options input accepts any properties from THREE.PointsMaterial in addition to the following:

Properties

name type description
size number The size of the points.
color THREE.ColorRepresentation The color of the points.
sizeAttenuation boolean Whether points should get smaller as they get further from the camera.
map THREE.Texture A texture to apply to the points.
transparent boolean Whether the material is transparent.
opacity number The opacity of the material (0-1).