samplerComparison
samplerComparison
Creates a node for hardware-accelerated sampling and depth comparison of a depth texture (shadow map), which is fundamental for implementing real-time shadows.
Core Advantages
Leverages GPU hardware features (like PCF) to perform depth comparisons efficiently, greatly simplifying the implementation of soft shadows while offering far superior performance than manual sampling and comparison.
Common Uses
Directional Light Shadows
Spot Light Shadows
Point Light Shadows
How to adjust
This node cannot be adjusted directly. Shadow appearance is controlled by adjusting the light's `shadow` properties (e.g., `light.shadow.radius` for softness) or by post-processing its output factor in the node graph (e.g., using `smoothstep` to refine the shadow edge transition).
Code Examples
1// Get the shadow factor using the high-level shadowmap node (uses samplerComparison internally)
2const shadowFactor = shadowmap( myLight );
3
4// Mix the base color with a shadow color based on the factor
5material.colorNode = mix( baseColor, shadowColor, shadowFactor.oneMinus() );