Skip to content

Examples: Add DepthSavePass and depth texture tools #31360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

gchoqueux
Copy link

@gchoqueux gchoqueux commented Jul 3, 2025

Description

Add DepthSavePass, depth texture utilities, and interactive displacement example

This DepthSavePass introduces support for working with depth textures in post-processing workflows and DepthTextureUtils adds a world position picking;

This position picking method based on the depth texture takes into account map displacement. It can also be more performant than raycasting, especially when the mesh has a high number of faces, as it avoids the computational cost of geometric intersection tests.

🧱 New Post-Processing Pass

  • DepthSavePass
    A render pass that saves the scene’s depth buffer into a Texture.
    Useful for accessing per-pixel depth values using renderer.readRenderTargetPixels() or for use in subsequent post-processing effects.

🛠️ Depth Utilities

  • DepthTextureUtils
    A small utility module for working with depth data:
    • pickWorldPosition() — converts screen-space mouse coordinates into a 3D world position using the depth texture.

🧪 Example

  • webgl_postprocessing_interactive_displacement.html
    A live demo showcasing:
    • Animated displacement mapping.
    • Real-time mouse interaction using depth-based position picking.

These additions extend Three.js’s post-processing capabilities and simplify depth buffer access for custom spatial effects.

⚠️ Note: On some Windows configurations, depth values read from the buffer may appear incorrect.

@gchoqueux gchoqueux force-pushed the depthTextureUtils branch from 584b132 to 2880978 Compare July 3, 2025 13:25
@gchoqueux gchoqueux marked this pull request as ready for review July 3, 2025 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant