Game Development Community

Sphere rendering/lighting

by William Finlayson · in Technical Issues · 02/17/2002 (12:02 pm) · 3 replies

Can anyone tell me, or point me to some tuts about rendering a lit sphere. Nothing fancy, just lighting up the portion of the sphere that is facing the light source.

It doesn't need to be especially fast, nor perfect, just clear - I would be more interested in finding out how it works. The accuracy is of little importance.

There's loads on how to light triangles, but I have no idea how that could be translated onto a sphere.

I have written a 3D engine in java using spheres as the basic world element. All the transforms are there for skeletal models, the perspective correction is nice and fast, and I can draw the spheres fast. Only problem is that they are a simgle colour, so it doesn't look very 3D. I played around with calculating an elipse for the boundary of the light on the sphere, but gave up on that, as I have no idea how to rotate the elipse so that the light can be simulated from any direction.

#1
02/17/2002 (2:58 pm)
If you want to do your own vertex lightning , you can do this:

for every vertex you have
{
1)vertex_normal=vertex_position- sphere_center
2)Light_magnitute=light_direction dot vertex_normal
3)Light_value=light_color modulate light_magnitute
4)vertex_color=light_value
}
5)render the sphere as you did with lit vertex.
#2
02/18/2002 (10:27 am)
That would be fine, but I'm not drawing it using triangles, I'm just rendering a sphere directly. At the moment that just means drawing a flat, solid circle on the screen :)
#3
02/26/2002 (5:29 pm)
For each pixel that you render you could calculate what that point is on the sphere (possibly by a ray-sphere collision test) then derive the the normal for that point which you could use to find the ambient color, diffuse color, etc for that point.