Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Show function on the surface of a sphere

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    6

    Show function on the surface of a sphere

    Hey Guys!

    I'm a absolute beginner in OpenGL. I have created a sphere with the help of tutorials. Now i would like to display a function on the surface of the sphere. This means for every point (x,y,z) on the surface of the sphere i compute a scalar value f(xi,yi,zi) = si and assign a color to this value.

    Do someone of you know a tutorial that shows how to achieve this or can explain it to me?

    Thanks in advance,

    AeRoOo

  2. #2
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    187
    I have created a sphere with the help of tutorials. Now i would like to display a function on the surface of the sphere. This means for every point (x,y,z) on the surface of the sphere i compute a scalar value f(xi,yi,zi) = si and assign a color to this value.
    Depends on what you mean by 'create'. Did you use gluSphere, or did you define surface polygons by computing the coordinates of the vertices?

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    6
    Quote Originally Posted by Carmine View Post
    Depends on what you mean by 'create'. Did you use gluSphere, or did you define surface polygons by computing the coordinates of the vertices?
    I created it with gluSphere. Is this good / bad?

  4. #4
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    187
    I created it with gluSphere. Is this good / bad?
    Neither good or bad. What I would try to do in this situation is texture map the sphere with an image onto which you plot your function. gluSpheres have texture coordinates assigned, so you don't have to worry about that. You will have to convert (xi, yi, zi) into 2D image coordinates, generate the image, then map it onto the sphere. As a first step, try mapping any image onto the surface of the sphere. If you can do that, it will be very easy to map images you generate onto the sphere.

    Note - that I use the older, classic version of GL. Modern GL users might have other suggestions for you.

    An example is shown below. I compute the image in my C code, then map it onto a rectangle (flat map) and a sphere (earth globe) using texture mapping.

    Click image for larger version. 

Name:	Sphere_Surf_Map.jpg 
Views:	59 
Size:	51.3 KB 
ID:	1238
    Last edited by Carmine; 03-13-2014 at 10:00 AM.

  5. #5
    Intern Contributor Brokenmind's Avatar
    Join Date
    Feb 2014
    Location
    Aachen / Germany
    Posts
    71
    Do you want to assign the colors to each vertex individually and interpolate between them (so that the colors fade), or do you want pixel-precise color transitions showing accurate curves?

    The problem with a texture is that you have to know beforehand what function you would like to plot and cannot change it afterwards. Plus, you have to distort it at the poles of the sphere. A more dynamic approach could be achieved with shaders, where you can change the parameters at runtime according to your function or even recompute the shader into something new.

    If possible, you should refrain from drawing the gluSphere() and create a VBO with all the vertices and normals you need. This gives you a much greater freedom in achieving what you want.

  6. #6
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    6
    at Carmine: Thank you for your suggestion. I have implemented this idea in Matlab and it is a good starting point for my implementation in C++.

    at Brokenmind: Sorry i'm a newbie in OpenGL. I have scattered data points on the surface of the sphere and i interpolate between this points (this is the function i want to show). So i can compute a value for an arbitrary point on the sphere.

    Quote Originally Posted by Brokenmind View Post
    A more dynamic approach could be achieved with shaders, where you can change the parameters at runtime according to your function or even recompute the shader into something new.

    If possible, you should refrain from drawing the gluSphere() and create a VBO with all the vertices and normals you need. This gives you a much greater freedom in achieving what you want.
    That sounds very interesting. Could you please guide me to some good tutorials to create a VBO and the more dynamic approach with the shader?

    Thank you two for your help.

  7. #7
    Intern Contributor Brokenmind's Avatar
    Join Date
    Feb 2014
    Location
    Aachen / Germany
    Posts
    71
    If you only have scattered points on the sphere's surface, there is no need for shaders. They work best if you have a mathematical description for the function you want to show, which I thought you meant by saying
    Quote Originally Posted by AeRoOo View Post
    This means for every point (x,y,z) on the surface of the sphere i compute a scalar value f(xi,yi,zi) = si and assign a color to this value.
    With scattered points, this might be a little more difficult, as they cannot be assigned to the default sphere coordinates given by gluSphere() or any custom-made regular sphere representation, e.g. icosahedron. You could of course interpolate your points and imitate a smooth curve, but that depends on the values you want to plot. You dont have some graphical example of what you want to do, by chance?

  8. #8
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    6
    Finally i would like to have something like:

    Click image for larger version. 

Name:	idea.jpg 
Views:	21 
Size:	13.6 KB 
ID:	1239

    So my idea is to interpolate between my scattered data points (= position + e.g. temperature). This gives me a function for e.g. the temperature over the whole sphere and i can determine for an arbitrary point on the sphere the interpolated temperature. Now i'm not sure how to visualize this function like it is shown in the example image. As last step i will map the outlines of Earth's continents on the sphere.

    Does this help?
    Last edited by AeRoOo; 03-14-2014 at 05:37 AM.

  9. #9
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    187
    Quote Originally Posted by Brokenmind View Post
    The problem with a texture is that you have to know beforehand what function you would like to plot and cannot change it afterwards.
    My textures are computed on the fly. As the satellites orbit the coverage swaths are updated. Also, the swath widths can be changed interactively. So I am constantly changing the texture.[/QUOTE]

    Plus, you have to distort it at the poles of the sphere.
    This is a very straightforward lat-lon to spherical conversion.

    Would this run faster with shaders and VBO's? Probably - but I'm satisfied with what I have now.

  10. #10
    Intern Contributor Brokenmind's Avatar
    Join Date
    Feb 2014
    Location
    Aachen / Germany
    Posts
    71
    You got me; I've never done sphere mapping before and thus am not familiar with the coordinate conversion.

    If the creation of the texture is computationally efficient, then this is no problem. My experience with procedural textures is that the creation can take quite some time, so the process either takes quite long or the result needs to be fairly small. Do you have a basic texture on which you only highlight certain areas? Again, I didn't try this before.

    Anyway, I think your solution is much more suited for the OP than mine I was expecting a more noise-like surface like this, but for a reality-based globe, this is hardly an option.

    €dit: This might be faster with VBOs and shaders and might give you more freedom in doing fancy things, but you're right, it might not be necessary.
    Last edited by Brokenmind; 03-14-2014 at 09:19 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •