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 8780f83262
commit 25686ed4be
294 changed files with 3894 additions and 2813 deletions

View file

@ -59,16 +59,16 @@ ColladaAppMaterial::ColladaAppMaterial(const char* matName)
flags |= TSMaterialList::S_Wrap;
flags |= TSMaterialList::T_Wrap;
diffuseColor = ColorF::ONE;
specularColor = ColorF::ONE;
diffuseColor = LinearColorF::ONE;
specularColor = LinearColorF::ONE;
specularPower = 8.0f;
doubleSided = false;
}
ColladaAppMaterial::ColladaAppMaterial(const domMaterial *pMat)
: mat(pMat),
diffuseColor(ColorF::ONE),
specularColor(ColorF::ONE),
diffuseColor(LinearColorF::ONE),
specularColor(LinearColorF::ONE),
specularPower(8.0f),
doubleSided(false)
{
@ -174,7 +174,7 @@ void ColladaAppMaterial::resolveFloat(const domCommon_float_or_param_type* value
}
}
void ColladaAppMaterial::resolveColor(const domCommon_color_or_texture_type* value, ColorF* dst)
void ColladaAppMaterial::resolveColor(const domCommon_color_or_texture_type* value, LinearColorF* dst)
{
if (value && value->getColor()) {
dst->red = value->getColor()->getValue()[0];

View file

@ -44,8 +44,8 @@ public:
String diffuseMap;
String normalMap;
String specularMap;
ColorF diffuseColor;
ColorF specularColor;
LinearColorF diffuseColor;
LinearColorF specularColor;
F32 specularPower;
bool doubleSided;
@ -56,7 +56,7 @@ public:
String getName() const { return name; }
void resolveFloat(const domCommon_float_or_param_type* value, F32* dst);
void resolveColor(const domCommon_color_or_texture_type* value, ColorF* dst);
void resolveColor(const domCommon_color_or_texture_type* value, LinearColorF* dst);
// Determine the material transparency
template<class T> void resolveTransparency(const T shader, F32* dst)
@ -66,7 +66,7 @@ public:
resolveFloat(shader->getTransparency(), dst);
// Multiply the transparency by the transparent color
ColorF transColor(1.0f, 1.0f, 1.0f, 1.0f);
LinearColorF transColor(1.0f, 1.0f, 1.0f, 1.0f);
if (shader->getTransparent() && shader->getTransparent()->getColor()) {
const domCommon_color_or_texture_type::domColor* color = shader->getTransparent()->getColor();
transColor.set(color->getValue()[0], color->getValue()[1], color->getValue()[2], color->getValue()[3]);

View file

@ -878,7 +878,11 @@ void ColladaAppMesh::getMorphVertexData(const domMorph* morph, F32 time, const M
}
if (colors_array) {
for (S32 iVert = 0; iVert < vertTuples.size(); iVert++)
colors_array[iVert] += targetColors[iVert] * (F32)targetWeights[iTarget];
{
LinearColorF tCol = colors_array[iVert];
tCol += LinearColorF(targetColors[iVert]) * (F32)targetWeights[iTarget];
colors_array[iVert] = tCol.toColorI();
}
}
}
}

View file

@ -35,7 +35,7 @@
// Collada <light> elements are very similar, but are arranged as separate, unrelated
// classes. These template functions are used to provide a simple way to access the
// common elements.
template<class T> static void resolveLightColor(T* light, ColorF& color)
template<class T> static void resolveLightColor(T* light, LinearColorF& color)
{
if (light->getColor())
{
@ -80,7 +80,7 @@ static void processNodeLights(AppNode* appNode, const MatrixF& offset, SimGroup*
}
LightBase* pLight = 0;
ColorF color(ColorF::WHITE);
LinearColorF color(LinearColorF::WHITE);
Point3F attenuation(0, 1, 1);
if (technique->getAmbient()) {

View file

@ -31,7 +31,7 @@
#include "renderInstance/renderImposterMgr.h"
#include "gfx/gfxTransformSaver.h"
#include "gfx/bitmap/ddsFile.h"
#include "gfx/bitmap/ddsUtils.h"
#include "gfx/bitmap/imageUtils.h"
#include "gfx/gfxTextureManager.h"
#include "math/mRandom.h"
#include "core/stream/fileStream.h"
@ -240,12 +240,12 @@ void TSLastDetail::update( bool forceUpdate )
// Get the diffuse texture and from its size and
// the imposter dimensions we can generate the UVs.
GFXTexHandle diffuseTex( diffuseMapPath, &GFXDefaultStaticDiffuseProfile, String::EmptyString );
GFXTexHandle diffuseTex( diffuseMapPath, &GFXStaticTextureSRGBProfile, String::EmptyString );
Point2I texSize( diffuseTex->getWidth(), diffuseTex->getHeight() );
_validateDim();
S32 downscaledDim = mDim >> GFXTextureManager::getTextureDownscalePower(&GFXDefaultStaticDiffuseProfile);
S32 downscaledDim = mDim >> GFXTextureManager::getTextureDownscalePower(&GFXStaticTextureSRGBProfile);
// Ok... pack in bitmaps till we run out.
Vector<RectF> imposterUVs;
@ -482,14 +482,14 @@ void TSLastDetail::_update()
// DEBUG: Some code to force usage of a test image.
//GBitmap* tempMap = GBitmap::load( "./forest/data/test1234.png" );
//tempMap->extrudeMipLevels();
//mTexture.set( tempMap, &GFXDefaultStaticDiffuseProfile, false );
//mTexture.set( tempMap, &GFXStaticTextureSRGBProfile, false );
//delete tempMap;
DDSFile *ddsDest = DDSFile::createDDSFileFromGBitmap( &destBmp );
DDSUtil::squishDDS( ddsDest, GFXFormatDXT3 );
ImageUtil::ddsCompress( ddsDest, GFXFormatBC2 );
DDSFile *ddsNormals = DDSFile::createDDSFileFromGBitmap( &destNormal );
DDSUtil::squishDDS( ddsNormals, GFXFormatDXT5 );
ImageUtil::ddsCompress( ddsNormals, GFXFormatBC3 );
// Finally save the imposters to disk.
FileStream fs;

View file

@ -291,12 +291,12 @@ bool TSMaterialList::renameMaterial(U32 i, const String& newName)
GFXTexHandle texHandle;
if (mLookupPath.isEmpty())
{
texHandle.set( newName, &GFXDefaultStaticDiffuseProfile, avar("%s() - handle (line %d)", __FUNCTION__, __LINE__) );
texHandle.set( newName, &GFXStaticTextureSRGBProfile, avar("%s() - handle (line %d)", __FUNCTION__, __LINE__) );
}
else
{
String fullPath = String::ToString( "%s/%s", mLookupPath.c_str(), newName.c_str() );
texHandle.set( fullPath, &GFXDefaultStaticDiffuseProfile, avar("%s() - handle (line %d)", __FUNCTION__, __LINE__) );
texHandle.set( fullPath, &GFXStaticTextureSRGBProfile, avar("%s() - handle (line %d)", __FUNCTION__, __LINE__) );
}
if (!texHandle.isValid())
return false;