View Full Version : Torus

03-31-2009, 05:43 PM
Not entirely certain if this is the right place. I'm giving a seminar presentation on Morse Theory, and part of this involves an example with a function (actually, set of functions) which acts on the surface of a Torus. I have a function f(x,y,z,t) which when given a value on the torus and a time t will define what color I want to set that point.

The problem is that the behavior of this function on a small scale is rather crucial. Two "sections" of the torus coming together at a corner can't look like they are doing so in a more parabolic fashion, and vice-versa. So far I've been trying to increase my polygon count, but I'm at the limits of my laptop and it's still not really as nice as I want it.

Right now I'm defining the torus with GL_QUAD_STRIP and using display lists. So for each time t, I need a different list because at each different point in time the function f will result in coloring the torus a bit differently. 100 or so such lists will be sufficient.

An example of such a function is simply:

f(x,y,z,t) gives red if z < k(t), blue otherwise, for some function k(t).

There are a few more functions like this, each a bit more complicated, but that's the main idea. So is this the right way to be going about this? Or is there something more efficient I can do?

What I'm going to attempt next is to write an adaptive algorithm so that my polygon count increases at certain points on the torus.

03-31-2009, 10:03 PM
If I understand you correctly, your torus should be one part red, the other part blue, split by the plane z=k(t).

A simple and performant way to achieve this is using a fragment shader. Specify k(t) as a uniform parameter. This way you will have your colouring decision on a per pixel basis, no need to tessellate your torus to much.

If shaders are not an option, you could draw your torus twice, once solid red, once solid blue, and specify a clipping plane to cut off the other part. Again, no need to tessellate your torus beyond what your hardware can handle.

04-02-2009, 03:47 PM
I have no experience with shaders (yet), but that sounds like it will do the trick. Hopefully I'll start looking into them this weekend. But before I do, I'm wondering if it will work when I add a second function:

Pick a point on the torus (x,y,z), and what I wish to do is set every point within epsilon distance (distance being the standard distance in 3-space, not distance as defined with geodesics on the torus) of this point to be the color yellow.

So will the shader also work for this? And if so, would you happen to recommend any online tutorials for it?

04-02-2009, 11:11 PM
Yes, you can do per fragment (that is: point that might end up as a pixel) color computations.

For a start, you might take a look at this tutorial (http://www.lighthouse3d.com/opengl/glsl/).
But beware: this tutorial is targeted at opengl 2.0 (or previous versions with extensions) and glsl 1.0. The glsl has changed quite a bit since then. So in the long run you might also what to take a look at the spec (http://www.opengl.org/documentation/specs/).