Success with Geometry Shaders

So finally, after playing around a bit with Geometry Shaders and having brainstormed a lot, we got some success in Geometry Shaders and this can be considered as a good accomplishment in this GSoC project. With the help of vtk.SetGeometryShaderCode now I am able to inject my custom shader and able to amplify points.

As a first step towards achieving custom visualization, I attempted to amplify a point into lines as given in the example here. I was able to achieve this but was unable to color the points as per my wish. This is where David came to my rescue and helped me out with coloring the points in a GS.

The trick here is to add line_strip as the output of the Geometry Shader. In case we want triangle strips, we have to replace it with triangle_strip. On the first go, I obtained a visualization as shown below. The complete code is available here.

Next, after having checking basic line rendering, its time to try out with 2-D shapes such as triangles and squares. So replacing line_strip with triangle_strip and make necessary changes, we obtain a beautiful representation of a pentagon each on the four positions of the screen as shown below. The complete code for this part of the project can be seen here.

The aim now is to display a sphere built using triangles as done previously using vertex and fragment shaders. As of now, we are able to see shapes on the screen but unfortunately, we hit vertex limitation as we can not use too many vertices in a single geometry shader. For my system with Windows and anaconda environment, we can get only 256 amplified vertices per base vertex. For David, this number was less than 256. So, we may not be able to use Geometry Shader to always render complicated shapes but this is surely interesting and can be of great use.


The progress with Geometry Shaders so far

As mentioned in the previous post, we are having issues implementing the manual Geometry Shader part. I posted on the vtkusers mailing list and finally got the attention of Ken from Kitware. He pointed out that we might be missing some uniform variables. He was correct and we made a progress by manually setting the uniform shader. But it does not render as a tube but only as a line. Our next step is to make it work like a tube. After having found the initial glitch, I think either me or David will come up with a correct implementation of the Geometry Shader.
Meanwhile, for the purpose of putting into mailing list, I wrote a small snippet with 3 cases – 1st to render a simple line, 2nd with SetRenderLineAsTubes() and 3rd with Geometry Shader manually being injected into the code.  Later, it was pointed out by Elef that we were not specifying any value to the uniform variable linewidthNVC. I manually used vec2(0.1, 0.1) instead of this variable to be able to see the lines on the screen. But also, it was observed that still, it is not tube.
We are hopeful of more progress in coming days, as we now have a better understanding of how Geometry Shaders work.

The code can be seen here.


The uncertainty with injecting Geometry Shader in vtk

Hello all,
For the last two weeks, I have been focusing on how to set custom Geometry Shader Code to any simple vtk mapper with actors. In the case of Fragment Shader and Vertex Shader, this task of injecting code was relatively easier and has been well explored by me. Now shifting our focus to Geometry Shaders, we encountered a few abnormal behaviours.

From the documentation and source code of vtk, it is very clear that the library supports custom Geometry Shader along with a few other custom shaders available.  The default Geometry Shaders for WideLines works very well. The existing example in dipy docs with and without geometry shaders is attached. The difference can be clearly observed in this case.

For the task of replicating the shader, I used the method ‘SetReplacementShaderCode’ to set the same code given in WideLines. It is somehow not working well. The same was also observed by David and we are currently approaching the vtk mailing list to get more insight into the problem we are facing now.

The current working of the normal renderer and the one with WideLines enabled are shown below.

Line with WideLines GS disabled.

Line with WideLine GS enabled.

We are hoping to find the solution to this issue and hopefully help vtk with a few working examples of the same.