Game Development Community

Sun Azumith and Zenith

by Gordon West (ToKrZ) · in Artist Corner · 10/24/2001 (2:15 am) · 15 replies

Are there azumith and zenith settings for the sun position? As in werew the shadows fall? Need to position sun for custom sky textures so that shadows fall properly....

#1
10/24/2001 (3:35 pm)
Yes there are, they are properties on the sun object. Select it in the mission editor from the mission object tree and you should see them in the inspector window. Or look at the .mis file, they shouldn't be to hard to spot.
#2
10/26/2001 (9:12 am)
ToKrZ posted partly on my behalf, thanks for replying Tim, but i dont see anything that resembles what you said... Here is a cut and paste from my .mis file:

new Sun(Sun) {
position = "-1024 -1024 0";
rotation = "1 0 0 0";
scale = "1 1 1";
direction = "0.622506 0.622506 -0.474313";
color = "0.800000 0.800000 0.800000 1.000000";
ambient = "0.400000 0.400000 0.400000 1.000000";
texture[0] = "special/sunFlare";
texture[1] = "special/sunFlare02";
texture[2] = "special/LensFlare/flare01";
texture[3] = "special/LensFlare/flare02";
texture[4] = "special/LensFlare/flare03";
lensFlareScale = "0.7";
lensFlareIntensity = "1";
frontFlareSize = "300";
backFlareSize = "450";
flareColor = "1.000000 1.000000 1.000000 1.000000";
locked = "true";

Now, I have tried messing with the rotation and direction fields, neither seems to change the direction the sunlight is coming from. The rotation didnt seem to do anything, and the direction field is.. well... conmfusing. It DID do something, but it didnt change the direction of the shadows noticably at all. Any further help would be greatly appreciated.
#3
10/26/2001 (9:19 am)
Well it worked for me so...
Try saving the changes and restart the mission.

// Clocks out
#4
10/26/2001 (9:34 am)
The direction is a vector representing the direction of light comming from the sun (z is always negative). Not as easy to use as azimuth and zenith, you have to visualize that one :) You also have to re-light the misison to see sun changes.

I think there is a bug with the terrain lighting, as I've seen some wierd results with some sun vectors. I haven't really played with it much though.
#5
10/26/2001 (9:42 am)
I have a mission where i used a butmap to make the heightfield.
As you know the bitmap is getting flipped so its upside down.
That wouldn't normally mean anything as you can just flip it in photoshop.
But I have noticed a weird side effect with this flipping.
The shadows on the terrain cast by the WC buildings and the shadows cast by the player model is pointing in 2 different directions. 180 degrees to be exact, and that off couse looks stupid.
It's my guess that the light/shadow map for the is getting flipped as well but the player shadow stay the way it should.

// Clocks out
#6
10/26/2001 (11:33 am)
Yeah, that could be. It's on our list of things to investigate. If some takes a look before us, please post about it :)
#7
10/26/2001 (12:14 pm)
hehe, thanks Tim, could you or someone else explain to me, in laymans terms, how to use the direction field? All I want is for the shadow to fall in the exact opposite direction as it is now.. (See the above code snipet in my other post)
#8
10/29/2001 (1:01 pm)
Here's a little question for you that falls under this category - sort of. Why is it, when I run the V12/Torque test app with my new building, shadows on the lightmap caused by sunlight go in one direction, but shadows caused by the player model always fall in the opposite direction?
#9
11/06/2001 (8:13 am)
I looked into it at one point and it turns out the some of the objects do not get their sun direction from the sun. I don't think T2 missions ever change the sun position, or they would have noticed this one earlier :)
#10
11/28/2001 (3:33 pm)
Erm. I think there may be more wrong than that.

With direction set to 0.157372 0.892542 -0.422615, color all 1's, and ambient all 0's (to make the shadows more obvious) WaterWorld looks like this:

hosted.tribalwar.com/zear/temp/screwy_shadows.jpg
According to the lighting of objects (buildings, trees, etc.) the sun (or it's origin of light anyway) should be in the field of view shown here. What's with the funky lit strip over there. Am I just missing something?

As a matter of fact, not only is that strip of hillside odd, but by walking around in the game and looking at various points, I see a lot of oddly lit areas. This one might be explained by the sun being low behind me, and there being two big hils blocking the light, but in other places there are shadows that look to me like they could only be thrown from another direction (and no, they aren't player or object shadows - they are from terrain). The sun can't be in more than one place can it?

Can someone else put the above values into the sun object on WaterWorld and make sure I haven't simply lost my mind? Cause the shadows I'm seing are a bit strange.
#11
11/29/2001 (8:09 am)
After some experimentation, I have noticed the following about lighting and shadows:

1) Object shading (the darkening of an object on the side opposite the sun/light source) is correct for the sun position - for both shapes (.dts) and interiors (.dif).

2) Shape (.dts) shadows are always cast to the southwest, regardless of the sun direction.

3) Interiors (.dif) do not appear to cast shadows at all.

4) Terrain features are shaded and cast shadows toward the west, regardless of the sun direction (as if the sun were in the east - morning is eternal ).

This means the engine is using three different light source directions, two of them hardcoded, and is failing to cast shadows based in the interiors at all...

Erm, wish I had a clue how to fix it...
#12
11/29/2001 (9:02 am)
Further checking shows that the player's shadow does indeed exhibit the same behavior in T2. Interiors (.dif) also throw a coorect shadow, based on the sun direction in T2. Terrain shadows however are close but act oddly. If a gully exists to the west of a hill, and the sun is in the east, the hill will shadow the far side (west side) of the gully, but down in the gully itself, it is fully lit (this despite the fact that the gully is entirely in the shadow of the hill). Go figure.


Finally, I have written small utility to translate sun direction and elevation values in degrees into the appropriate vector needed for the sun object. Seems to work fine (obviously it doesn't fix the bugs mentioned above tho). I just need to write up a little readme and disclaimer, etc. Mebbe today...
#13
02/28/2002 (7:33 pm)
mmm... was wondering... what happened with all this?
#14
03/07/2002 (7:07 pm)
The best I can tell the odd artifacts are caused by the sun vector pointing up instead of down at the terrain. This leads me to believe that what's happening with the odd shadows is the underside of the terrain is used to generate the shadows instead.

With out looking at the source though there's really no way of knowing. For all we know the lighting engine could make assumptions when given erraneous data.
#15
03/20/2002 (12:03 pm)
No, Tim's lightDir vector has -z, meaning its pointing down. And he pre-normalized it, so those are the values the engine is using. It's just real low to the ground.

He's correct about the player shadow. It's hardcoded. And the shapes cast no shadow at all.

But the difs have a problem with shadows being slightly off--working on that. As to the odd terrain shadows, that bears some more investigation also.