ScatterSky source line endings fix

This commit is contained in:
DavidWyand-GG 2013-04-23 10:39:03 -04:00
parent 808f1a5beb
commit 78242191ec
2 changed files with 124 additions and 124 deletions

View file

@ -90,33 +90,33 @@ GFXImplementVertexFormat( ScatterSkyVertex )
} }
ScatterSky::ScatterSky() ScatterSky::ScatterSky()
{ {
mPrimCount = 0; mPrimCount = 0;
mVertCount = 0; mVertCount = 0;
// Rayleigh scattering constant. // Rayleigh scattering constant.
mRayleighScattering = 0.0035f; mRayleighScattering = 0.0035f;
mRayleighScattering4PI = mRayleighScattering * 4.0f * M_PI_F; mRayleighScattering4PI = mRayleighScattering * 4.0f * M_PI_F;
// Mie scattering constant. // Mie scattering constant.
mMieScattering = 0.0045f; mMieScattering = 0.0045f;
mMieScattering4PI = mMieScattering * 4.0f * M_PI_F; mMieScattering4PI = mMieScattering * 4.0f * M_PI_F;
// Overall scatter scalar. // Overall scatter scalar.
mSkyBrightness = 25.0f; mSkyBrightness = 25.0f;
// The Mie phase asymmetry factor. // The Mie phase asymmetry factor.
mMiePhaseAssymetry = -0.75f; mMiePhaseAssymetry = -0.75f;
mSphereInnerRadius = 1.0f; mSphereInnerRadius = 1.0f;
mSphereOuterRadius = 1.0f * 1.025f; mSphereOuterRadius = 1.0f * 1.025f;
mScale = 1.0f / (mSphereOuterRadius - mSphereInnerRadius); mScale = 1.0f / (mSphereOuterRadius - mSphereInnerRadius);
// 650 nm for red // 650 nm for red
// 570 nm for green // 570 nm for green
// 475 nm for blue // 475 nm for blue
mWavelength.set( 0.650f, 0.570f, 0.475f, 0 ); mWavelength.set( 0.650f, 0.570f, 0.475f, 0 );
mWavelength4[0] = mPow(mWavelength[0], 4.0f); mWavelength4[0] = mPow(mWavelength[0], 4.0f);
mWavelength4[1] = mPow(mWavelength[1], 4.0f); mWavelength4[1] = mPow(mWavelength[1], 4.0f);
@ -127,9 +127,9 @@ ScatterSky::ScatterSky()
mAmbientColor.set( 0, 0, 0, 1.0f ); mAmbientColor.set( 0, 0, 0, 1.0f );
mAmbientScale.set( 1.0f, 1.0f, 1.0f, 1.0f ); mAmbientScale.set( 1.0f, 1.0f, 1.0f, 1.0f );
mSunColor.set( 0, 0, 0, 1.0f ); mSunColor.set( 0, 0, 0, 1.0f );
mSunScale = ColorF::WHITE; mSunScale = ColorF::WHITE;
mFogColor.set( 0, 0, 0, 1.0f ); mFogColor.set( 0, 0, 0, 1.0f );
mFogScale = ColorF::WHITE; mFogScale = ColorF::WHITE;
@ -138,7 +138,7 @@ ScatterSky::ScatterSky()
mNightInterpolant = 0; mNightInterpolant = 0;
mShader = NULL; mShader = NULL;
mTimeOfDay = 0; mTimeOfDay = 0;
mSunAzimuth = 0.0f; mSunAzimuth = 0.0f;
@ -153,7 +153,7 @@ ScatterSky::ScatterSky()
mDirty = true; mDirty = true;
mLight = LightManager::createLightInfo(); mLight = LightManager::createLightInfo();
mLight->setType( LightInfo::Vector ); mLight->setType( LightInfo::Vector );
mFlareData = NULL; mFlareData = NULL;
mFlareState.clear(); mFlareState.clear();
@ -187,7 +187,7 @@ ScatterSky::ScatterSky()
ScatterSky::~ScatterSky() ScatterSky::~ScatterSky()
{ {
SAFE_DELETE( mLight ); SAFE_DELETE( mLight );
SAFE_DELETE( mMoonMatInst ); SAFE_DELETE( mMoonMatInst );
dFree_aligned(mMatrixSet); dFree_aligned(mMatrixSet);
@ -196,19 +196,20 @@ ScatterSky::~ScatterSky()
bool ScatterSky::onAdd() bool ScatterSky::onAdd()
{ {
PROFILE_SCOPE(ScatterSky_onAdd); PROFILE_SCOPE(ScatterSky_onAdd);
// onNewDatablock for the server is called here // onNewDatablock for the server is called here
// for the client it is called in unpackUpdate // for the client it is called in unpackUpdate
if ( !Parent::onAdd() ) if ( !Parent::onAdd() )
return false; return false;
if ( isClientObject() ) if ( isClientObject() )
TimeOfDay::getTimeOfDayUpdateSignal().notify( this, &ScatterSky::_updateTimeOfDay ); TimeOfDay::getTimeOfDayUpdateSignal().notify( this, &ScatterSky::_updateTimeOfDay );
setGlobalBounds(); setGlobalBounds();
resetWorldBox(); resetWorldBox();
addToScene(); addToScene();
if ( isClientObject() ) if ( isClientObject() )
{ {
@ -236,18 +237,18 @@ void ScatterSky::_conformLights()
F32 val = mCurves[0].getVal( mTimeOfDay ); F32 val = mCurves[0].getVal( mTimeOfDay );
mNightInterpolant = 1.0f - val; mNightInterpolant = 1.0f - val;
VectorF lightDirection; VectorF lightDirection;
F32 brightness; F32 brightness;
// Build the light direction from the azimuth and elevation. // Build the light direction from the azimuth and elevation.
F32 yaw = mDegToRad(mClampF(mSunAzimuth,0,359)); F32 yaw = mDegToRad(mClampF(mSunAzimuth,0,359));
F32 pitch = mDegToRad(mClampF(mSunElevation,-360,+360)); F32 pitch = mDegToRad(mClampF(mSunElevation,-360,+360));
MathUtils::getVectorFromAngles(lightDirection, yaw, pitch); MathUtils::getVectorFromAngles(lightDirection, yaw, pitch);
lightDirection.normalize(); lightDirection.normalize();
mSunDir = -lightDirection; mSunDir = -lightDirection;
yaw = mDegToRad(mClampF(mMoonAzimuth,0,359)); yaw = mDegToRad(mClampF(mMoonAzimuth,0,359));
pitch = mDegToRad(mClampF(mMoonElevation,-360,+360)); pitch = mDegToRad(mClampF(mMoonElevation,-360,+360));
MathUtils::getVectorFromAngles( mMoonLightDir, yaw, pitch ); MathUtils::getVectorFromAngles( mMoonLightDir, yaw, pitch );
mMoonLightDir.normalize(); mMoonLightDir.normalize();
mMoonLightDir = -mMoonLightDir; mMoonLightDir = -mMoonLightDir;
@ -255,12 +256,12 @@ void ScatterSky::_conformLights()
brightness = mCurves[2].getVal( mTimeOfDay ); brightness = mCurves[2].getVal( mTimeOfDay );
if ( mNightInterpolant >= 1.0f ) if ( mNightInterpolant >= 1.0f )
lightDirection = -mMoonLightDir; lightDirection = -mMoonLightDir;
mLight->setDirection( -lightDirection ); mLight->setDirection( -lightDirection );
mLight->setBrightness( brightness * mBrightness ); mLight->setBrightness( brightness * mBrightness );
mLightDir = lightDirection; mLightDir = lightDirection;
// Have to do interpolation // Have to do interpolation
// after the light direction is set // after the light direction is set
// otherwise the sun color will be invalid. // otherwise the sun color will be invalid.
@ -272,7 +273,7 @@ void ScatterSky::_conformLights()
FogData fog = getSceneManager()->getFogData(); FogData fog = getSceneManager()->getFogData();
fog.color = mFogColor; fog.color = mFogColor;
getSceneManager()->setFogData( fog ); getSceneManager()->setFogData( fog );
} }
void ScatterSky::submitLights( LightManager *lm, bool staticLighting ) void ScatterSky::submitLights( LightManager *lm, bool staticLighting )
@ -297,7 +298,7 @@ void ScatterSky::setAzimuth( F32 azimuth )
void ScatterSky::setElevation( F32 elevation ) void ScatterSky::setElevation( F32 elevation )
{ {
mSunElevation = elevation; mSunElevation = elevation;
while( elevation < 0 ) while( elevation < 0 )
elevation += 360.0f; elevation += 360.0f;
@ -317,7 +318,7 @@ void ScatterSky::inspectPostApply()
void ScatterSky::initPersistFields() void ScatterSky::initPersistFields()
{ {
addGroup( "ScatterSky", addGroup( "ScatterSky",
"Only azimuth and elevation are networked fields. To trigger a full update of all other fields use the applyChanges ConsoleMethod." ); "Only azimuth and elevation are networked fields. To trigger a full update of all other fields use the applyChanges ConsoleMethod." );
addField( "skyBrightness", TypeF32, Offset( mSkyBrightness, ScatterSky ), addField( "skyBrightness", TypeF32, Offset( mSkyBrightness, ScatterSky ),
@ -333,51 +334,51 @@ void ScatterSky::initPersistFields()
"Tints the sky the color specified, the alpha controls the brigthness. The brightness is multipled by the value of colorizeAmt." ); "Tints the sky the color specified, the alpha controls the brigthness. The brightness is multipled by the value of colorizeAmt." );
addField( "rayleighScattering", TypeF32, Offset( mRayleighScattering, ScatterSky ), addField( "rayleighScattering", TypeF32, Offset( mRayleighScattering, ScatterSky ),
"Controls how blue the atmosphere is during the day." ); "Controls how blue the atmosphere is during the day." );
addField( "sunScale", TypeColorF, Offset( mSunScale, ScatterSky ), addField( "sunScale", TypeColorF, Offset( mSunScale, ScatterSky ),
"Modulates the directional color of sunlight." ); "Modulates the directional color of sunlight." );
addField( "ambientScale", TypeColorF, Offset( mAmbientScale, ScatterSky ), addField( "ambientScale", TypeColorF, Offset( mAmbientScale, ScatterSky ),
"Modulates the ambient color of sunlight." ); "Modulates the ambient color of sunlight." );
addField( "fogScale", TypeColorF, Offset( mFogScale, ScatterSky ), addField( "fogScale", TypeColorF, Offset( mFogScale, ScatterSky ),
"Modulates the fog color. Note that this overrides the LevelInfo.fogColor " "Modulates the fog color. Note that this overrides the LevelInfo.fogColor "
"property, so you should not use LevelInfo.fogColor if the level contains " "property, so you should not use LevelInfo.fogColor if the level contains "
"a ScatterSky object." ); "a ScatterSky object." );
addField( "exposure", TypeF32, Offset( mExposure, ScatterSky ), addField( "exposure", TypeF32, Offset( mExposure, ScatterSky ),
"Controls the contrast of the sky and sun during daytime." ); "Controls the contrast of the sky and sun during daytime." );
endGroup( "ScatterSky" ); endGroup( "ScatterSky" );
addGroup( "Orbit" ); addGroup( "Orbit" );
addProtectedField( "azimuth", TypeF32, Offset( mSunAzimuth, ScatterSky ), &ScatterSky::ptSetAzimuth, &defaultProtectedGetFn, addProtectedField( "azimuth", TypeF32, Offset( mSunAzimuth, ScatterSky ), &ScatterSky::ptSetAzimuth, &defaultProtectedGetFn,
"The horizontal angle of the sun measured clockwise from the positive Y world axis. This field is networked." ); "The horizontal angle of the sun measured clockwise from the positive Y world axis. This field is networked." );
addProtectedField( "elevation", TypeF32, Offset( mSunElevation, ScatterSky ), &ScatterSky::ptSetElevation, &defaultProtectedGetFn, addProtectedField( "elevation", TypeF32, Offset( mSunElevation, ScatterSky ), &ScatterSky::ptSetElevation, &defaultProtectedGetFn,
"The elevation angle of the sun above or below the horizon. This field is networked." ); "The elevation angle of the sun above or below the horizon. This field is networked." );
addField( "moonAzimuth", TypeF32, Offset( mMoonAzimuth, ScatterSky ), addField( "moonAzimuth", TypeF32, Offset( mMoonAzimuth, ScatterSky ),
"The horizontal angle of the moon measured clockwise from the positive Y world axis. This is not animated by time or networked." ); "The horizontal angle of the moon measured clockwise from the positive Y world axis. This is not animated by time or networked." );
addField( "moonElevation", TypeF32, Offset( mMoonElevation, ScatterSky ), addField( "moonElevation", TypeF32, Offset( mMoonElevation, ScatterSky ),
"The elevation angle of the moon above or below the horizon. This is not animated by time or networked." ); "The elevation angle of the moon above or below the horizon. This is not animated by time or networked." );
endGroup( "Orbit" ); endGroup( "Orbit" );
// We only add the basic lighting options that all lighting // We only add the basic lighting options that all lighting
// systems would use... the specific lighting system options // systems would use... the specific lighting system options
// are injected at runtime by the lighting system itself. // are injected at runtime by the lighting system itself.
addGroup( "Lighting" ); addGroup( "Lighting" );
addField( "castShadows", TypeBool, Offset( mCastShadows, ScatterSky ), addField( "castShadows", TypeBool, Offset( mCastShadows, ScatterSky ),
"Enables/disables shadows cast by objects due to ScatterSky light." ); "Enables/disables shadows cast by objects due to ScatterSky light." );
addField( "brightness", TypeF32, Offset( mBrightness, ScatterSky ), addField( "brightness", TypeF32, Offset( mBrightness, ScatterSky ),
"The brightness of the ScatterSky's light object." ); "The brightness of the ScatterSky's light object." );
endGroup( "Lighting" ); endGroup( "Lighting" );
@ -395,33 +396,33 @@ void ScatterSky::initPersistFields()
addField( "nightColor", TypeColorF, Offset( mNightColor, ScatterSky ), addField( "nightColor", TypeColorF, Offset( mNightColor, ScatterSky ),
"The ambient color during night. Also used for the sky color if useNightCubemap is false." ); "The ambient color during night. Also used for the sky color if useNightCubemap is false." );
addField( "nightFogColor", TypeColorF, Offset( mNightFogColor, ScatterSky ), addField( "nightFogColor", TypeColorF, Offset( mNightFogColor, ScatterSky ),
"The fog color during night." ); "The fog color during night." );
addField( "moonEnabled", TypeBool, Offset( mMoonEnabled, ScatterSky ), addField( "moonEnabled", TypeBool, Offset( mMoonEnabled, ScatterSky ),
"Enable or disable rendering of the moon sprite during night." ); "Enable or disable rendering of the moon sprite during night." );
addField( "moonMat", TypeMaterialName, Offset( mMoonMatName, ScatterSky ), addField( "moonMat", TypeMaterialName, Offset( mMoonMatName, ScatterSky ),
"Material for the moon sprite." ); "Material for the moon sprite." );
addField( "moonScale", TypeF32, Offset( mMoonScale, ScatterSky ), addField( "moonScale", TypeF32, Offset( mMoonScale, ScatterSky ),
"Controls size the moon sprite renders, specified as a fractional amount of the screen height." ); "Controls size the moon sprite renders, specified as a fractional amount of the screen height." );
addField( "moonLightColor", TypeColorF, Offset( mMoonTint, ScatterSky ), addField( "moonLightColor", TypeColorF, Offset( mMoonTint, ScatterSky ),
"Color of light cast by the directional light during night." ); "Color of light cast by the directional light during night." );
addField( "useNightCubemap", TypeBool, Offset( mUseNightCubemap, ScatterSky ), addField( "useNightCubemap", TypeBool, Offset( mUseNightCubemap, ScatterSky ),
"Transition to the nightCubemap during night. If false we use nightColor." ); "Transition to the nightCubemap during night. If false we use nightColor." );
addField( "nightCubemap", TypeCubemapName, Offset( mNightCubemapName, ScatterSky ), addField( "nightCubemap", TypeCubemapName, Offset( mNightCubemapName, ScatterSky ),
"Cubemap visible during night." ); "Cubemap visible during night." );
endGroup( "Night" ); endGroup( "Night" );
// Now inject any light manager specific fields. // Now inject any light manager specific fields.
LightManager::initLightFields(); LightManager::initLightFields();
Parent::initPersistFields(); Parent::initPersistFields();
} }
@ -450,25 +451,25 @@ U32 ScatterSky::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
stream->write( mSunSize ); stream->write( mSunSize );
stream->write( mSkyBrightness ); stream->write( mSkyBrightness );
stream->write( mMiePhaseAssymetry ); stream->write( mMiePhaseAssymetry );
stream->write( mSphereInnerRadius ); stream->write( mSphereInnerRadius );
stream->write( mSphereOuterRadius ); stream->write( mSphereOuterRadius );
stream->write( mScale ); stream->write( mScale );
stream->write( mWavelength ); stream->write( mWavelength );
stream->write( mWavelength4[0] ); stream->write( mWavelength4[0] );
stream->write( mWavelength4[1] ); stream->write( mWavelength4[1] );
stream->write( mWavelength4[2] ); stream->write( mWavelength4[2] );
stream->write( mRayleighScaleDepth ); stream->write( mRayleighScaleDepth );
stream->write( mMieScaleDepth ); stream->write( mMieScaleDepth );
stream->write( mNightColor ); stream->write( mNightColor );
stream->write( mNightFogColor ); stream->write( mNightFogColor );
stream->write( mAmbientScale ); stream->write( mAmbientScale );
stream->write( mSunScale ); stream->write( mSunScale );
stream->write( mFogScale ); stream->write( mFogScale );
@ -486,7 +487,7 @@ U32 ScatterSky::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
if ( stream->writeFlag( mFlareData ) ) if ( stream->writeFlag( mFlareData ) )
{ {
stream->writeRangedU32( mFlareData->getId(), stream->writeRangedU32( mFlareData->getId(),
DataBlockObjectIdFirst, DataBlockObjectIdFirst,
DataBlockObjectIdLast ); DataBlockObjectIdLast );
} }
@ -500,7 +501,7 @@ U32 ScatterSky::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
stream->write( mMoonAzimuth ); stream->write( mMoonAzimuth );
stream->write( mMoonElevation ); stream->write( mMoonElevation );
mLight->packExtended( stream ); mLight->packExtended( stream );
} }
return retMask; return retMask;
@ -509,7 +510,7 @@ U32 ScatterSky::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
void ScatterSky::unpackUpdate(NetConnection *con, BitStream *stream) void ScatterSky::unpackUpdate(NetConnection *con, BitStream *stream)
{ {
Parent::unpackUpdate(con, stream); Parent::unpackUpdate(con, stream);
if ( stream->readFlag() ) // TimeMask if ( stream->readFlag() ) // TimeMask
{ {
F32 temp = 0; F32 temp = 0;
@ -531,27 +532,27 @@ void ScatterSky::unpackUpdate(NetConnection *con, BitStream *stream)
stream->read( &mSunSize ); stream->read( &mSunSize );
stream->read( &mSkyBrightness ); stream->read( &mSkyBrightness );
stream->read( &mMiePhaseAssymetry ); stream->read( &mMiePhaseAssymetry );
stream->read( &mSphereInnerRadius ); stream->read( &mSphereInnerRadius );
stream->read( &mSphereOuterRadius ); stream->read( &mSphereOuterRadius );
stream->read( &mScale ); stream->read( &mScale );
ColorF tmpColor( 0, 0, 0 ); ColorF tmpColor( 0, 0, 0 );
stream->read( &tmpColor ); stream->read( &tmpColor );
stream->read( &mWavelength4[0] ); stream->read( &mWavelength4[0] );
stream->read( &mWavelength4[1] ); stream->read( &mWavelength4[1] );
stream->read( &mWavelength4[2] ); stream->read( &mWavelength4[2] );
stream->read( &mRayleighScaleDepth ); stream->read( &mRayleighScaleDepth );
stream->read( &mMieScaleDepth ); stream->read( &mMieScaleDepth );
stream->read( &mNightColor ); stream->read( &mNightColor );
stream->read( &mNightFogColor ); stream->read( &mNightFogColor );
stream->read( &mAmbientScale ); stream->read( &mAmbientScale );
stream->read( &mSunScale ); stream->read( &mSunScale );
stream->read( &mFogScale ); stream->read( &mFogScale );
@ -584,7 +585,7 @@ void ScatterSky::unpackUpdate(NetConnection *con, BitStream *stream)
if ( stream->readFlag() ) if ( stream->readFlag() )
{ {
SimObjectId id = stream->readRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast ); SimObjectId id = stream->readRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast );
LightFlareData *datablock = NULL; LightFlareData *datablock = NULL;
if ( Sim::findObject( id, datablock ) ) if ( Sim::findObject( id, datablock ) )
@ -603,12 +604,12 @@ void ScatterSky::unpackUpdate(NetConnection *con, BitStream *stream)
stream->read( &mMoonScale ); stream->read( &mMoonScale );
stream->read( &mMoonTint ); stream->read( &mMoonTint );
mUseNightCubemap = stream->readFlag(); mUseNightCubemap = stream->readFlag();
stream->read( &mNightCubemapName ); stream->read( &mNightCubemapName );
stream->read( &mMoonAzimuth ); stream->read( &mMoonAzimuth );
stream->read( &mMoonElevation ); stream->read( &mMoonElevation );
mLight->unpackExtended( stream ); mLight->unpackExtended( stream );
if ( isProperlyAdded() ) if ( isProperlyAdded() )
{ {
@ -664,7 +665,7 @@ void ScatterSky::prepRenderImage( SceneRenderState *state )
if ( mNightInterpolant <= 0.0f ) if ( mNightInterpolant <= 0.0f )
return; return;
// Render instance for Moon sprite. // Render instance for Moon sprite.
if ( mMoonEnabled && mMoonMatInst ) if ( mMoonEnabled && mMoonMatInst )
{ {
mMatrixSet->setSceneView(GFX->getWorldMatrix()); mMatrixSet->setSceneView(GFX->getWorldMatrix());
@ -673,7 +674,7 @@ void ScatterSky::prepRenderImage( SceneRenderState *state )
ObjectRenderInst *ri = state->getRenderPass()->allocInst<ObjectRenderInst>(); ObjectRenderInst *ri = state->getRenderPass()->allocInst<ObjectRenderInst>();
ri->renderDelegate.bind( this, &ScatterSky::_renderMoon ); ri->renderDelegate.bind( this, &ScatterSky::_renderMoon );
ri->type = RenderPassManager::RIT_Sky; ri->type = RenderPassManager::RIT_Sky;
// Render after sky objects and before CloudLayer! // Render after sky objects and before CloudLayer!
ri->defaultKey = 5; ri->defaultKey = 5;
ri->defaultKey2 = 0; ri->defaultKey2 = 0;
@ -707,20 +708,20 @@ bool ScatterSky::_initShader()
mStateBlock = GFX->createStateBlock( data->getState() ); mStateBlock = GFX->createStateBlock( data->getState() );
} }
if ( !mStateBlock ) if ( !mStateBlock )
return false; return false;
mShaderConsts = mShader->allocConstBuffer(); mShaderConsts = mShader->allocConstBuffer();
mModelViewProjSC = mShader->getShaderConstHandle( "$modelView" ); mModelViewProjSC = mShader->getShaderConstHandle( "$modelView" );
// Camera height, cam height squared, scale and scale over depth. // Camera height, cam height squared, scale and scale over depth.
mMiscSC = mShader->getShaderConstHandle( "$misc" ); mMiscSC = mShader->getShaderConstHandle( "$misc" );
// Inner and out radius, and inner and outer radius squared. // Inner and out radius, and inner and outer radius squared.
mSphereRadiiSC = mShader->getShaderConstHandle( "$sphereRadii" ); mSphereRadiiSC = mShader->getShaderConstHandle( "$sphereRadii" );
// Rayleigh sun brightness, mie sun brightness and 4 * PI * coefficients. // Rayleigh sun brightness, mie sun brightness and 4 * PI * coefficients.
mScatteringCoefficientsSC = mShader->getShaderConstHandle( "$scatteringCoeffs" ); mScatteringCoefficientsSC = mShader->getShaderConstHandle( "$scatteringCoeffs" );
mCamPosSC = mShader->getShaderConstHandle( "$camPos" ); mCamPosSC = mShader->getShaderConstHandle( "$camPos" );
mLightDirSC = mShader->getShaderConstHandle( "$lightDir" ); mLightDirSC = mShader->getShaderConstHandle( "$lightDir" );
mSunDirSC = mShader->getShaderConstHandle( "$sunDir" ); mSunDirSC = mShader->getShaderConstHandle( "$sunDir" );
@ -744,9 +745,9 @@ void ScatterSky::_initVBIB()
Point3F vertScale( 16.0f, 16.0f, 4.0f ); Point3F vertScale( 16.0f, 16.0f, 4.0f );
F32 zOffset = -( mCos( mSqrt( 1.0f ) ) + 0.01f ); F32 zOffset = -( mCos( mSqrt( 1.0f ) ) + 0.01f );
mVB.set( GFX, mVertCount, GFXBufferTypeStatic ); mVB.set( GFX, mVertCount, GFXBufferTypeStatic );
ScatterSkyVertex *pVert = mVB.lock(); ScatterSkyVertex *pVert = mVB.lock();
for ( U32 y = 0; y < vertStride; y++ ) for ( U32 y = 0; y < vertStride; y++ )
{ {
@ -772,12 +773,12 @@ void ScatterSky::_initVBIB()
mVB.unlock(); mVB.unlock();
// Primitive Buffer... // Primitive Buffer...
mPrimBuffer.set( GFX, mPrimCount * 3, mPrimCount, GFXBufferTypeStatic ); mPrimBuffer.set( GFX, mPrimCount * 3, mPrimCount, GFXBufferTypeStatic );
U16 *pIdx = NULL; U16 *pIdx = NULL;
mPrimBuffer.lock(&pIdx); mPrimBuffer.lock(&pIdx);
U32 curIdx = 0; U32 curIdx = 0;
for ( U32 y = 0; y < strideMinusOne; y++ ) for ( U32 y = 0; y < strideMinusOne; y++ )
{ {
@ -801,7 +802,7 @@ void ScatterSky::_initVBIB()
} }
} }
mPrimBuffer.unlock(); mPrimBuffer.unlock();
} }
void ScatterSky::_initMoon() void ScatterSky::_initMoon()
@ -812,8 +813,8 @@ void ScatterSky::_initMoon()
if ( mMoonMatInst ) if ( mMoonMatInst )
SAFE_DELETE( mMoonMatInst ); SAFE_DELETE( mMoonMatInst );
if ( mMoonMatName.isNotEmpty() ) if ( mMoonMatName.isNotEmpty() )
mMoonMatInst = MATMGR->createMatInstance( mMoonMatName, MATMGR->getDefaultFeatures(), getGFXVertexFormat<GFXVertexPCT>() ); mMoonMatInst = MATMGR->createMatInstance( mMoonMatName, MATMGR->getDefaultFeatures(), getGFXVertexFormat<GFXVertexPCT>() );
} }
void ScatterSky::_initCurves() void ScatterSky::_initCurves()
@ -896,7 +897,6 @@ void ScatterSky::_initCurves()
mCurves[4].addPoint( 1.98001f, 0.5f ); mCurves[4].addPoint( 1.98001f, 0.5f );
mCurves[4].addPoint( 2.0f, 1.0f ); mCurves[4].addPoint( 2.0f, 1.0f );
} }
void ScatterSky::_updateTimeOfDay( TimeOfDay *timeOfDay, F32 time ) void ScatterSky::_updateTimeOfDay( TimeOfDay *timeOfDay, F32 time )
{ {
setElevation( timeOfDay->getElevationDegrees() ); setElevation( timeOfDay->getElevationDegrees() );
@ -922,12 +922,12 @@ void ScatterSky::_render( ObjectRenderInst *ri, SceneRenderState *state, BaseMat
Point4F scatteringCoeffs( mRayleighScattering * mSkyBrightness, mRayleighScattering4PI, Point4F scatteringCoeffs( mRayleighScattering * mSkyBrightness, mRayleighScattering4PI,
mMieScattering * mSkyBrightness, mMieScattering4PI ); mMieScattering * mSkyBrightness, mMieScattering4PI );
Point4F invWavelength( 1.0f / mWavelength4[0], Point4F invWavelength( 1.0f / mWavelength4[0],
1.0f / mWavelength4[1], 1.0f / mWavelength4[1],
1.0f / mWavelength4[2], 1.0f ); 1.0f / mWavelength4[2], 1.0f );
Point3F camPos( 0, 0, smViewerHeight ); Point3F camPos( 0, 0, smViewerHeight );
Point4F miscParams( camPos.z, camPos.z * camPos.z, mScale, mScale / mRayleighScaleDepth ); Point4F miscParams( camPos.z, camPos.z * camPos.z, mScale, mScale / mRayleighScaleDepth );
Frustum frust = state->getFrustum(); Frustum frust = state->getFrustum();
frust.setFarDist( smEarthRadius + smAtmosphereRadius ); frust.setFarDist( smEarthRadius + smAtmosphereRadius );
@ -937,7 +937,7 @@ void ScatterSky::_render( ObjectRenderInst *ri, SceneRenderState *state, BaseMat
Point3F camPos2 = state->getCameraPosition(); Point3F camPos2 = state->getCameraPosition();
MatrixF xfm(true); MatrixF xfm(true);
xfm.setPosition(camPos2);//-Point3F( 0, 0, 200000.0f)); xfm.setPosition(camPos2);//-Point3F( 0, 0, 200000.0f));
GFX->multWorld(xfm); GFX->multWorld(xfm);
MatrixF xform(proj);//GFX->getProjectionMatrix()); MatrixF xform(proj);//GFX->getProjectionMatrix());
xform *= GFX->getViewMatrix(); xform *= GFX->getViewMatrix();
xform *= GFX->getWorldMatrix(); xform *= GFX->getWorldMatrix();
@ -962,7 +962,7 @@ void ScatterSky::_render( ObjectRenderInst *ri, SceneRenderState *state, BaseMat
} }
else else
GFX->setStateBlock( mStateBlock ); GFX->setStateBlock( mStateBlock );
if ( mUseNightCubemap && mNightCubemap ) if ( mUseNightCubemap && mNightCubemap )
{ {
mShaderConsts->setSafe( mUseCubemapSC, 1.0f ); mShaderConsts->setSafe( mUseCubemapSC, 1.0f );
@ -970,11 +970,11 @@ void ScatterSky::_render( ObjectRenderInst *ri, SceneRenderState *state, BaseMat
if ( !mNightCubemap->mCubemap ) if ( !mNightCubemap->mCubemap )
mNightCubemap->createMap(); mNightCubemap->createMap();
GFX->setCubeTexture( 0, mNightCubemap->mCubemap ); GFX->setCubeTexture( 0, mNightCubemap->mCubemap );
} }
else else
{ {
GFX->setCubeTexture( 0, NULL ); GFX->setCubeTexture( 0, NULL );
mShaderConsts->setSafe( mUseCubemapSC, 0.0f ); mShaderConsts->setSafe( mUseCubemapSC, 0.0f );
} }
@ -1010,7 +1010,7 @@ void ScatterSky::_debugRender( ObjectRenderInst *ri, SceneRenderState *state, Ba
} }
void ScatterSky::_renderMoon( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat ) void ScatterSky::_renderMoon( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat )
{ {
if ( !mMoonMatInst ) if ( !mMoonMatInst )
return; return;
@ -1025,13 +1025,13 @@ void ScatterSky::_renderMoon( ObjectRenderInst *ri, SceneRenderState *state, Bas
F32 worldRadius = screenRadius * dist / state->getWorldToScreenScale().y; F32 worldRadius = screenRadius * dist / state->getWorldToScreenScale().y;
// Calculate Billboard Radius (in world units) to be constant, independent of distance. // Calculate Billboard Radius (in world units) to be constant, independent of distance.
// Takes into account distance, viewport size, and specified size in editor // Takes into account distance, viewport size, and specified size in editor
F32 BBRadius = worldRadius; F32 BBRadius = worldRadius;
mMatrixSet->restoreSceneViewProjection(); mMatrixSet->restoreSceneViewProjection();
if ( state->isReflectPass() ) if ( state->isReflectPass() )
mMatrixSet->setProjection( state->getSceneManager()->getNonClipProjection() ); mMatrixSet->setProjection( state->getSceneManager()->getNonClipProjection() );
@ -1044,16 +1044,16 @@ void ScatterSky::_renderMoon( ObjectRenderInst *ri, SceneRenderState *state, Bas
points[2] = Point3F( BBRadius, 0.0, BBRadius); points[2] = Point3F( BBRadius, 0.0, BBRadius);
points[3] = Point3F( BBRadius, 0.0, -BBRadius); points[3] = Point3F( BBRadius, 0.0, -BBRadius);
static const Point2F sCoords[4] = static const Point2F sCoords[4] =
{ {
Point2F( 0.0f, 0.0f ), Point2F( 0.0f, 0.0f ),
Point2F( 0.0f, 1.0f ), Point2F( 0.0f, 1.0f ),
Point2F( 1.0f, 1.0f ), Point2F( 1.0f, 1.0f ),
Point2F( 1.0f, 0.0f ) Point2F( 1.0f, 0.0f )
}; };
// Get info we need to adjust points // Get info we need to adjust points
const MatrixF &camView = state->getCameraTransform(); const MatrixF &camView = state->getCameraTransform();
// Finalize points // Finalize points
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
@ -1065,7 +1065,7 @@ void ScatterSky::_renderMoon( ObjectRenderInst *ri, SceneRenderState *state, Bas
} }
// Vertex color. // Vertex color.
ColorF moonVertColor( 1.0f, 1.0f, 1.0f, mNightInterpolant ); ColorF moonVertColor( 1.0f, 1.0f, 1.0f, mNightInterpolant );
// Copy points to buffer. // Copy points to buffer.
@ -1096,14 +1096,14 @@ void ScatterSky::_renderMoon( ObjectRenderInst *ri, SceneRenderState *state, Bas
mMoonMatInst->setTransforms( *mMatrixSet, state ); mMoonMatInst->setTransforms( *mMatrixSet, state );
mMoonMatInst->setSceneInfo( state, sgData ); mMoonMatInst->setSceneInfo( state, sgData );
GFX->setVertexBuffer( vb ); GFX->setVertexBuffer( vb );
GFX->drawPrimitive( GFXTriangleFan, 0, 2 ); GFX->drawPrimitive( GFXTriangleFan, 0, 2 );
} }
} }
void ScatterSky::_generateSkyPoints() void ScatterSky::_generateSkyPoints()
{ {
U32 rings=60, segments=20;//rings=160, segments=20; U32 rings=60, segments=20;//rings=160, segments=20;
Point3F tmpPoint( 0, 0, 0 ); Point3F tmpPoint( 0, 0, 0 );
@ -1115,7 +1115,7 @@ void ScatterSky::_generateSkyPoints()
for( int ring = 0; ring < 2; ring++ ) for( int ring = 0; ring < 2; ring++ )
{ {
F32 r0 = mSin( ring * deltaRingAngle ); F32 r0 = mSin( ring * deltaRingAngle );
F32 y0 = mCos( ring * deltaRingAngle ); F32 y0 = mCos( ring * deltaRingAngle );
// Generate the group of segments for the current ring. // Generate the group of segments for the current ring.
for( int seg = 0; seg < segments + 1 ; seg++ ) for( int seg = 0; seg < segments + 1 ; seg++ )
@ -1143,7 +1143,7 @@ void ScatterSky::_interpolateColors()
mAmbientColor.set( 0, 0, 0, 0 ); mAmbientColor.set( 0, 0, 0, 0 );
mSunColor.set( 0, 0, 0, 0 ); mSunColor.set( 0, 0, 0, 0 );
_getFogColor( &mFogColor ); _getFogColor( &mFogColor );
_getAmbientColor( &mAmbientColor ); _getAmbientColor( &mAmbientColor );
_getSunColor( &mSunColor ); _getSunColor( &mSunColor );
@ -1173,7 +1173,7 @@ void ScatterSky::_getSunColor( ColorF *outColor )
U32 count = 0; U32 count = 0;
ColorF tmpColor( 0, 0, 0 ); ColorF tmpColor( 0, 0, 0 );
VectorF tmpVec( 0, 0, 0 ); VectorF tmpVec( 0, 0, 0 );
tmpVec = mLightDir; tmpVec = mLightDir;
tmpVec.x *= smEarthRadius + smAtmosphereRadius; tmpVec.x *= smEarthRadius + smAtmosphereRadius;
tmpVec.y *= smEarthRadius + smAtmosphereRadius; tmpVec.y *= smEarthRadius + smAtmosphereRadius;
@ -1187,7 +1187,7 @@ void ScatterSky::_getSunColor( ColorF *outColor )
tmpVec.x += (smEarthRadius * 0.5f) + (smAtmosphereRadius * 0.5f); tmpVec.x += (smEarthRadius * 0.5f) + (smAtmosphereRadius * 0.5f);
count++; count++;
} }
if ( count > 0 ) if ( count > 0 )
(*outColor) /= count; (*outColor) /= count;
} }
@ -1267,7 +1267,7 @@ void ScatterSky::_getFogColor( ColorF *outColor )
F32 ScatterSky::_vernierScale( F32 fCos ) F32 ScatterSky::_vernierScale( F32 fCos )
{ {
F32 x = 1.0 - fCos; F32 x = 1.0 - fCos;
return 0.25f * exp( -0.00287f + x * (0.459f + x * (3.83f + x * ((-6.80f + (x * 5.25f))))) ); return 0.25f * exp( -0.00287f + x * (0.459f + x * (3.83f + x * ((-6.80f + (x * 5.25f))))) );
} }
F32 ScatterSky::_getMiePhase( F32 fCos, F32 fCos2, F32 g, F32 g2) F32 ScatterSky::_getMiePhase( F32 fCos, F32 fCos2, F32 g, F32 g2)
@ -1288,13 +1288,13 @@ void ScatterSky::_getColor( const Point3F &pos, ColorF *outColor )
F32 rayleighBrightness = mRayleighScattering * mSkyBrightness; F32 rayleighBrightness = mRayleighScattering * mSkyBrightness;
F32 mieBrightness = mMieScattering * mSkyBrightness; F32 mieBrightness = mMieScattering * mSkyBrightness;
Point3F invWaveLength( 1.0f / mWavelength4[0], Point3F invWaveLength( 1.0f / mWavelength4[0],
1.0f / mWavelength4[1], 1.0f / mWavelength4[1],
1.0f / mWavelength4[2] ); 1.0f / mWavelength4[2] );
Point3F v3Pos = pos / 6378000.0f; Point3F v3Pos = pos / 6378000.0f;
v3Pos.z += mSphereInnerRadius; v3Pos.z += mSphereInnerRadius;
Point3F newCamPos( 0, 0, smViewerHeight ); Point3F newCamPos( 0, 0, smViewerHeight );
VectorF v3Ray = v3Pos - newCamPos; VectorF v3Ray = v3Pos - newCamPos;
@ -1323,16 +1323,16 @@ void ScatterSky::_getColor( const Point3F &pos, ColorF *outColor )
F32 fScatter = (fStartOffset + fDepth * ( _vernierScale( fLightAngle ) - _vernierScale( fCameraAngle ) )); F32 fScatter = (fStartOffset + fDepth * ( _vernierScale( fLightAngle ) - _vernierScale( fCameraAngle ) ));
Point3F v3Attenuate( 0, 0, 0 ); Point3F v3Attenuate( 0, 0, 0 );
F32 tmp = mExp( -fScatter * (invWaveLength[0] * mRayleighScattering4PI + mMieScattering4PI) ); F32 tmp = mExp( -fScatter * (invWaveLength[0] * mRayleighScattering4PI + mMieScattering4PI) );
v3Attenuate.x = tmp; v3Attenuate.x = tmp;
tmp = mExp( -fScatter * (invWaveLength[1] * mRayleighScattering4PI + mMieScattering4PI) ); tmp = mExp( -fScatter * (invWaveLength[1] * mRayleighScattering4PI + mMieScattering4PI) );
v3Attenuate.y = tmp; v3Attenuate.y = tmp;
tmp = mExp( -fScatter * (invWaveLength[2] * mRayleighScattering4PI + mMieScattering4PI) ); tmp = mExp( -fScatter * (invWaveLength[2] * mRayleighScattering4PI + mMieScattering4PI) );
v3Attenuate.z = tmp; v3Attenuate.z = tmp;
v3FrontColor += v3Attenuate * (fDepth * fScaledLength); v3FrontColor += v3Attenuate * (fDepth * fScaledLength);
v3SamplePoint += v3SampleRay; v3SamplePoint += v3SampleRay;
} }
@ -1418,7 +1418,7 @@ void ScatterSky::_onUnselected()
// ConsoleMethods // ConsoleMethods
DefineEngineMethod( ScatterSky, applyChanges, void, (),, DefineEngineMethod( ScatterSky, applyChanges, void, (),,
"Apply a full network update of all fields to all clients." "Apply a full network update of all fields to all clients."
) )
{ {
object->inspectPostApply(); object->inspectPostApply();

View file

@ -133,7 +133,7 @@ protected:
void _getSunColor( ColorF *outColor ); void _getSunColor( ColorF *outColor );
void _interpolateColors(); void _interpolateColors();
void _conformLights(); void _conformLights();
void _updateTimeOfDay( TimeOfDay *timeofDay, F32 time ); void _updateTimeOfDay( TimeOfDay *timeofDay, F32 time );
@ -199,7 +199,7 @@ protected:
ColorF mSunColor; ///< Not a field ColorF mSunColor; ///< Not a field
ColorF mFogColor; ///< Not a field ColorF mFogColor; ///< Not a field
ColorF mAmbientScale; ColorF mAmbientScale;
ColorF mSunScale; ColorF mSunScale;
ColorF mFogScale; ColorF mFogScale;
@ -211,15 +211,15 @@ protected:
LightFlareData *mFlareData; LightFlareData *mFlareData;
LightFlareState mFlareState; LightFlareState mFlareState;
F32 mFlareScale; F32 mFlareScale;
bool mMoonEnabled; bool mMoonEnabled;
String mMoonMatName; String mMoonMatName;
BaseMatInstance *mMoonMatInst; BaseMatInstance *mMoonMatInst;
F32 mMoonScale; F32 mMoonScale;
ColorF mMoonTint; ColorF mMoonTint;
VectorF mMoonLightDir; VectorF mMoonLightDir;
CubemapData *mNightCubemap; CubemapData *mNightCubemap;
String mNightCubemapName; String mNightCubemapName;
bool mUseNightCubemap; bool mUseNightCubemap;
MatrixSet *mMatrixSet; MatrixSet *mMatrixSet;