-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Background image depth compositing (#83)
* very early WIP of depth compositing shader, sort of works for a hardcoded turtle example * fix texture sampling logic with vertex shader * improvements * GUI container refactor * Clean up panel display, still some kinks to work out * working depth compositing, need to clean up/document things * Improve expanded panel behavior; drag regression for mobile view * Fix toggle for sidebar display * Fix type * refactor for popup img instead of background_image * add enabled flag to texture * bad merge * 4 byte packing * more work * working float passing? * works! * Remove icons : ) * Revert SMPL-X example * remove depth scale * cleanup * make popup example * comment * garbage collect old textures, repackage PopupImage into BackgroundImage * Update compositing example * More precision * Nits, type errors * Nits * Use 3 bytes, fix mypy/ruff * Naming --------- Co-authored-by: Brent Yi <[email protected]>
- Loading branch information
Showing
6 changed files
with
209 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# mypy: disable-error-code="var-annotated" | ||
"""Background image example with depth compositing. | ||
In this example, we show how to use a background image with depth compositing. This can | ||
be useful when we want a 2D image to occlude 3D geometry, such as for NeRF rendering. | ||
""" | ||
|
||
import time | ||
|
||
import numpy as onp | ||
import trimesh | ||
import trimesh.creation | ||
|
||
import viser | ||
|
||
server = viser.ViserServer() | ||
|
||
|
||
img = onp.random.randint(0, 255, size=(1000, 1000, 3), dtype=onp.uint8) | ||
depth = onp.ones((1000, 1000, 1), dtype=onp.float32) | ||
|
||
# Make a square middle portal. | ||
depth[250:750, 250:750, :] = 10.0 | ||
img[250:750, 250:750, :] = 255 | ||
|
||
mesh = trimesh.creation.box((0.5, 0.5, 0.5)) | ||
server.add_mesh_trimesh( | ||
name="/cube", | ||
mesh=mesh, | ||
position=(0, 0, 0.0), | ||
) | ||
server.set_background_image(img, depth=depth) | ||
|
||
|
||
while True: | ||
time.sleep(1.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters