Lighting a Sphere

I’m really enjoying OF => there has been some tremendous work put into it, and it shows.

I’m building a solar system model for a class. It works great, but the sun (which has the main, point light source) is dark. I assume because the light is emanating from it. If the image shows up below you can see what I’m talking about.

[The sun is the dark object in the middle. The others are planets with correct shading]

How would you go about lighting the sun? With two spotlights on it? Or is there a better way?

Thank you

1 Like

Hi. Good to know you’re enjoying OF. :smiley:

There are several methods, from fancy raymarching, raytracing or using open GL materials and such, although I would choose the simplest one, which is faking it. Considering that the sun, as a light source should be a more or less homogeneous you can simply put a white 3D sphere with the illumination off. Make sure you put ofEnableDepthTest() before rendering the shperes and ofDisableDepthTest() after rendering these, so the overlaps look correctly.

you can set the emissive value of the sun so it emits light, that light won’t light up other objects but the object itself will appear lighten up

Oh, true. Thanks for noting it :slight_smile:
Although this implies using ofMaterial. I think there are no examples for how to use ofMaterial, right?

That was super-helpful guys. Got it. Thanks for your reply.


which approach you used?

I had to combine both of your approaches. First setting up a material and then setting it emissive color. (Show below in case someone else is trying to figure it out):

this->material.setShininess(0.5); //not sure if this is necessary

Thanks for pointing this out! It’s a simple trick and works great with ofDrawSphere() and a simple ofLight().

What I did is first draw all the spheres in the same white color, including the dark spherical star in the middle with the light inside. After that I did ofDisableLighting() and drew the centered star again, then turned lighting back on.