Dynamic Sun

Dynamic Sun

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Dynamic Sun

Post by Beherith »

Sorry for the long post, but I got latest master to compile in VS 2005, but ran into 2 issues that I needed to fix for it to work:
In

Code: Select all

void CFeatureDrawer::DrawFadeFeaturesSet(std::set<CFeature*>& fadeFeatures, int modelType)
{
	for (std::set<CFeature*>::const_iterator fi = fadeFeatures.begin(); fi != fadeFeatures.end(); ) {
		std::set<CFeature*>::const_iterator fiNext(fi); ++fiNext;
I had to change it to a non const iterator for it to compile:

Code: Select all

void CFeatureDrawer::DrawFadeFeaturesSet(std::set<CFeature*>& fadeFeatures, int modelType)
{
	for (std::set<CFeature*>::iterator fi = fadeFeatures.begin(); fi != fadeFeatures.end(); ) {
		std::set<CFeature*>::iterator fiNext(fi); ++fiNext;
And in ./include/al/efx.h I had to change all

Code: Select all

typedef void (AL_APIENTRY *LPALGENEFFECTS)(ALsizei, ALuint*);
to

Code: Select all

typedef void (ALAPIENTRY *LPALGENEFFECTS)(ALsizei, ALuint*);

I loaded it up, and found this great new feature, dynamic sun :)
I dont mean to drop the bomb on this, but could you share how I can give parameters to this? Because most of my maps rely heavily on pre-baked lighting, and I would like to configure this to suit them more.

Also, I found numerous other rendering bugs, and would like to ask if I should share these, or are they known to you as well? Like the minimap getting corrupted, grass texture issues, and lighting level issues.

Thank you devs for your hard work on giving us great new features!
zerver
Spring Developer
Posts: 1358
Joined: 16 Dec 2006, 20:59

Re: Dynamic Sun

Post by zerver »

Add a fourth parameter to the "sunDir" in the map info (x,y,z,sunDist). "sunOrbitTime" (in seconds) and "sunStartAngle" (in radians) can also be set. The sun normally starts at the peak elevation point, but e.g. sunStartAngle = PI would make it start at the lowest elevation point.

x,y,z is the axis of rotation for the orbit and sunDist is the distance from the origin to the center of the orbit. So, for a sun that passes through zenith (x,0,z,0) so that x^2+z^2=1^2

For a sun at a constant elevation (0,1,0,sunDist), 0<sunDist<1. Note that a sun too near the horizon currently has zero brightness so cannot be seen.

To change settings at runtime:

Code: Select all

Spring.SetSunParameters(x,y,z,sunDist,sunStartAngle,sunOrbitTime)
Or use completely manual control:

Code: Select all

Spring.SetSunManualControl(true)
Spring.SetSunDirection(x,y,z)
Does it fail? Well it is all untested :)
User avatar
KaiserJ
Community Representative
Posts: 3113
Joined: 08 Sep 2008, 22:59

Re: Dynamic Sun

Post by KaiserJ »

8)

awesome
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Dynamic Sun

Post by Forboding Angel »

Oh hells yes! Excellent work!
User avatar
manolo_
Posts: 1370
Joined: 01 Jul 2008, 00:08

Re: Dynamic Sun

Post by manolo_ »

will this effect the shadows of the map (hills,...)? because i thought that they are fixed
zerver
Spring Developer
Posts: 1358
Joined: 16 Dec 2006, 20:59

Re: Dynamic Sun

Post by zerver »

Correct. Some maps have fixed shadows, and will not look very good if the sun direction is changed.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Dynamic Sun

Post by Forboding Angel »

@manolo, for maps that have the shadows literally baked in it won't look very good (very few maps do this tho). For the ones that have baked preshading (which is most of the high quality maps), it's possible that at certain points it might look a little odd, but I doubt it will be so noticeable that it will make a difference to the player. They are all going to be shitting themselves about dynamic sunlight to notice :-) And in the future, mapmakers will simply be not baking preshading, so while it "could" be an issue of sorts, it is one that will resolve itself.
User avatar
KaiserJ
Community Representative
Posts: 3113
Joined: 08 Sep 2008, 22:59

Re: Dynamic Sun

Post by KaiserJ »

easy enough to an ambient bake rather than a directional shadowed one; im sure combined with ssmf it will look far superior to anything that exists ATM
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Dynamic Sun

Post by knorke »

/shadows 2 turns off terrain shadows, guess you will still be able to do that on maps with pre baked shadows.
User avatar
Floris
Posts: 611
Joined: 04 Jan 2011, 20:00

Re: Dynamic Sun

Post by Floris »

Oh great, then also implement a feature to let the teams swap sides.
I mean the team with the sun in their back has the advantage right?

:o)
zerver
Spring Developer
Posts: 1358
Joined: 16 Dec 2006, 20:59

Re: Dynamic Sun

Post by zerver »

And team1 cannot jeffyspam because the wind is too strong. Luckily team2 had some lightning strike their advfus to even things out a bit.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Dynamic Sun

Post by jK »

Beherith wrote:And in ./include/al/efx.h I had to change all

Code: Select all

typedef void (AL_APIENTRY *LPALGENEFFECTS)(ALsizei, ALuint*);
to

Code: Select all

typedef void (ALAPIENTRY *LPALGENEFFECTS)(ALsizei, ALuint*);
ALAPIENTRY is deprecated in OpenAL1.1, so update your OpenAL headers.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Dynamic Sun

Post by Forboding Angel »

knorke wrote:/shadows 2 turns off terrain shadows, guess you will still be able to do that on maps with pre baked shadows.
Knorke... Prebaked shadows means that the shadow is burned into the texture. As a result, using /shadows 2 would do nothing.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: Dynamic Sun

Post by FLOZi »

I think he was meaning 'turn off engine shadows if they look funky on old maps'
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Dynamic Sun

Post by Forboding Angel »

Wouldn't this take the place of the engine shadows?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Dynamic Sun

Post by knorke »

if i understand correctly, those are the engine shadows just updated with a new feature.
I think he was meaning 'turn off engine shadows if they look funky on old maps'
yup.
So if you have some old map with shadows drawn onto the terrain, it might be better to switch engine terrain shadows off so that you do not get double shadows, possible pointing in different directions.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Dynamic Sun

Post by Forboding Angel »

Ahh ok. YOur wording was a bit funky.
User avatar
Johannes
Posts: 1265
Joined: 17 Sep 2010, 15:49

Re: Dynamic Sun

Post by Johannes »

So how can this be turned off, for a map with shadows on the texture? SunOrbitTime=something?
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Dynamic Sun

Post by Forboding Angel »

I believe this post answers your question (read all the way through to the end and it'll make sense).
zerver wrote:Add a fourth parameter to the "sunDir" in the map info (x,y,z,sunDist). "sunOrbitTime" (in seconds) and "sunStartAngle" (in radians) can also be set. The sun normally starts at the peak elevation point, but e.g. sunStartAngle = PI would make it start at the lowest elevation point.

x,y,z is the axis of rotation for the orbit and sunDist is the distance from the origin to the center of the orbit. So, for a sun that passes through zenith (x,0,z,0) so that x^2+z^2=1^2

For a sun at a constant elevation (0,1,0,sunDist), 0<sunDist<1. Note that a sun too near the horizon currently has zero brightness so cannot be seen.

To change settings at runtime:

Code: Select all

Spring.SetSunParameters(x,y,z,sunDist,sunStartAngle,sunOrbitTime)
Or use completely manual control:

Code: Select all

Spring.SetSunManualControl(true)
Spring.SetSunDirection(x,y,z)
Does it fail? Well it is all untested :)
zerver
Spring Developer
Posts: 1358
Joined: 16 Dec 2006, 20:59

Re: Dynamic Sun

Post by zerver »

jK wrote:ALAPIENTRY is deprecated in OpenAL1.1, so update your OpenAL headers.
https://github.com/downloads/spring/spr ... libs-v8.7z
Post Reply

Return to “Engine”