Skip to content

NgtsCustomShaderMaterial

NgtsCustomShaderMaterial is a port of three-custom-shader-material that allows you to create custom shader materials by extending existing THREE.js materials. It provides a flexible way to define your own shaders while retaining all the features of the base material.

Usage

import { NgtsCustomShaderMaterial } from 'angular-three-soba/materials';
<ngt-points>
<ngt-icosahedron-geometry *args="[1, 32]" />
<ngts-custom-shader-material
[baseMaterial]="PointsMaterial"
[options]="{
vertexShader: myVertexShader,
fragmentShader: myFragmentShader,
uniforms: { time: { value: 0 } }
}"
/>
</ngt-points>

Peer Dependencies

Requires three-custom-shader-material:

Terminal window
npm install three-custom-shader-material

Example with MeshPhysicalMaterial

import * as THREE from 'three';
@Component({
template: `
<ngt-mesh>
<ngt-sphere-geometry />
<ngts-custom-shader-material
[baseMaterial]="MeshPhysicalMaterial"
[options]="{
vertexShader: vertexShader,
fragmentShader: fragmentShader,
uniforms: uniforms,
roughness: 0.5,
metalness: 0.8
}"
/>
</ngt-mesh>
`
})
export class CustomMaterial {
MeshPhysicalMaterial = THREE.MeshPhysicalMaterial;
vertexShader = `
varying vec3 vPosition;
void main() {
vPosition = position;
}
`;
fragmentShader = `
varying vec3 vPosition;
void main() {
csm_DiffuseColor = vec4(vPosition * 0.5 + 0.5, 1.0);
}
`;
uniforms = {
time: { value: 0 }
};
}

Options

Properties

name type description
baseMaterial Material | Class<Material> | ElementRef<Material> The base material to extend. Can be a material instance, a material class, or an ElementRef to a material.
attach string How to attach the material to its parent object.
vertexShader string The vertex shader code.
fragmentShader string The fragment shader code.
uniforms Record<string, { value: any }> An object containing the uniforms for the shader.
cacheKey string Cache key for shader compilation.