Skip to content

NgtsMeshRefractionMaterial

NgtsMeshRefractionMaterial is a port of Drei’s MeshRefractionMaterial that simulates realistic light refraction through transparent objects. It uses ray tracing with BVH acceleration for accurate light bending effects, making it ideal for diamonds, crystals, glass, and other transparent materials.

Peer Dependencies

Requires three-mesh-bvh:

Terminal window
npm install three-mesh-bvh

Usage

import { NgtsMeshRefractionMaterial } from 'angular-three-soba/materials';

If you want the material to reflect other objects in the scene, pair it with NgtsCubeCamera:

<ngts-cube-camera>
<ngt-mesh *cameraContent="let texture">
<ngt-dodecahedron-geometry />
<ngts-mesh-refraction-material [envMap]="texture()" />
</ngt-mesh>
</ngts-cube-camera>

Otherwise, just pass an environment map directly:

<!-- texture = loaderResource(() => RGBELoader, () => 'path/to/texture.hdr') -->
<ngt-mesh>
<ngt-dodecahedron-geometry />
<ngts-mesh-refraction-material [envMap]="texture()" />
</ngt-mesh>

Diamond Example

@Component({
template: `
<ngts-cube-camera [options]="{ resolution: 256, frames: 1 }">
<ngt-mesh *cameraContent="let texture">
<ngt-dodecahedron-geometry />
<ngts-mesh-refraction-material
[envMap]="texture()"
[options]="{
bounces: 3,
ior: 2.4,
fresnel: 1,
aberrationStrength: 0.02,
color: 'white'
}"
/>
</ngt-mesh>
</ngts-cube-camera>
`
})
export class Diamond {}

Common IOR Values

MaterialIOR
Air1.0
Water1.33
Glass1.5
Crystal2.0
Diamond2.4

Higher bounces values produce more accurate refractions but require more computation. For most cases, 2-3 bounces provide a good balance between quality and performance.

Inputs

name type description required
envMap THREE.CubeTexture | THREE.Texture The environment map used for refraction. Required for the material to work. yes
attach string How to attach the material to its parent object. no

Options

Properties

name type description
bounces number The number of ray-cast bounces for light simulation.
ior number The refraction index. Diamond is 2.4, glass is 1.5, water is 1.33.
fresnel number The Fresnel effect intensity (strip light reflections).
aberrationStrength number The RGB chromatic aberration shift intensity.
color THREE.ColorRepresentation The color of the material.
fastChroma boolean Whether to use fewer ray casts for the RGB shift, sacrificing physical accuracy for performance.