Skip to content

NgtsContactShadows

NgtsContactShadows is a port of Drei’s ContactShadows which creates a contact shadow implementation facing upwards (positive Y) by default.

Contact shadows are ideal for grounding objects in a scene without the complexity of traditional shadow mapping.

Usage

Basic Contact Shadows

<app-model />
<ngts-contact-shadows
[options]="{
opacity: 1,
scale: 10,
blur: 1,
far: 10,
resolution: 512,
color: '#000000'
}"
/>

High-Quality Static Shadows

Since contact shadows can be expensive, you can limit the number of frames for static objects:

<!-- Render only once for static scenes -->
<ngts-contact-shadows [options]="{ frames: 1 }" />

Soft Shadows with Smoothing

<ngts-contact-shadows
[options]="{
opacity: 0.8,
scale: 15,
blur: 2.5,
far: 8,
resolution: 1024,
smooth: true,
color: '#1a1a2e'
}"
/>

Non-Square Shadow Plane

<ngts-contact-shadows
[options]="{
scale: [20, 10],
blur: 1,
opacity: 0.6
}"
/>

Notes

  • Contact shadows are Y-up oriented and render from above
  • Higher resolution and blur values increase quality but also GPU cost
  • For animated scenes, keep frames at Infinity (default)
  • For static scenes, set frames: 1 for better performance

Options

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

Properties

name type description
opacity number Opacity of the shadows. Default: 1
width number Width of the shadow plane. Default: 1
height number Height of the shadow plane. Default: 1
blur number Blur radius of the shadows. Default: 1
near number Near clipping plane for the shadow camera. Default: 0
far number Far distance of the shadow camera. Default: 10
resolution number Resolution of the shadow map. Default: 512
smooth boolean Whether to apply smoothing to the shadows. Default: true
color THREE.ColorRepresentation Color of the shadows. Default: '#000000'
depthWrite boolean Whether the shadows should write to the depth buffer. Default: false
frames number How many frames it can render, more yields cleaner results. Default: Infinity
scale number | [number, number] Scale of the shadow plane. Can be a number or [x, y] tuple. Default: 10