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:
Areloch 2017-06-23 11:36:20 -05:00
parent 8943c673fb
commit 0801a3cca8
294 changed files with 3894 additions and 2813 deletions

View file

@ -266,7 +266,6 @@ void TerrainBaseMapFeatGLSL::processPix( Vector<ShaderComponent*> &componentLis
baseColor->setType( "vec4" );
baseColor->setName( "baseColor" );
meta->addStatement( new GenOp( " @ = tex2D( @, @.xy );\r\n", new DecOp( baseColor ), diffuseMap, texCoord ) );
meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", baseColor, baseColor));
ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
@ -574,7 +573,7 @@ void TerrainDetailMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
Var *normalMap = _getNormalMapTex();
// Call the library function to do the rest.
if (fd.features.hasFeature(MFT_IsDXTnm, detailIndex))
if (fd.features.hasFeature(MFT_IsBC3nm, detailIndex))
{
meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @.xy, @, @.z * @ );\r\n",
inDet, normalMap, inDet, negViewTS, detailInfo, detailBlend));

View file

@ -273,8 +273,6 @@ void TerrainBaseMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentLis
diffuseTex->constNum = diffuseMap->constNum;
meta->addStatement(new GenOp(" @ = @.Sample( @, @.xy );\r\n", new DecOp(baseColor), diffuseTex, diffuseMap, texCoord));
meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", baseColor, baseColor));
ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
if (fd.features.hasFeature(MFT_isDeferred))
@ -508,7 +506,7 @@ void TerrainDetailMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
}
// Call the library function to do the rest.
if (fd.features.hasFeature(MFT_IsDXTnm, detailIndex))
if (fd.features.hasFeature(MFT_IsBC3nm, detailIndex))
{
meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @, @.xy, @, @.z * @ );\r\n",
inDet, normalMapTex, normalMap, inDet, negViewTS, detailInfo, detailBlend));

View file

@ -1040,14 +1040,14 @@ void TerrCell::getRenderPrimitive( GFXPrimitive *prim,
void TerrCell::renderBounds() const
{
ColorI color;
LinearColorF color;
color.interpolate( ColorI::RED, ColorI::GREEN, (F32)mLevel / 3.0f );
GFXStateBlockDesc desc;
desc.setZReadWrite( true, false );
desc.fillMode = GFXFillWireframe;
GFX->getDrawUtil()->drawCube( desc, mBounds, color );
GFX->getDrawUtil()->drawCube( desc, mBounds, color.toColorI());
}
void TerrCell::preloadMaterials()

View file

@ -436,10 +436,13 @@ bool TerrainCellMaterial::_createPass( Vector<MaterialInfo*> *materials,
features.addFeature( MFT_TerrainNormalMap, featureIndex );
normalMaps.last().set( mat->getNormalMap(),
&GFXDefaultStaticNormalMapProfile, "TerrainCellMaterial::_createPass() - NormalMap" );
&GFXNormalMapProfile, "TerrainCellMaterial::_createPass() - NormalMap" );
if ( normalMaps.last().getFormat() == GFXFormatDXT5 )
features.addFeature( MFT_IsDXTnm, featureIndex );
GFXFormat normalFmt = normalMaps.last().getFormat();
if ( normalFmt == GFXFormatBC3 )
features.addFeature( MFT_IsBC3nm, featureIndex );
else if ( normalFmt == GFXFormatBC5)
features.addFeature( MFT_IsBC5nm, featureIndex);
// Do we need and can we do parallax mapping?
if ( !disableParallaxMaps &&
@ -610,7 +613,7 @@ bool TerrainCellMaterial::_createPass( Vector<MaterialInfo*> *materials,
desc.samplers[sampler].minFilter = GFXTextureFilterLinear;
matInfo->detailTex.set( matInfo->mat->getDetailMap(),
&GFXDefaultStaticDiffuseProfile, "TerrainCellMaterial::_createPass() - DetailMap" );
&GFXStaticTextureProfile, "TerrainCellMaterial::_createPass() - DetailMap" );
}
matInfo->macroInfoVConst = pass->shader->getShaderConstHandle( avar( "$macroScaleAndFade%d", i ) );
@ -634,7 +637,7 @@ bool TerrainCellMaterial::_createPass( Vector<MaterialInfo*> *materials,
desc.samplers[sampler].minFilter = GFXTextureFilterLinear;
matInfo->macroTex.set( matInfo->mat->getMacroMap(),
&GFXDefaultStaticDiffuseProfile, "TerrainCellMaterial::_createPass() - MacroMap" );
&GFXStaticTextureProfile, "TerrainCellMaterial::_createPass() - MacroMap" );
}
//end macro texture

View file

@ -176,7 +176,6 @@ ImplementEnumType(baseTexFormat,
{ TerrainBlock::NONE, "NONE", "No cached terrain.\n" },
{ TerrainBlock::DDS, "DDS", "Cache the terrain in a DDS format.\n" },
{ TerrainBlock::PNG, "PNG", "Cache the terrain in a PNG format.\n" },
{ TerrainBlock::JPG, "JPG", "Cache the terrain in a JPG format.\n" },
EndImplementEnumType;
TerrainBlock::TerrainBlock()
@ -189,7 +188,7 @@ TerrainBlock::TerrainBlock()
mDetailsDirty( false ),
mLayerTexDirty( false ),
mBaseTexSize( 1024 ),
mBaseTexFormat( TerrainBlock::JPG ),
mBaseTexFormat( TerrainBlock::DDS ),
mCell( NULL ),
mBaseMaterial( NULL ),
mDefaultMatInst( NULL ),
@ -873,7 +872,7 @@ GFXTextureObject* TerrainBlock::getLightMapTex()
if ( mLightMapTex.isNull() && mLightMap )
{
mLightMapTex.set( mLightMap,
&GFXDefaultStaticDiffuseProfile,
&GFXStaticTextureProfile,
false,
"TerrainBlock::getLightMapTex()" );
}
@ -966,7 +965,7 @@ bool TerrainBlock::onAdd()
_updateBaseTexture( true );
// The base texture should have been cached by now... so load it.
mBaseTex.set( baseCachePath, &GFXDefaultStaticDiffuseProfile, "TerrainBlock::mBaseTex" );
mBaseTex.set( baseCachePath, &GFXStaticTextureSRGBProfile, "TerrainBlock::mBaseTex" );
GFXTextureManager::addEventDelegate( this, &TerrainBlock::_onTextureEvent );
MATMGR->getFlushSignal().notify( this, &TerrainBlock::_onFlushMaterials );

View file

@ -78,7 +78,7 @@ public:
enum BaseTexFormat
{
NONE, DDS, PNG, JPG
NONE, DDS, PNG
};
static const char* formatToExtension(BaseTexFormat format)
@ -89,8 +89,6 @@ public:
return "dds";
case PNG:
return "png";
case JPG:
return "jpg";
default:
return "";
}

View file

@ -457,7 +457,7 @@ void TerrainFile::_loadLegacy( FileStream &stream )
if ( materials[i].isEmpty() )
continue;
terrainMat.set( materials[i], &GFXDefaultPersistentProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) );
terrainMat.set( materials[i], &GFXTexturePersistentSRGBProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) );
if ( terrainMat )
continue;
@ -470,7 +470,7 @@ void TerrainFile::_loadLegacy( FileStream &stream )
{
matRelPath.setPath( String(Con::getVariable( "$defaultGame" )) + path.substr( n, path.length() - n ) );
terrainMat.set( matRelPath, &GFXDefaultPersistentProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) );
terrainMat.set( matRelPath, &GFXTexturePersistentSRGBProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ) );
if ( terrainMat )
{
materials[i] = matRelPath.getFullPath();

View file

@ -48,7 +48,7 @@
#include "gfx/gfxTransformSaver.h"
#include "gfx/bitmap/gBitmap.h"
#include "gfx/bitmap/ddsFile.h"
#include "gfx/bitmap/ddsUtils.h"
#include "gfx/bitmap/imageUtils.h"
#include "terrain/terrMaterial.h"
#include "gfx/gfxDebugEvent.h"
#include "gfx/gfxCardProfile.h"
@ -83,10 +83,11 @@ void TerrainBlock::_updateMaterials()
{
TerrainMaterial *mat = mFile->mMaterials[i];
if( !mat->getDiffuseMap().isEmpty() )
mBaseTextures[i].set( mat->getDiffuseMap(),
&GFXDefaultStaticDiffuseProfile,
"TerrainBlock::_updateMaterials() - DiffuseMap" );
if (!mat->getDiffuseMap().isEmpty())
{
mBaseTextures[i].set(mat->getDiffuseMap(), &GFXStaticTextureSRGBProfile,
"TerrainBlock::_updateMaterials() - DiffuseMap");
}
else
mBaseTextures[ i ] = GFXTexHandle();
@ -232,12 +233,12 @@ void TerrainBlock::_updateBaseTexture(bool writeToCache)
// use it to render to else we create one.
if ( mBaseTex.isValid() &&
mBaseTex->isRenderTarget() &&
mBaseTex->getFormat() == GFXFormatR8G8B8A8 &&
mBaseTex->getFormat() == GFXFormatR8G8B8A8_SRGB &&
mBaseTex->getWidth() == destSize.x &&
mBaseTex->getHeight() == destSize.y )
blendTex = mBaseTex;
else
blendTex.set( destSize.x, destSize.y, GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, "" );
blendTex.set( destSize.x, destSize.y, GFXFormatR8G8B8A8_SRGB, &GFXRenderTargetSRGBProfile, "" );
GFX->pushActiveRenderTarget();
@ -324,7 +325,7 @@ void TerrainBlock::_updateBaseTexture(bool writeToCache)
blendBmp.extrudeMipLevels();
DDSFile *blendDDS = DDSFile::createDDSFileFromGBitmap( &blendBmp );
DDSUtil::squishDDS( blendDDS, GFXFormatDXT1 );
ImageUtil::ddsCompress( blendDDS, GFXFormatBC1 );
// Write result to file stream
blendDDS->write( fs );
@ -342,7 +343,7 @@ void TerrainBlock::_updateBaseTexture(bool writeToCache)
return;
}
GBitmap bitmap(blendTex->getWidth(), blendTex->getHeight(), false, GFXFormatR8G8B8);
GBitmap bitmap(blendTex->getWidth(), blendTex->getHeight(), false, GFXFormatR8G8B8A8);
blendTex->copyToBmp(&bitmap);
bitmap.writeBitmap(formatToExtension(mBaseTexFormat), stream);
}