toastedcrumpets

12-15-2011, 11:10 AM

This problem is a little involved, but I was hoping it might catch the eye of some advanced GL programmer out there (I'm looking at you DarkPhoton).

I've got a shader which ray-traces spheres for a molecular visualizer I've written.

Shader Code:

https://github.com/toastedcrumpets/DynamO/blob/experimental/src/magnet/magnet/GL/shader/sphere.hpp

I'm very happy with the shader, it works by

- Taking in a VBO of GL_POINTS

- The geometry shader creates a camera-facing billboard centered at the location of the point with the width/height of the sphere diameter.

- Then the fragment shader discards all fragments outside of the circle inside the billboard, and calculates a normal and gl_FragDepth for any fragment inside the circle using the equation of a sphere.

The problem is although I am now capable of rendering millions of perfect spheres, they're not quite perfect.

As an example, the left image is ray-traced, and the right image is from a high resolution triangular mesh.

https://marcusbannerman.co.uk/Raytraced.jpghttps://marcusbannerman.co.uk/Meshed.jpg

What I hope you can see is that the triangular mesh spheres are "fisheyed" by the projection. I need some way to add this perspective effect in the ray tracing of the spheres.

This is more important to me than you might think as I have played around with head tracking (wii-mote) and 3DTV displays and the ray-traced spheres don't quite look right in 3D due to this issue.

For reference, I started with this resource on GLSL sphere ray tracing

http://morgan.leborgne.free.fr/Home.html

And to get anti-aliased ray-traced spheres I used the GL_ARB_sample_shading extension to force per-sample evaluation of the fragment shader.

I've got a shader which ray-traces spheres for a molecular visualizer I've written.

Shader Code:

https://github.com/toastedcrumpets/DynamO/blob/experimental/src/magnet/magnet/GL/shader/sphere.hpp

I'm very happy with the shader, it works by

- Taking in a VBO of GL_POINTS

- The geometry shader creates a camera-facing billboard centered at the location of the point with the width/height of the sphere diameter.

- Then the fragment shader discards all fragments outside of the circle inside the billboard, and calculates a normal and gl_FragDepth for any fragment inside the circle using the equation of a sphere.

The problem is although I am now capable of rendering millions of perfect spheres, they're not quite perfect.

As an example, the left image is ray-traced, and the right image is from a high resolution triangular mesh.

https://marcusbannerman.co.uk/Raytraced.jpghttps://marcusbannerman.co.uk/Meshed.jpg

What I hope you can see is that the triangular mesh spheres are "fisheyed" by the projection. I need some way to add this perspective effect in the ray tracing of the spheres.

This is more important to me than you might think as I have played around with head tracking (wii-mote) and 3DTV displays and the ray-traced spheres don't quite look right in 3D due to this issue.

For reference, I started with this resource on GLSL sphere ray tracing

http://morgan.leborgne.free.fr/Home.html

And to get anti-aliased ray-traced spheres I used the GL_ARB_sample_shading extension to force per-sample evaluation of the fragment shader.