Tile illumination for trunk

Discuss the future of Warzone 2100 with us.
i-NoD
Code contributor
Code contributor
Posts: 318
Joined: 30 Nov 2008, 00:42
Location: In the middle of nowhere

Tile illumination for trunk

Post by i-NoD »

Hello everyone!

I've noticed some inconsistency with model shadows and terrain illuminations. If you look at model shadows then you can tell that light is coming from the south-west, yet cliff faces are lit from north. Plus all territory from the wall to the bottom of the screen is visible to player, but it looks like shrouded in some places.
wz2100-20120130_054336-Sk-Rush.jpg
With a quick change I've inverted sun position for terrain, here are the results:
wz2100-20120130_054422-Sk-Rush.jpg
The main problem is with mini-map, it look a bit inverted now. Dunno if its some hack buried there or it need another hack :roll:

Here is the patch, any thoughts are welcome...

Code: Select all

diff --git a/src/lighting.cpp b/src/lighting.cpp
index 0b21350..d9f951d 100644
--- a/src/lighting.cpp
+++ b/src/lighting.cpp
@@ -217,7 +217,8 @@ static void calcTileIllum(UDWORD tileX, UDWORD tileY)
 		finalVector = finalVector + normals[i];
 	}
 
-	dotProduct = normalise(finalVector) * theSun;
+	Vector3f sunVector(theSun.x, theSun.y, -theSun.z);
+	dotProduct = normalise(finalVector) * sunVector;
 
 	val = abs(dotProduct) / 16;
 	if (val == 0) val = 1;
You do not have the required permissions to view the files attached to this post.
Safety0ff
Trained
Trained
Posts: 397
Joined: 18 Jul 2009, 23:23

Re: Tile illumination for trunk

Post by Safety0ff »

Looks similar to what I have done in my work on graphics issues: https://github.com/Safety0ff/warzone210 ... 872e#L7L62
(There are many other changes in the branch so it doesn't look identical).

I don't think the screen shot to show the changes very well though, the big cliff to the left of your screen shots is much better as a example.
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Tile illumination for trunk

Post by Jorzi »

This has been bugging me for quite some time, good to know someone is working on it
ImageImage
-insert deep philosophical statement here-
User avatar
effigy
Regular
Regular
Posts: 1217
Joined: 22 Jan 2010, 03:21

Re: Tile illumination for trunk

Post by effigy »

Is this a related issue:
wz2100-20120130_211240-Sk-MizaMaze.jpg
Notice the row of mortor pit shadows on the cliff face.
You do not have the required permissions to view the files attached to this post.
This is why some features aren't implemented: http://forums.wz2100.net/viewtopic.php?f=30&t=7490&view=unread#p87241
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Tile illumination for trunk

Post by Jorzi »

It is somewhat related in that the cliff face should not be illuminated and therefore the shadows should be blending in with the shadowed cliff.
The shadow casting of units is also not without its problems. Thebest way would probably be to get it as a boolean/mask in the fragment shader, instead of drawing it on top of the already rendered scene.
ImageImage
-insert deep philosophical statement here-
i-NoD
Code contributor
Code contributor
Posts: 318
Joined: 30 Nov 2008, 00:42
Location: In the middle of nowhere

Re: Tile illumination for trunk

Post by i-NoD »

effigy wrote:Is this a related issue:
Notice the row of mortor pit shadows on the cliff face.
Yes, I guess if all shadows (from terrain and from models) were casted in the same direction then it wouldn't be THAT strange.
Safety0ff wrote:Looks similar to what I have done in my work on graphics issues: https://github.com/Safety0ff/warzone210 ... 872e#L7L62
(There are many other changes in the branch so it doesn't look identical).
I'm poking around gfxrebase branch and it looks like those changes results in too much light everywhere, almost no terrain shadows. Needs more tweaking :)
Safety0ff
Trained
Trained
Posts: 397
Joined: 18 Jul 2009, 23:23

Re: Tile illumination for trunk

Post by Safety0ff »

Yea, still a big work in progress, if it's just an amplitude problem then that's likely due to changing the "val" calculation. I'd have to re-review the code and changes to see actual issue was, but I think there was a mix in interpretation of the coordinate system the vector was stated in.
Safety0ff
Trained
Trained
Posts: 397
Joined: 18 Jul 2009, 23:23

Re: Tile illumination for trunk

Post by Safety0ff »

How does it look if you use swapYZ on either variable of the dot product? From looking at it again, I think this is the right solution.
EDIT: It might also need the Z component negated too since the current code still has that :stare:
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Tile illumination for trunk

Post by Jorzi »

By the way, how does the rendering currently work?
Seems like the terrain is first drawn using its own totally custom code, then the building bases are drawn using their own custom code. Then the features, units and buildings are drawn using shaders. Then the shadows are drawn on top of everything except that features don't cast them and bulding bases don't recieve them?
(I'm not saying this is anyone's fault :P )

Anyway, am I somewhat right or have I missed something? Also, if anyone could point out where in the code all this stuff is located I'd be thankful (I'm especially interested in the shadow casting)
ImageImage
-insert deep philosophical statement here-
User avatar
MaNGusT
Art contributor
Posts: 1154
Joined: 22 Sep 2006, 10:31
Location: Russia

Re: Tile illumination for trunk

Post by MaNGusT »

Jorzi wrote:Then the shadows are drawn on top of everything except that features don't cast them and bulding bases don't recieve them?
As someone noted this on irc, it is a bug because shadows render before building bases. :)
Image
i-NoD
Code contributor
Code contributor
Posts: 318
Joined: 30 Nov 2008, 00:42
Location: In the middle of nowhere

Re: Tile illumination for trunk

Post by i-NoD »

Jorzi wrote:By the way, how does the rendering currently work?
Seems like the terrain is first drawn using its own totally custom code, then the building bases are drawn using their own custom code. Then the features, units and buildings are drawn using shaders. Then the shadows are drawn on top of everything except that features don't cast them and bulding bases don't recieve them?
(I'm not saying this is anyone's fault :P )

Anyway, am I somewhat right or have I missed something? Also, if anyone could point out where in the code all this stuff is located I'd be thankful (I'm especially interested in the shadow casting)
Yup, two separated code paths for terrain and models (pretty much anything non-terrain). IIRC building bases are in models path too, but they are drawn with some blending mode that prevents shadows for them.

Shadow casting is done from here.
MaNGusT wrote:
Jorzi wrote:Then the shadows are drawn on top of everything except that features don't cast them and bulding bases don't recieve them?
As someone noted this on irc, it is a bug because shadows render before building bases. :)
I guess they draw in that order because of some issues with blending mode mentioned above...
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Tile illumination for trunk

Post by Jorzi »

Thanks for the link :)
I'm finally starting to get how this stuff works...
Btw, what is preventing the building bases from being drawn using shaders?
ImageImage
-insert deep philosophical statement here-
Cyp
Evitcani
Evitcani
Posts: 784
Joined: 17 Jan 2010, 23:35

Re: Tile illumination for trunk

Post by Cyp »

Aren't there shadows on baseplates since a4d518102079af2bb670c51ad5641b53e89e03b5?
Jorzi
Regular
Regular
Posts: 2063
Joined: 11 Apr 2010, 00:14

Re: Tile illumination for trunk

Post by Jorzi »

Hey, you're right :D
I opened the 3.1 version of warzone and the shadows were there :P
ImageImage
-insert deep philosophical statement here-
i-NoD
Code contributor
Code contributor
Posts: 318
Joined: 30 Nov 2008, 00:42
Location: In the middle of nowhere

Re: Tile illumination for trunk

Post by i-NoD »

:shok:
My bet they've hacked history while I was in the middle of 'Singin' in the Rain' movie... :read: