# How to create half-spheres?

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

## 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 on other sites
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 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 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 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 on other sites
Quote:
 Original post by DargFind 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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 14
• 14
• 45
• 22
• 27
• ### Forum Statistics

• Total Topics
634043
• Total Posts
3015206
×