LR17
December 17, 2025, 2:24pm
1
After upgrading to threejs r182 from r181 i see console fills with warnings:
Trying to use xx texture units while this GPU supports only 16
This happens if the scene contains at least five points lights.
With r181 I could add far more lights before reaching the limit.
Have there been any implementation change on this side?
Mugen87
December 17, 2025, 5:10pm
2
Yes, shadow mapping has been received fundamental updates in r182. There were multiple PRs but one of the leading ones is:
dev ← shadows
opened 01:20PM - 18 Nov 25 UTC
Related issue: #5554 #8577 #32180
This PR modernizes the `WebGLRenderer` shad… ow mapping with several significant improvements:
| Before | After |
| --- | --- |
| <img width="906" height="663" alt="Screenshot 2025-11-18 at 22 04 20" src="https://github.com/user-attachments/assets/33e448ac-e6da-4194-a896-c09f7eca79d1" /> | <img width="906" height="663" alt="Screenshot 2025-11-18 at 22 04 14" src="https://github.com/user-attachments/assets/3ef29242-f5d4-4f3f-b3d0-2f2e00905bb6" /> |
## Major Changes
### 1. Native Cube Depth Texture Support for PointLight Shadows
- Added new `CubeDepthTexture` class for native cube shadow maps
- Removed legacy 2D viewport-based cube rendering (old xzXZ/yY layout)
- Updated `PointLightShadow` to render directly to cube faces instead of 2D viewports
- Updated `WebGLTextures` to support cube depth texture binding
### 2. Removed RGBA Depth Packing
- Now using native depth textures (`samplerShadow`/`samplerCubeShadow` for PCF, `samples`/`samplerCube` for Basic)
- Renamed `distanceRGBA.glsl.js` → `distance.glsl.js`
- Removed all `cubeToUV()` and RGBA packing code from shaders
- Updated `ShadowMapViewer` and related examples to work with native depth
### 3. Vogel Disk + Interleaved Gradient Noise (IGN) Sampling
- Implemented modern soft shadow sampling technique in `shadowmap_pars_fragment.glsl.js`
- Uses Vogel disk for uniform circular distribution
- IGN provides per-pixel noise to rotate sampling patterns
- Hardware PCF with LinearFilter gives 4-tap filtering per sample
- 5 samples × 4 taps = effectively 20 filtered taps with better quality
- Removed `PCFSoftShadowMap` as the new `PCFShadowMap` is already soft
### 4. VSM Shadow Map Improvements
- Fixed VSM shadow map type switching errors (proper texture disposal)
- Added VSM/PointLight incompatibility handling at multiple levels:
- JavaScript: Skip shadow map creation with console warning
- Shader declarations: Exclude VSM-specific uniforms for PointLights
- Shader usage: Only call shadow functions when appropriate
- Proper depth texture cleanup when switching shadow map types
### 5. WebGL Optimizations
- `WebGLUniforms`: Prioritize shadow samplers (`SAMPLER_2D_SHADOW`, `SAMPLER_CUBE_SHADOW`) for Adreno GPUs
- `WebGLUniforms`: Support reversed depth buffer compare functions
- `WebGLLights`: Added `shadowCameraNear` and `shadowCameraFar` uniforms for PointLight shadows
## Files Changed
- **New**: `src/textures/CubeDepthTexture.js`
- **Renamed**: `distanceRGBA.glsl.js` → `distance.glsl.js`
- **Major rewrites**: `shadowmap_pars_fragment.glsl.js`, `WebGLShadowMap.js`
- **Significant updates**: `PointLightShadow.js`, `WebGLTextures.js`, `WebGLUniforms.js`
## Testing
Tested with DirectionalLight, SpotLight, and PointLight shadows across BasicShadowMap, PCFShadowMap, and VSMShadowMap types. Shadow map type switching works correctly, with appropriate warnings for VSM/PointLight combinations.
(Made using [Claude Code](https://code.claude.com/docs/en/vs-code) with Sonnet 4.5)
Do your point lights cast shadows? How many lights could you add with r181 before the engine warned you?
2 Likes
LR17
December 18, 2025, 9:49am
3
Yes, they cast shadow. Just did a test and with r181 I can add 10 point lights before reaching the limit.
Moreover r181 does not emit a warning but I get a program error:
Program Info Log: FRAGMENT shader texture image units count exceeds MAX_TEXTURE_IMAGE_UNITS(16)
Mugen87
December 18, 2025, 10:42am
4
Consider to open an issue at GitHub if the reduced number of shadow casting lights is an issue for you.
Mugen87
December 19, 2025, 5:15pm
5
GitHub issue for reference:
opened 05:07PM - 19 Dec 25 UTC
### Description
It seems r182 uses far more texture units to handle shadow cast… ing lights than r181.
### Reproduction steps
Add some shadow casting lights.
### Code
``
### Live example
r181 -> 15 lights on my gpu before reaching the limit
[https://jsfiddle.net/drc3hvs7/](https://jsfiddle.net/drc3hvs7/)
r182 -> 5 lights on my gpu before reaching the limit
[https://jsfiddle.net/2hj3dgau/](https://jsfiddle.net/2hj3dgau/)
You can change the `n` variable to change the number of lights added in the fiddle
### Screenshots
_No response_
### Version
182
### Device
_No response_
### Browser
_No response_
### OS
_No response_