shadow (?) problem with skyx/hydrax integration

Lagger

07-08-2013 18:29:46

Hi,

I followed the HydraxSkyXDemo source to integrate both skyx and hydrax into my project but i'm encountering a problem.

During the day time the entire terrain turns red. And during the night well, the terrain doesn't go dark.



I believe this is a shadow problem but i don't know how to fix it, here is my code:
Shadow initialize
/** Set shadow mode
*/
void setShadowMode(Ogre::SceneManager *sm, const ShadowMode& smode)
{
Ogre::MaterialPtr TerrainMat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName("Terrain"));

if (mShadowConfigList[smode].Enable && !mForceDisableShadows)
{
sm->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED);
sm->setShadowTextureConfig(0, mShadowConfigList[smode].Size, mShadowConfigList[smode].Size, Ogre::PF_X8R8G8B8);
TerrainMat->getTechnique(0)->setSchemeName("Default");
TerrainMat->getTechnique(1)->setSchemeName("NoDefault");
}
else
{
sm->setShadowTechnique(Ogre::SHADOWTYPE_NONE);
TerrainMat->getTechnique(0)->setSchemeName("NoDefault");
TerrainMat->getTechnique(1)->setSchemeName("Default");
}
}


shadow gradients
class SkyXDemoFrameListener : public ExampleFrameListener
{
public:
SceneManager *mSceneMgr;
Real mKeyBuffer;
Real mLastPositionLength;

// Color gradients
SkyX::ColorGradient mWaterGradient,
mSunGradient,
mAmbientGradient;

SkyXDemoFrameListener(RenderWindow* win, Camera* cam, SceneManager *sm)
: ExampleFrameListener(win,cam)
, mSceneMgr(sm)
, mKeyBuffer(-1)
, mLastPositionLength((Ogre::Vector3(1500, 100, 1500) - mCamera->getDerivedPosition()).length())
{
// Color gradients
// Water
//mWaterGradient = SkyX::ColorGradient();
mWaterGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.058209,0.535822,0.779105)*0.4, 1));
mWaterGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.058209,0.535822,0.729105)*0.3, 0.8));
mWaterGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.058209,0.535822,0.679105)*0.25, 0.6));
mWaterGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.058209,0.535822,0.679105)*0.2, 0.5));
mWaterGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.058209,0.535822,0.679105)*0.1, 0.45));
mWaterGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.058209,0.535822,0.679105)*0.025, 0));
// Sun
//mSunGradient = SkyX::ColorGradient();
mSunGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.8,0.75,0.55)*1.5, 1.0f));
mSunGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.8,0.75,0.55)*1.4, 0.75f));
mSunGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.8,0.75,0.55)*1.3, 0.5625f));
mSunGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.6,0.5,0.2)*1.5, 0.5f));
mSunGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.5,0.5,0.5)*0.25, 0.45f));
mSunGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.5,0.5,0.5)*0.01, 0.0f));
// Ambient
//mAmbientGradient = SkyX::ColorGradient();
mAmbientGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(1,1,1)*1, 1.0f));
mAmbientGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(1,1,1)*1, 0.6f));
mAmbientGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(1,1,1)*0.6, 0.5f));
mAmbientGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(1,1,1)*0.3, 0.45f));
mAmbientGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(1,1,1)*0.1, 0.35f));
mAmbientGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(1,1,1)*0.05, 0.0f));
}
[...]

// Update environment lighting
updateEnvironmentLighting();

// Update shadow far distance
updateShadowFarDistance();

// Update Hydrax
mHydrax->update(e.timeSinceLastFrame);
//Update skyX
mSkyX->update(e.timeSinceLastFrame);

mKeyBuffer -= e.timeSinceLastFrame;

// Update terrain material
/*static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName("Terrain"))->getTechnique(0)->getPass(0)
->getFragmentProgramParameters()->setNamedConstant("uLightY", mBasicController->getSunDirection().y);
*/
return true;
}


Update lighting and shadows
/** Update environment lighting
*/
void updateEnvironmentLighting()
{
//Ogre::Vector3 lightDir = mSkyX->getAtmosphereManager()->getSunDirection();
Ogre::Vector3 lightDir = mSkyX->getController()->getSunDirection();

bool preForceDisableShadows = mForceDisableShadows;
mForceDisableShadows = (lightDir.y > 0.15f) ? true : false;

if (preForceDisableShadows != mForceDisableShadows)
{
setShadowMode(mSceneMgr, static_cast<ShadowMode>(mShadowMode));
}

// Calculate current color gradients point
//float point = (-lightDir.y + 1.0f) / 2.0f;
float point = (-lightDir.y) / 2.0f;
mHydrax->setWaterColor(mWaterGradient.getColor(point));

Ogre::Vector3 sunPos = mCamera->getDerivedPosition() - lightDir*mSkyX->getMeshManager()->getSkydomeRadius(mCamera)*0.1;
//Ogre::Vector3 sunPos = mCamera->getDerivedPosition() - lightDir*mSkyX->getSceneManager()->getSkyDomeGenParameters().skyDomeDistance*0.1;
mHydrax->setSunPosition(sunPos);



Ogre::Light *Light0 = mSceneMgr->getLight("Light0"),
*Light1 = mSceneMgr->getLight("Light1");

Light0->setPosition(mCamera->getDerivedPosition() - lightDir*mSkyX->getMeshManager()->getSkydomeRadius(mCamera)*0.02);
//Light0->setPosition(mCamera->getDerivedPosition() - lightDir*mSkyX->getSceneManager()->getSkyDomeGenParameters().skyDomeDistance*0.02);
Light1->setDirection(lightDir);

Ogre::Vector3 sunCol = mSunGradient.getColor(point);
Light0->setSpecularColour(sunCol.x, sunCol.y, sunCol.z);
Ogre::Vector3 ambientCol = mAmbientGradient.getColor(point);
Light0->setDiffuseColour(ambientCol.x, ambientCol.y, ambientCol.z);
mHydrax->setSunColor(sunCol);
}


/** Update shadow far distance
*/
void updateShadowFarDistance()
{
Ogre::Light* Light1 = mSceneMgr->getLight("Light1");
float currentLength = (Ogre::Vector3(1500, 100, 1500) - mCamera->getDerivedPosition()).length();

if (currentLength < 1000)
{
mLastPositionLength = currentLength;
return;
}

if (currentLength - mLastPositionLength > 100)
{
mLastPositionLength += 100;

Light1->setShadowFarDistance(Light1->getShadowFarDistance() + 100);
}
else if (currentLength - mLastPositionLength < -100)
{
mLastPositionLength -= 100;

Light1->setShadowFarDistance(Light1->getShadowFarDistance() - 100);
}
}

};


calling the shadows
class SampleApp : public ExampleApplication
{
public:
// Basic constructor
SampleApp()
{}

protected:
[...]
// Light
Ogre::Light *mLight0 = mSceneMgr->createLight("Light0");
mLight0->setDiffuseColour(1, 1, 1);
mLight0->setCastShadows(false);

// Shadow caster
Ogre::Light *mLight1 = mSceneMgr->createLight("Light1");
mLight1->setType(Ogre::Light::LT_DIRECTIONAL);
[...]

// Shadows
mSceneMgr->setShadowCameraSetup(Ogre::ShadowCameraSetupPtr(new Ogre::FocusedShadowCameraSetup()));
mSceneMgr->setShadowTextureCasterMaterial("ShadowCaster");
mSceneMgr->getLight("Light1")->setShadowFarDistance(1750);
setShadowMode(mSceneMgr, static_cast<ShadowMode>(mShadowMode));


If i disable the shadows though, the water becomes super bright :/


Any help would be very welcomed :)

Cheer,

Lagger

Lagger

10-08-2013 05:00:03

images don't show, here they are:

during the day:
http://imageshack.us/photo/my-images/19/p4wl.png/

during the night:
http://imageshack.us/photo/my-images/827/7v4d.png/

super bright water:
http://imageshack.us/photo/my-images/707/4j0h.png/

Lagger

24-09-2013 19:32:05

bump :/