# Multivolume : Shading is not working

**URL:** https://discourse.vtk.org/t/multivolume-shading-is-not-working/771
**Category:** Development
**Created:** [April 17, 2019, 7:56am UTC](https://discourse.vtk.org/t/multivolume-shading-is-not-working/771 "2019-04-17T07:56:32Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![CNA](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@CNA](https://discourse.vtk.org/u/CNA)
#### Post date: [April 17, 2019, 7:56am UTC](https://discourse.vtk.org/t/multivolume-shading-is-not-working/771/1 "2019-04-17T07:56:32Z")

</div>

Hi everyone,

I am trying to use a vtkMultivolume with a vtkGPUVolumeRayCastMapper in 8.2 in c++ and I found something weird.

When there is only on port used in the mapper and also one port used in the vtkMultivolume I can see that a shader is computed, I can see shadows. The volume is thus “well” displayed.  
However, when I add more volumes there is no more shader and the result is obviously bad.

I also found a note in TestGPURayCastMultiVolumeOverlapping.cxx saying :  
" // Note: Shading is currently not supported with multi-volume active  
//-\>ShadeOn();"

Do you have any idea if I can apply a shader by my own or if there is a way to active the shader even if there are multiple volumes displayed ?  
I’m also wondering if it’s because of the mapper or because of the multivolume.

You can see an example here : (1) Only 1 volume. (2) Two volumes but I hid one to have the same view.

![image](https://discourse.vtk.org/uploads/default/original/1X/fbe86f9950c96185256d6b738ac4a926a8fb5e61.jpeg) (1)  
 ![image](https://discourse.vtk.org/uploads/default/original/1X/3213c8eac849cd2e073c3f96fd9554d45e7db113.jpeg) (2)

Thanks for your help.  
Regards,  
CNA

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [April 17, 2019, 12:22pm UTC](https://discourse.vtk.org/t/multivolume-shading-is-not-working/771/2 "2019-04-17T12:22:55Z")

</div>

As far as I know, developers ran out of time/funding before they could complete implementation of shading in the multi-volume mapper, but it should not be too difficult to do it.

Would you have time and expertise (or funding) to contribute to the development?

---

<div class="post-metadata">

### Author: ![CNA](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@CNA](https://discourse.vtk.org/u/CNA)
#### Post date: [April 18, 2019, 3:05pm UTC](https://discourse.vtk.org/t/multivolume-shading-is-not-working/771/3 "2019-04-18T15:05:16Z")

</div>

Hi Lassoan, Thank you for your answer.

I might be able to work on this implementation but I’ll need some help. Do you have any idea how I can start and what I should do in general.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [April 18, 2019, 3:11pm UTC](https://discourse.vtk.org/t/multivolume-shading-is-not-working/771/4 "2019-04-18T15:11:14Z")

</div>

I don’t know the details well enough but @ken-martin, @sankhesh, or @Simon should be able to help you to get started.

---

<div class="post-metadata">

### Author: ![Simon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@Simon](https://discourse.vtk.org/u/Simon)
#### Post date: [April 18, 2019, 7:00pm UTC](https://discourse.vtk.org/t/multivolume-shading-is-not-working/771/5 "2019-04-18T19:00:29Z")

</div>

If you know something about GLSL shaders, I think it shouldn’t be too difficult to fix the problem.

`vtkOpenGLGPURaycastMapper` compiles a fragment shader program that computes the ray integration for each pixel to render. The code of this shader program is modified and recompiled when you change the parameters of the mapper (`vtkOpenGLGPUVolumeRayCastMapper::BuildShader()`).

When assembling the different shader program parts, the mapper has a different behavior for the single volume and the multi volume cases (see [this line](https://gitlab.kitware.com/vtk/vtk/blob/master/Rendering/VolumeOpenGL2/vtkOpenGLGPUVolumeRayCastMapper.cxx#L2550) and below). The multiple volume case doesn’t even try to take into account shading. So, basically, you need to find a way to either merge `vtkvolume::ShadingMultipleInputs()` and `vtkvolume::ShadingSingleInput()` into a single function that handles all cases or bring the functionality of `vtkvolume::ShadingSingleInput()` to the multi-volume function.

To help with the development, you can set a path with `vtkShaderProgram::SetFileNamePrefixForDebugging (const char *)`, which will output the shader program to the file once assembled.

Let me know if you have more questions.

---

<div class="post-metadata">

### Author: ![CNA](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@CNA](https://discourse.vtk.org/u/CNA)
#### Post date: [April 26, 2019, 9:23am UTC](https://discourse.vtk.org/t/multivolume-shading-is-not-working/771/6 "2019-04-26T09:23:11Z")

</div>

Hi @Simon

Thank you for this explanation. I’m starting to work on it and I want to output the shader of the “ShadingSingleInput” to compare the shader i’m actually coding for each volume of the MultiVolume. (I assume that it should be close to the one compute on a single volume).  
However i’m struggling at using this function " vtkShaderProgram::SetFileNamePrefixForDebugging (const char \*)"  
Would you like to help me on this ?

Thank you

CNA.

---

<div class="post-metadata">

### Author: ![Simon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@Simon](https://discourse.vtk.org/u/Simon)
#### Post date: [April 26, 2019, 6:38pm UTC](https://discourse.vtk.org/t/multivolume-shading-is-not-working/771/7 "2019-04-26T18:38:50Z")

</div>

Can you be a little more specific about your difficulty with vtkShaderProgram? I just found out @cpinter is also interested in fixing this shading problem. You might want to coordinate.
