Render a Sphere

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

Recommended Posts

Hi, Im trying to do something fairly 'simple' Using raytracing, I want to render a simple sphere. But the thing is, I don't have an polygonal data for it, but instead I want to render it based of some attributes (so it will be a perfect sphere). For example, I know it has a location and radius. So I cast my rays towards the location. I determine how far away the ray is from the spheres location Give that ray point a clamped gradient value (based on the radius). The result is a simple circle gradient: What I want now is to render it with some lighting (and eventually with reflection and specular highlights), but to do this I need the normal of a point on the spheres 'surface' How would I calculate this? If I sent a ray directly to the center of the sphere, I know the normal at that point would be directly reflected towards the camera, but I cant work out how to do it for any part of the 'sphere'

Share on other sites
the normal of a sphere on a given position is simply the vector from the center of the sphere to this given location. But dont forget to normalize it ;)

Share on other sites
If your sphere has for center O, and your ray intersects the sphere at point I, then the surface normal at I is colinear with the radius vector OI.

Share on other sites
First thing's first. You need to find out how to determine (in 3D) if and where a ray intersects with a sphere of a certain radius.

The following publication presents a function called intersectSphere in the QJuliaFragment.cg file. It's in Cg, but should be more than understandable to a C++ programmer:
http://graphics.cs.uiuc.edu/svn/kcrane/web/project_qjulia.html

Using a bounding sphere as such, the intersection test generally runs in constant time, O(n). This speeds up the render quite nicely.

As suggested above, once you find the ray-sphere intersection point on the sphere surface, you determine its surface normal by pointing a unit vector from the sphere centre towards it.

That should lead you right up to the lighting stage.

1. 1
2. 2
3. 3
frob
12
4. 4
5. 5

• 13
• 14
• 65
• 14
• 15
• Forum Statistics

• Total Topics
632130
• Total Posts
3004286

×