@@ -18,6 +18,7 @@ import { Directive, effect, input } from '@angular/core';
1818import { injectStore } from 'angular-three' ;
1919import { mergeInputs } from 'ngxtension/inject-inputs' ;
2020import * as THREE from 'three' ;
21+ import { getVersion } from './constants' ;
2122
2223/**
2324 * Options for configuring soft shadows using PCSS (Percentage-Closer Soft Shadows).
@@ -39,6 +40,11 @@ const defaultOptions: NgtsSoftShadowsOptions = {
3940
4041function pcss ( options : NgtsSoftShadowsOptions ) : string {
4142 const { focus, size, samples } = options ;
43+ // Three.js r182 removed unpackRGBAToDepth and switched to native depth textures
44+ const useNativeDepth = getVersion ( ) >= 182 ;
45+ const sampleDepth = useNativeDepth
46+ ? 'texture2D( shadowMap, uv + offset ).r'
47+ : 'unpackRGBAToDepth( texture2D( shadowMap, uv + offset ) )' ;
4248 return `
4349#define PENUMBRA_FILTER_SIZE float(${ size } )
4450#define RGB_NOISE_FUNCTION(uv) (randRGB(uv))
@@ -96,7 +102,7 @@ float findBlocker(sampler2D shadowMap, vec2 uv, float compare, float angle) {
96102 #pragma unroll_loop_start
97103 for(int i = 0; i < ${ samples } ; i ++) {
98104 offset = (vogelDiskSample(j, ${ samples } , angle) * texelSize) * 2.0 * PENUMBRA_FILTER_SIZE;
99- depth = unpackRGBAToDepth( texture2D( shadowMap, uv + offset)) ;
105+ depth = ${ sampleDepth } ;
100106 if (depth < compare) {
101107 blockerDepthSum += depth;
102108 blockers++;
@@ -122,7 +128,7 @@ float vogelFilter(sampler2D shadowMap, vec2 uv, float zReceiver, float filterRad
122128 for (int i = 0; i < ${ samples } ; i++) {
123129 vogelSample = vogelDiskSample(j, ${ samples } , angle) * texelSize;
124130 offset = vogelSample * (1.0 + filterRadius * float(${ size } ));
125- shadow += step( zReceiver, unpackRGBAToDepth( texture2D( shadowMap, uv + offset ) ) );
131+ shadow += step( zReceiver, ${ sampleDepth } );
126132 j++;
127133 }
128134 #pragma unroll_loop_end
0 commit comments