Jump to content
  • Advertisement
Sign in to follow this  

How to create half-spheres?

This topic is 2862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there. I am currently rendering a lot of spheres.

However, they are only seen from one direction (like in a 2D game), and it would be more optimized if they were half-spheres for that reason. The reason it needs to be spheres and not just circles, is the fact that I need lighting to work on it, so it will still look three-dimensional.

How can I create a vertex- and indexbuffer of a half-sphere?

Share this post


Link to post
Share on other sites
Advertisement
This might be a bit easier if you approach it in more general terms.

Given an arbitrary triangle mesh, how would you clip it with a 3D plane and only keep one side of the plane and remove the other?

Iterate through each triangle:
1. if it's behind the plane, discard it completely.
2. if it's in front of the plane, keep all of it.
3. if it intersects the plane, clip the triangle against the plane and store the modified (at most two) triangles. (For your case, you might not even implement this.) Google helps you here, see for example http://graphics.idav.ucdavis.edu/education/GraphicsNotes/Clipping/Clipping.html.

Now, generating a half-sphere with the above routine is just about generating a sphere and then cutting it in half with a plane.

If you really care the most about your vertex use, then the most desired way to do this for a sphere is to find a plane that splits you sphere cleanly in half, i.e. without the case 3) from happening. That way you won't generate any odd-shaped small triangles at the rim. Whether this is possible of course depends on your construction of the sphere geometry.

The extra hidden triangles in full spheres only burden your vertex shaders, since they're culled. Have you profiled that the bottleneck really is in your vertex shader step, and not e.g. your CPU-side batch submits (since you're rendering lots of objects)? Your case smells a bit like where draw call instancing might help. (Of course, profile first before conclusions)

Going through the trouble to optimize away hidden geometry that the GPU already optimizes away quite effectively might not solve your problems, but naturally if those hidden backsides are 50% of your scene geometry..

Share this post


Link to post
Share on other sites
use quad sprites with normal mapping, and you have plane with image of sphere,
and surface normal of sphere witch comes from normalmap. (correct lighting)

(if you have overlaping spheres, you can use per-pixel depth write.)

Or more complex way in case of extreme angle of view.
Create mesh of half sphere, and use vertex shader to
rotate hemisphere to face cam.

/Tyrian

Share this post


Link to post
Share on other sites
Find a piece of code that creates a sphere, look for the loop that goes around 360 degrees (2 pi in radians) and change it to 1pi or 180 degrees.

Share this post


Link to post
Share on other sites
I agree with TyrianFin, but if you really want a 3d model then why not just make it in a 3d modelling program like Maya or 3D Studio Max ?

Share this post


Link to post
Share on other sites
Quote:
Original post by Darg
Find a piece of code that creates a sphere, look for the loop that goes around 360 degrees (2 pi in radians) and change it to 1pi or 180 degrees.


If you are interested in this method I can provide some info to you get you started as this is what I've done for my own spheres.

I think a google for 'spherical coordinates' will be a good starting point if you are interested.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!