Using SkyX with Ogre::Terrain

Darkeye

01-07-2010 07:39:19

Hola Xavi!

I am trying to implement your great library with Ogre official terrain.
I am using the code from the terrain basic tutorial (3rd) and I have modified the light to have the same position and direction of the SkyX's sun, updated every frame.

Doing that is almost ready, but some shadows still remain in the terrain.
Better an image :D


As you can see in the first image, those shadows never disappear, and I don't know why, in the second those shadows seems no to disturb so much.

And I've got two more curious effects, in the third, you can notice how some areas of the terrain still have light while the sun have already gone, they get dark slower than normal, but in the end, they are updated ok.

And since I added SkyX, I have noticed that only the area around you get updated for the light, is there any option to tweak this? I want it only a bit further, since I plan to add some trees ;)

By the way, I've posted here the code related to SkyX in my app: http://pastebin.com/vAN2C2ZE

Saludos y gracias Xavi, espero no haberte aburrido mucho xD :wink:

Xavyiy

04-07-2010 11:26:09

Hi! =)

About the official Ogre 1.7 terrain, I've to say that I've never use it - I'll start with it in some months, in the Paradise Engine -, so I'm only going to reply you from my experience, but maybe I'm totally wrong!

As you can see in the first image, those shadows never disappear, and I don't know why, in the second those shadows seems no to disturb so much.If these shadows are always on the terrain, for any light direction, maybe is some kind of non-realtime shadows generated by the terrain plugin.

But if these shadowed parts aren't static, but even if the light direction is (0,-1,0) are always visible, then it might be some kind of bug or rendering artifact in the terrain material, or maybe the terrain uses a kind of light where the light position is taken account (LT_POINT, LT_) and you've to set the sun position relative the some kind of terrain origin, in other words:
SkyX::AtmosphereManager::getSunPosition() (is queals to) = mCamera::derivedPosition - mSunDir*SkyDomeRadius;
but maybe the terrain only needs:
sunPosition = -mSunDir*SkyDomeRadius;
(Or something like that, because from your first, it seems that there's a little offset between the casted shadows and where them must appear, if in this screenshot the sun is at the top sky position)

Of course, all of that are only speculations, I think you should ask that at the Ogre terrain thread, or in the Help forum.

And I've got two more curious effects, in the third, you can notice how some areas of the terrain still have light while the sun have already gone, they get dark slower than normal, but in the end, they are updated ok.I think you should apply some kind of non-linear relation between the sun y-coord and your light colour, something like:
sun_light->setDiffuseColour(Ogre::ColourValue::White*std::clamp<Ogre::Real>(Ogre::Math::Pow(-SkyXSunDirection.y, 0.25)*2, 0.2, 1));
That basically keeps your sun light diffuse colour near to pure WHITE during the day, and changes it to a dark colour during the sunset/sunrise, you can control the max/min difusse colour values with the std::clamp function(as far as I remember the Ogre::Math class doesn't implement the clamp method), in the example case it's between [0.2, 1]*Colour::White.
With these kind of little hacks I think you can avoid these little light artefacts at the sunset.

(Of course, you can make a more elaborated trick, even changing the light direction to just the opposite during the night(SunDirection.y > 0) with a dark light difusse colour to simulate the moon (in skyx the moon and the sun are always in oposite directions from the camera, so if the sun is at (0,-Radius,0) the moon is at (0, Radius, 0) ) light in the terrain)

And since I added SkyX, I have noticed that only the area around you get updated for the light, is there any option to tweak this? I want it only a bit further, since I plan to add some trees If you say that, then it seems that the terrain materials care about the sun position too, so try to update the light position with:
sun_light->setPosition(mCamera->_getDerivedPosition() - mSkyX->getAtmosphereManager()->getSunDirection()*mCamera->getFarClipDistance()*0.5f); And see if the light area is increased.

Hope some of these words can help you!

Xavi

Darkeye

04-07-2010 14:22:15

Thank you very much Xavi!

For the moment problem #1 is solved, it seems that the file (X.dat) that Ogre::Terrain saves includes a lightmap and this file was generated some time ago, when testing the terrain system, and when the light was in a different position. :oops: :oops:

So deleting that file and setting the light dir to (0, -1, 0) until it gets the Sun dir, solved the problem of the persistent shadows.

I am trying to implement the rest, I will keep you informed. :D

nevarim

26-08-2013 18:24:41

better with hydrax included :D