Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem with positional light and camera.

Started by SirTwist Aug 27, 2006 at 11:11 AM 2 replies 950+ views
Original Post
SirTwist
SirTwist
Hello there, I got a weird problem. I made a little program where I just put a few rectangular surfaces into a 3D space and I built a camera class (based on the NeHe camera tutorial) to move around in this small world. Now I added a positional light, which I can move around as well. One of the surfaces is simply white colored without texture. The positional light has red color. Now if I move the light close to the white surface a strange behaviour can be observed. The color added to the white surface seems to be dependant on where my camera is located (or rather which direction it is facing. Cause even if there appears a red spot (from the light) on the surface, when I rotate the camera that spot moves also or even gets bigger or smaller or disappears entirely. Whatever the change, the rotation definitely influences the color which the surface gets from the spot light ... question is why ? Has anybody experienced something like this, or can even help ? Cheers SirTwist
TheBlackJester
TheBlackJester
Hey,

Easy solution. You simply need to set the light position AFTER you apply the camera transform. When you move a camera around, you're applying a matrix transformation that is, in reality, moving everything else around in exactly the opposite direction. If you position your light only once in your setup, or you position it before the camera transform, it's not being affected by the camera transform and it will always be relative to the camera position.

"With my feet upon the ground I lose myself between the sounds and open wide to suck it in, I feel it move across my skin. I'm reaching up and reaching out. I'm reaching for the random or what ever will bewilder me, what ever will bewilder me. And following our will and wind we may just go where no one's been. We'll ride the spiral to the end and may just go where no one's been." - Maynard James Keenan <
Red_falcon
Red_falcon
Maybe its the simulation of reflection/glossiness. I read something about similiar thing on lighthouse3d.com
-----"Master! Apprentice! Heartborne, 7th Seeker Warrior! Disciple! In me the Wishmaster..." Wishmaster - Nightwish
SirTwist
SirTwist
Indeed, BlackJester ... how incredibly stupid of me. Actually I thought I had tried this solution already. But obviously I did not.

Thanks so very much. This had cost me some sleep yesterday. God, I feel like such a moron.

Oh, as long as I am at it, I just encountered another question mark (yeah, got lots of them :)). The surface only is colored by the positional light as long as the surface color is plain white. As soon as I change the color of the surface to, e.g, blue the light doesn´t seem to affect it anymore. Is there a valid reason for this behaviour ?

SirTwist

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.