# Raycasting sparse TSDF

**URL:** https://discourse.vtk.org/t/raycasting-sparse-tsdf/12694
**Category:** Development
**Created:** [November 13, 2023, 4:28pm UTC](https://discourse.vtk.org/t/raycasting-sparse-tsdf/12694 "2023-11-13T16:28:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [November 13, 2023, 4:28pm UTC](https://discourse.vtk.org/t/raycasting-sparse-tsdf/12694/1 "2023-11-13T16:28:57Z")

</div>

Hi Developers

I am developing a real-time application where I want to perform raycasting on a block-sparse truncated signed distance field (TSDF). For this purpose my though is to use the multi-volume ray cast mapper, where each block can be represented by a `vtkImageData`. On every update, I will then update on few of the `vtkImageData`.

Question: Do we shaders that can be used for ray-casting a truncated signed distance field. I will get the colors from the resulting voxel? Do we have an example of ray-casting a TSDF?

Question: Ultimately, I will need to update/modify the `vtkGPUVolumeRayCastMapper` to accept meshes and update the TSDF prior to rendering. For this my plan is to re-introduce a compute shader pass. I did this a few years ago.

Question: Is there anyone working on either of the above two challenges?

Thanks in advance  
Jens Munk

---

<div class="post-metadata">

### Author: ![sankhesh](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sankhesh/32/73_2.png) [@sankhesh](https://discourse.vtk.org/u/sankhesh)
#### Post date: [November 13, 2023, 4:59pm UTC](https://discourse.vtk.org/t/raycasting-sparse-tsdf/12694/2 "2023-11-13T16:59:38Z")

</div>

> [@Jens\_Munk\_Hansen](#):
>
> Do we shaders that can be used for ray-casting a truncated signed distance field. I will get the colors from the resulting voxel? Do we have an example of ray-casting a TSDF?

There is nothing out of the box for TSDF volumes. But given that the volume shader is dynamically composed by the volume mapper, you should be able to modify the [scalar query](https://gitlab.kitware.com/vtk/vtk/-/blob/master/Rendering/VolumeOpenGL2/vtkVolumeShaderComposer.h#L2541) to be a computed value from the TSDF.

Note that there will be additional areas like gradient computation, etc. that would need to be modified.

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [November 13, 2023, 5:03pm UTC](https://discourse.vtk.org/t/raycasting-sparse-tsdf/12694/3 "2023-11-13T17:03:25Z")

</div>

Thanks. I will try out modifying the shader and with a single dense volume for starting. It is relatively easy to modify shader. A test volume. Next step will be figuring out how to incorporate a compute shader and update a volume owned by the mapper.

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [November 13, 2023, 10:39pm UTC](https://discourse.vtk.org/t/raycasting-sparse-tsdf/12694/4 "2023-11-13T22:39:07Z")

</div>

I made a small glfw program for testing a shader rendering a sphere. Figuring out exactly what parts to replace will take some time. Any interest in the community for raycasting og TSDF? Considering also to supporting some implicit primitives.
