mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-02 20:10:32 +00:00
Implementation of sRGB image support. Overhauls the linearization setup to utilize the sRGB image types, as well as refactors the use of ColorF and ColorI to be properly internally consistent. ColorIs are used only for front-facing/editing/UI settings, and ColorFs, now renamed to LinearColorF to reduce confusion of purpose, are used for color info in the engine itself. This avoids confusing and expensive conversions back and forth between types and avoids botches with linearity. Majority work done by @rextimmy
This commit is contained in:
parent
8780f83262
commit
25686ed4be
294 changed files with 3894 additions and 2813 deletions
|
|
@ -645,7 +645,7 @@ void AdvancedLightBinManager::LightMaterialInfo::setLightParameters( const Light
|
|||
MaterialParameters *matParams = matInstance->getMaterialParameters();
|
||||
|
||||
// Set color in the right format, set alpha to the luminance value for the color.
|
||||
ColorF col = lightInfo->getColor();
|
||||
LinearColorF col = lightInfo->getColor();
|
||||
|
||||
// TODO: The specularity control of the light
|
||||
// is being scaled by the overall lumiance.
|
||||
|
|
@ -658,7 +658,7 @@ void AdvancedLightBinManager::LightMaterialInfo::setLightParameters( const Light
|
|||
F32 lumiance = mDot(*((const Point3F *)&lightInfo->getColor()), colorToLumiance );
|
||||
col.alpha *= lumiance;
|
||||
|
||||
matParams->setSafe( lightColor, col.toLinear() );
|
||||
matParams->setSafe( lightColor, col );
|
||||
matParams->setSafe( lightBrightness, lightInfo->getBrightness() );
|
||||
|
||||
switch( lightInfo->getType() )
|
||||
|
|
@ -672,9 +672,9 @@ void AdvancedLightBinManager::LightMaterialInfo::setLightParameters( const Light
|
|||
|
||||
// Set small number for alpha since it represents existing specular in
|
||||
// the vector light. This prevents a divide by zero.
|
||||
ColorF ambientColor = renderState->getAmbientLightColor();
|
||||
LinearColorF ambientColor = renderState->getAmbientLightColor();
|
||||
ambientColor.alpha = 0.00001f;
|
||||
matParams->setSafe( lightAmbient, ambientColor.toLinear() );
|
||||
matParams->setSafe( lightAmbient, ambientColor );
|
||||
|
||||
// If no alt color is specified, set it to the average of
|
||||
// the ambient and main color to avoid artifacts.
|
||||
|
|
@ -682,13 +682,13 @@ void AdvancedLightBinManager::LightMaterialInfo::setLightParameters( const Light
|
|||
// TODO: Trilight disabled until we properly implement it
|
||||
// in the light info!
|
||||
//
|
||||
//ColorF lightAlt = lightInfo->getAltColor();
|
||||
ColorF lightAlt( ColorF::BLACK ); // = lightInfo->getAltColor();
|
||||
//LinearColorF lightAlt = lightInfo->getAltColor();
|
||||
LinearColorF lightAlt( LinearColorF::BLACK ); // = lightInfo->getAltColor();
|
||||
if ( lightAlt.red == 0.0f && lightAlt.green == 0.0f && lightAlt.blue == 0.0f )
|
||||
lightAlt = (lightInfo->getColor() + renderState->getAmbientLightColor()) / 2.0f;
|
||||
|
||||
ColorF trilightColor = lightAlt;
|
||||
matParams->setSafe(lightTrilight, trilightColor.toLinear());
|
||||
LinearColorF trilightColor = lightAlt;
|
||||
matParams->setSafe(lightTrilight, trilightColor);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -787,7 +787,7 @@ bool LightMatInstance::setupPass( SceneRenderState *state, const SceneData &sgDa
|
|||
getMaterialParameters()->set( mLightMapParamsSC, lmParams->shadowDarkenColor );
|
||||
}
|
||||
else
|
||||
getMaterialParameters()->set( mLightMapParamsSC, ColorF::WHITE );
|
||||
getMaterialParameters()->set( mLightMapParamsSC, LinearColorF::WHITE );
|
||||
}
|
||||
|
||||
// Now override stateblock with our own
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ bool AdvancedLightManager::isCompatible() const
|
|||
|
||||
// TODO: Test for the necessary texture formats!
|
||||
bool autoMips;
|
||||
if(!GFX->getCardProfiler()->checkFormat(GFXFormatR16F, &GFXDefaultRenderTargetProfile, autoMips))
|
||||
if(!GFX->getCardProfiler()->checkFormat(GFXFormatR16F, &GFXRenderTargetProfile, autoMips))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -106,7 +106,7 @@ void AdvancedLightManager::activate( SceneManager *sceneManager )
|
|||
Vector<GFXFormat> formats;
|
||||
formats.push_back( GFXFormatR16G16B16A16F );
|
||||
//formats.push_back( GFXFormatR16G16B16A16 );
|
||||
GFXFormat blendTargetFormat = GFX->selectSupportedFormat( &GFXDefaultRenderTargetProfile,
|
||||
GFXFormat blendTargetFormat = GFX->selectSupportedFormat( &GFXRenderTargetProfile,
|
||||
formats,
|
||||
true,
|
||||
true,
|
||||
|
|
|
|||
|
|
@ -249,11 +249,7 @@ Var* GBufferConditionerGLSL::printMethodHeader( MethodType methodType, const Str
|
|||
|
||||
// The gbuffer has no mipmaps, so use tex2dlod when
|
||||
// possible so that the shader compiler can optimize.
|
||||
meta->addStatement( new GenOp( " #if TORQUE_SM >= 30\r\n" ) );
|
||||
meta->addStatement( new GenOp( " @ = tex2Dlod(@, float4(@,0,0));\r\n", bufferSampleDecl, deferredSampler, screenUV ) );
|
||||
meta->addStatement( new GenOp( " #else\r\n" ) );
|
||||
meta->addStatement( new GenOp( " @ = tex2D(@, @);\r\n", bufferSampleDecl, deferredSampler, screenUV ) );
|
||||
meta->addStatement( new GenOp( " #endif\r\n\r\n" ) );
|
||||
meta->addStatement( new GenOp( "@ = tex2Dlod(@, float4(@,0,0));\r\n", bufferSampleDecl, deferredSampler, screenUV ) );
|
||||
|
||||
// We don't use this way of passing var's around, so this should cause a crash
|
||||
// if something uses this improperly
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ protected:
|
|||
|
||||
BitVector mShadowMask;
|
||||
ShadowVolumeBSP * mShadowVolume;
|
||||
ColorF * mLightmap;
|
||||
LinearColorF * mLightmap;
|
||||
|
||||
/// The dimension of the lightmap in pixels.
|
||||
const U32 mLightMapSize;
|
||||
|
|
@ -104,7 +104,7 @@ protected:
|
|||
/// The dimension of the terrain height map sample array.
|
||||
const U32 mTerrainBlockSize;
|
||||
|
||||
ColorF *sgBakedLightmap;
|
||||
LinearColorF *sgBakedLightmap;
|
||||
Vector<LightInfo *> sgLights;
|
||||
bool sgMarkStaticShadow(void *terrainproxy, SceneObject *sceneobject, LightInfo *light);
|
||||
//void postLight(bool lastLight);
|
||||
|
|
@ -122,7 +122,7 @@ protected:
|
|||
bool markObjectShadow(ObjectProxy *);
|
||||
bool sgIsCorrectStaticObjectType(SceneObject *obj);
|
||||
|
||||
inline ColorF _getValue( S32 row, S32 column );
|
||||
inline LinearColorF _getValue( S32 row, S32 column );
|
||||
|
||||
public:
|
||||
|
||||
|
|
@ -173,8 +173,8 @@ blTerrainProxy::~blTerrainProxy()
|
|||
//-------------------------------------------------------------------------------
|
||||
void blTerrainProxy::init()
|
||||
{
|
||||
mLightmap = new ColorF[ mLightMapSize * mLightMapSize ];
|
||||
dMemset(mLightmap, 0, mLightMapSize * mLightMapSize * sizeof(ColorF));
|
||||
mLightmap = new LinearColorF[ mLightMapSize * mLightMapSize ];
|
||||
dMemset(mLightmap, 0, mLightMapSize * mLightMapSize * sizeof(LinearColorF));
|
||||
mShadowMask.setSize( mTerrainBlockSize * mTerrainBlockSize );
|
||||
}
|
||||
|
||||
|
|
@ -190,7 +190,7 @@ bool blTerrainProxy::preLight(LightInfo * light)
|
|||
return(true);
|
||||
}
|
||||
|
||||
inline ColorF blTerrainProxy::_getValue( S32 row, S32 column )
|
||||
inline LinearColorF blTerrainProxy::_getValue( S32 row, S32 column )
|
||||
{
|
||||
while( row < 0 )
|
||||
row += mLightMapSize;
|
||||
|
|
@ -282,7 +282,7 @@ void blTerrainProxy::light(LightInfo * light)
|
|||
for( U32 j=0; j < mLightMapSize; j++ )
|
||||
{
|
||||
|
||||
ColorF val;
|
||||
LinearColorF val;
|
||||
val = _getValue( i-1, j-1 ) * kernel[0][0];
|
||||
val += _getValue( i-1, j ) * kernel[0][1];
|
||||
val += _getValue( i-1, j+1 ) * kernel[0][2];
|
||||
|
|
@ -583,7 +583,7 @@ void blTerrainProxy::lightVector(LightInfo * light)
|
|||
}
|
||||
|
||||
// Set the final lightmap color.
|
||||
mLightmap[i++] += ColorF::WHITE * mClampF( 1.0f - shadowed, 0.0f, 1.0f );
|
||||
mLightmap[i++] += LinearColorF::WHITE * mClampF( 1.0f - shadowed, 0.0f, 1.0f );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -688,7 +688,7 @@ bool blTerrainSystem::createPersistChunkFromProxy(SceneLighting::ObjectProxy* ob
|
|||
}
|
||||
|
||||
// Given a ray, this will return the color from the lightmap of this object, return true if handled
|
||||
bool blTerrainSystem::getColorFromRayInfo(const RayInfo & collision, ColorF& result) const
|
||||
bool blTerrainSystem::getColorFromRayInfo(const RayInfo & collision, LinearColorF& result) const
|
||||
{
|
||||
TerrainBlock *terrain = dynamic_cast<TerrainBlock *>(collision.object);
|
||||
if (!terrain)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public:
|
|||
virtual bool createPersistChunkFromProxy(SceneLighting::ObjectProxy* objproxy, PersistInfo::PersistChunk **ret);
|
||||
|
||||
// Given a ray, this will return the color from the lightmap of this object, return true if handled
|
||||
virtual bool getColorFromRayInfo(const RayInfo & collision, ColorF& result) const;
|
||||
virtual bool getColorFromRayInfo(const RayInfo & collision, LinearColorF& result) const;
|
||||
};
|
||||
|
||||
#endif // !_BLTERRAINSYSTEM_H_
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ void BlobShadow::generateGenericShadowBitmap(S32 dim)
|
|||
}
|
||||
}
|
||||
|
||||
smGenericShadowTexture.set( bitmap, &GFXDefaultStaticDiffuseProfile, true, "BlobShadow" );
|
||||
smGenericShadowTexture.set( bitmap, &GFXStaticTextureSRGBProfile, true, "BlobShadow" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public:
|
|||
// for console protected fields.
|
||||
|
||||
bool representedInLightmap; ///< This light is represented in lightmaps (static light, default: false)
|
||||
ColorF shadowDarkenColor; ///< The color that should be used to multiply-blend dynamic shadows onto lightmapped geometry (ignored if 'representedInLightmap' is false)
|
||||
LinearColorF shadowDarkenColor; ///< The color that should be used to multiply-blend dynamic shadows onto lightmapped geometry (ignored if 'representedInLightmap' is false)
|
||||
bool includeLightmappedGeometryInShadow; ///< This light should render lightmapped geometry during its shadow-map update (ignored if 'representedInLightmap' is false)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -115,11 +115,11 @@ protected:
|
|||
Type mType;
|
||||
|
||||
/// The primary light color.
|
||||
ColorF mColor;
|
||||
LinearColorF mColor;
|
||||
|
||||
F32 mBrightness;
|
||||
|
||||
ColorF mAmbient;
|
||||
LinearColorF mAmbient;
|
||||
|
||||
MatrixF mTransform;
|
||||
|
||||
|
|
@ -172,14 +172,14 @@ public:
|
|||
VectorF getDirection() const { return mTransform.getForwardVector(); }
|
||||
void setDirection( const VectorF &val );
|
||||
|
||||
const ColorF& getColor() const { return mColor; }
|
||||
void setColor( const ColorF &val ) { mColor = val; }
|
||||
const LinearColorF& getColor() const { return mColor; }
|
||||
void setColor( const LinearColorF &val ) { mColor = val; }
|
||||
|
||||
F32 getBrightness() const { return mBrightness; }
|
||||
void setBrightness( F32 val ) { mBrightness = val; }
|
||||
|
||||
const ColorF& getAmbient() const { return mAmbient; }
|
||||
void setAmbient( const ColorF &val ) { mAmbient = val; }
|
||||
const LinearColorF& getAmbient() const { return mAmbient; }
|
||||
void setAmbient( const LinearColorF &val ) { mAmbient = val; }
|
||||
|
||||
const Point3F& getRange() const { return mRange; }
|
||||
void setRange( const Point3F &range ) { mRange = range; }
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ public:
|
|||
// Runtime / dynamic methods
|
||||
//
|
||||
// Given a ray, this will return the color from the lightmap of this object, return true if handled
|
||||
virtual bool getColorFromRayInfo(const RayInfo & collision, ColorF& result) const { return false; }
|
||||
virtual bool getColorFromRayInfo(const RayInfo & collision, LinearColorF& result) const { return false; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -210,18 +210,18 @@ void LightShadowMap::calcLightMatrices( MatrixF &outLightMatrix, const Frustum &
|
|||
//SceneManager::setVisibleDistance(width * 2.0f);
|
||||
|
||||
#if 0
|
||||
DebugDrawer::get()->drawFrustum(viewFrustum, ColorF(1.0f, 0.0f, 0.0f));
|
||||
DebugDrawer::get()->drawBox(viewBB.minExtents, viewBB.maxExtents, ColorF(0.0f, 1.0f, 0.0f));
|
||||
DebugDrawer::get()->drawBox(lightViewBB.minExtents, lightViewBB.maxExtents, ColorF(0.0f, 0.0f, 1.0f));
|
||||
DebugDrawer::get()->drawBox(newLightPos - Point3F(1,1,1), newLightPos + Point3F(1,1,1), ColorF(1,1,0));
|
||||
DebugDrawer::get()->drawLine(newLightPos, newLightPos + mLight.mDirection*3.0f, ColorF(0,1,1));
|
||||
DebugDrawer::get()->drawFrustum(viewFrustum, LinearColorF(1.0f, 0.0f, 0.0f));
|
||||
DebugDrawer::get()->drawBox(viewBB.minExtents, viewBB.maxExtents, LinearColorF(0.0f, 1.0f, 0.0f));
|
||||
DebugDrawer::get()->drawBox(lightViewBB.minExtents, lightViewBB.maxExtents, LinearColorF(0.0f, 0.0f, 1.0f));
|
||||
DebugDrawer::get()->drawBox(newLightPos - Point3F(1,1,1), newLightPos + Point3F(1,1,1), LinearColorF(1,1,0));
|
||||
DebugDrawer::get()->drawLine(newLightPos, newLightPos + mLight.mDirection*3.0f, LinearColorF(0,1,1));
|
||||
|
||||
Point3F a(newLightPos);
|
||||
Point3F b(newLightPos);
|
||||
Point3F offset(width, height,0.0f);
|
||||
a -= offset;
|
||||
b += offset;
|
||||
DebugDrawer::get()->drawBox(a, b, ColorF(0.5f, 0.5f, 0.5f));
|
||||
DebugDrawer::get()->drawBox(a, b, LinearColorF(0.5f, 0.5f, 0.5f));
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
|
@ -719,7 +719,7 @@ GFXTextureObject* ShadowMapParams::getCookieTex()
|
|||
cookie != mCookieTex->getPath() ) )
|
||||
{
|
||||
mCookieTex.set( cookie,
|
||||
&GFXDefaultStaticDiffuseProfile,
|
||||
&GFXStaticTextureSRGBProfile,
|
||||
"ShadowMapParams::getCookieTex()" );
|
||||
}
|
||||
else if ( cookie.isEmpty() )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue