PDA

View Full Version : Diffuse light on a sphere



Guus
05-10-2003, 10:11 AM
I created a sphere which acts as a planet, and I'm using a diffuse light to immitate a sun. My problem is this:

As the diffuse light seems to be a inifinitive small point, it's always smaller than my sphere. Thus, my 'sun' won't ever light more than half of my 'planet,' right?

in ascii-art:
'sun' (diffuse light) <O (sphere) 'planet'

the sunrays have to expand (symbol < ) to cover the planet, which means more than half of my planet will always be in the dark.

I actually want my 'sun' to be bigger than my planet, like this:

'sun' O> (same sphere as before) 'planet'

How do I do this? I was thinking of using two diffuse lights, kind of like this:

'two suns' :> (sphere) 'planet'

The problem with this is that if one of the 'suns' gets blocked, half my planet goes dark http://www.opengl.org/discussion_boards/ubb/smile.gif

How do I fix this? Ideally, I'd like to increase the size of the diffuse light, but I don't know if this is even possible.

I'm sorry for the kind of childish explanation, but I started OpenGLling yesterday, still have to learn the big words http://www.opengl.org/discussion_boards/ubb/wink.gif

Help much appreciated!

[This message has been edited by Guus (edited 05-10-2003).]

shinpaughp
05-10-2003, 10:55 AM
I do not think it is possible to do with traditional OpenGL lighting. There is (as far as I know) a limit of 8 lights at any time. And, it may give an approximation but I am not sure how good of one. If you are willing to look into vertex programs or other more advanced topics you could probably do it that way. I've never done it, and I am no expert. But, you could try the 8 lights set up at the perimiter of the circle of the sun which is perpindicular to the line between centers of sun and planet. It may not look too bad??? Just a thought. But, if it is way too slow, you could also try a lightmap of some sort with multitexture???

Guus
05-10-2003, 11:17 AM
I don't like the idea of using more than one lightsource to simulate the sun, although I don't see another approach at this time. I'll use it as a last resort.

I'm going to look into this "lightmap of some sort with multitexture" you mentioned (I don't have a clue what it means, but I'll find out eventually :P ). Thanks!

shinpaughp
05-10-2003, 11:37 AM
Basically, you have a second texture which I guess would be shades of gray or luminance (which is basically the same thing) and multitexture combines the other texture with your other texture if there is one. Otherwise you could just use texture mapping if you do not have another texture. Like I said, I've never done it, so I am not positive that is the best way or even a way, but it seems correct. So, basically, your lightmap would probably be the same always but it would be rotating around your sphere or at least rotating to remain facing sun in same way.

Perhaps if someone with more expertise comes along, or you could post a new message asking about light maps. Hope you are able to get it. http://www.opengl.org/discussion_boards/ubb/smile.gif

For some reason my brain is mush today http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Guus
05-10-2003, 11:43 AM
I think I get it http://www.opengl.org/discussion_boards/ubb/smile.gif
You suggest using another texture on the dark side of the planet to make that side darker. Can I mix two textures (or one texture and one color) or would one of the two be on top? If I can mix, I'd use a gray to invoke 'shadow.' ... sounds good http://www.opengl.org/discussion_boards/ubb/smile.gif

Somehow, this reminds me of painting with my fingers when I was a kid http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by Guus (edited 05-10-2003).]

Guus
05-10-2003, 12:15 PM
Hmm, drawback: last mentioned method would have a quite harsh border between shadow and sun, instead of the nice twilight-zone I get when using diffuse lighting.

shinpaughp
05-10-2003, 01:27 PM
Actually, if you have a texture say of the moon and the sphere is mapped with that then you get what you had - half or a little less than half lit. But, a second texture used as a lightmap (probably with lighting disabled - I dunno) whereby you have a square texture with a gradually decreasing brightness until it is black. Of course, to do it, some of the corner or edge ares would have to be lighter so that more than half of the sphere is lit.

Edit:
Actually, probably a rectangular texture like 128 x 64 (diameter for longitude by radius for latitude). Only problem is you have part a spherical lit area which extends beyond the edges and must be continued on corners... FUN http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Edit2:
You could also use environment mapping using cube map. Again, never done it, just read about it but wasn't ready to use it.

[This message has been edited by shinpaughp (edited 05-10-2003).]

[This message has been edited by shinpaughp (edited 05-10-2003).]