diffuse/albedo texture linearization

http://http.developer.nvidia.com/GPUGems3/gpugems3_ch24.html
This commit is contained in:
Azaezel 2015-11-11 13:52:46 -06:00
parent 51b6469922
commit ce2964d2d0
31 changed files with 396 additions and 107 deletions

View file

@ -105,7 +105,7 @@ void AdvancedLightManager::activate( SceneManager *sceneManager )
// we prefer the floating point format if it works.
Vector<GFXFormat> formats;
formats.push_back( GFXFormatR16G16B16A16F );
formats.push_back( GFXFormatR16G16B16A16 );
//formats.push_back( GFXFormatR16G16B16A16 );
GFXFormat blendTargetFormat = GFX->selectSupportedFormat( &GFXDefaultRenderTargetProfile,
formats,
true,

View file

@ -46,6 +46,7 @@ ImplementFeatureType( MFT_AlphaTest, MFG_Texture, 7.0f, true );
ImplementFeatureType( MFT_SpecularMap, MFG_Texture, 8.0f, true );
ImplementFeatureType( MFT_NormalMap, MFG_Texture, 9.0f, true );
ImplementFeatureType( MFT_DetailNormalMap, MFG_Texture, 10.0f, true );
ImplementFeatureType( MFT_Imposter, U32(-1), -1, true );
ImplementFeatureType( MFT_AccuMap, MFG_PreLighting, 2.0f, true );

View file

@ -94,6 +94,7 @@ DeclareFeatureType( MFT_OverlayMap );
DeclareFeatureType( MFT_DetailMap );
DeclareFeatureType( MFT_DiffuseColor );
DeclareFeatureType( MFT_DetailNormalMap );
DeclareFeatureType( MFT_Imposter );
DeclareFeatureType( MFT_AccuMap );
DeclareFeatureType( MFT_AccuScale );

View file

@ -144,6 +144,8 @@ void AccuTexFeatGLSL::processPix(Vector<ShaderComponent*> &componentList,
// get the accu pixel color
meta->addStatement( new GenOp( " @ = tex2D(@, @ * @);\r\n", colorAccuDecl, accuMap, inTex, accuScale ) );
if (!fd.features[MFT_Imposter])
meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", accuColor, accuColor));
// scale up normals
meta->addStatement( new GenOp( " @.xyz = @.xyz * 2.0 - 0.5;\r\n", bumpNorm, bumpNorm ) );

View file

@ -828,6 +828,12 @@ Var* ShaderFeatureGLSL::addOutDetailTexCoord( Vector<ShaderComponent*> &compon
// Base Texture
//****************************************************************************
DiffuseMapFeatGLSL::DiffuseMapFeatGLSL()
: mTorqueDep("shaders/common/gl/torque.glsl")
{
addDependency(&mTorqueDep);
}
void DiffuseMapFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
@ -855,20 +861,23 @@ void DiffuseMapFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
diffuseMap->sampler = true;
diffuseMap->constNum = Var::getTexUnitNum(); // used as texture unit num here
// create sample color var
Var *diffColor = new Var;
diffColor->setType("vec4");
diffColor->setName("diffuseColor");
LangElement *colorDecl = new DecOp( diffColor );
MultiLine * meta = new MultiLine;
output = meta;
if ( fd.features[MFT_CubeMap] )
{
MultiLine * meta = new MultiLine;
// create sample color
Var *diffColor = new Var;
diffColor->setType( "vec4" );
diffColor->setName( "diffuseColor" );
LangElement *colorDecl = new DecOp( diffColor );
meta->addStatement( new GenOp( " @ = tex2D(@, @);\r\n",
colorDecl,
diffuseMap,
inTex ) );
if (!fd.features[MFT_Imposter])
meta->addStatement( new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor) );
meta->addStatement( new GenOp( " @;\r\n", assignColor( diffColor, Material::Mul ) ) );
output = meta;
@ -877,8 +886,6 @@ void DiffuseMapFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
{
// Handle atlased textures
// http://www.infinity-universe.com/Infinity/index.php?option=com_content&task=view&id=65&Itemid=47
MultiLine * meta = new MultiLine;
output = meta;
Var *atlasedTex = new Var;
atlasedTex->setName("atlasedTexCoord");
@ -934,11 +941,6 @@ void DiffuseMapFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
// For the rest of the feature...
inTex = atlasedTex;
// create sample color var
Var *diffColor = new Var;
diffColor->setType("vec4");
diffColor->setName("diffuseColor");
// To dump out UV coords...
//#define DEBUG_ATLASED_UV_COORDS
#ifdef DEBUG_ATLASED_UV_COORDS
@ -954,21 +956,26 @@ void DiffuseMapFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
{
meta->addStatement(new GenOp( " @ = tex2Dlod(@, float4(@, 0.0, mipLod));\r\n",
new DecOp(diffColor), diffuseMap, inTex));
if (!fd.features[MFT_Imposter])
meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor));
}
else
{
meta->addStatement(new GenOp( " @ = tex2D(@, @);\r\n",
new DecOp(diffColor), diffuseMap, inTex));
if (!fd.features[MFT_Imposter])
meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor));
}
meta->addStatement(new GenOp( " @;\r\n", assignColor(diffColor, Material::Mul)));
}
else
{
LangElement *statement = new GenOp( "tex2D(@, @)", diffuseMap, inTex );
output = new GenOp( " @;\r\n", assignColor( statement, Material::Mul ) );
meta->addStatement(new GenOp("@ = tex2D(@, @);\r\n", colorDecl, diffuseMap, inTex));
if (!fd.features[MFT_Imposter])
meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor));
meta->addStatement(new GenOp(" @;\r\n", assignColor(diffColor, Material::Mul)));
}
}
ShaderFeature::Resources DiffuseMapFeatGLSL::getResources( const MaterialFeatureData &fd )

View file

@ -236,7 +236,12 @@ public:
/// Base texture
class DiffuseMapFeatGLSL : public ShaderFeatureGLSL
{
protected:
ShaderIncludeDependency mTorqueDep;
public:
DiffuseMapFeatGLSL();
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );

View file

@ -68,6 +68,7 @@ void _initShaderGenGLSL( ShaderGen *shaderGen )
FEATUREMGR->registerFeature( MFT_IsTranslucent, new NamedFeatureGLSL( "Translucent" ) );
FEATUREMGR->registerFeature( MFT_Visibility, new VisibilityFeatGLSL );
FEATUREMGR->registerFeature( MFT_Fog, new FogFeatGLSL );
FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureGLSL( "Imposter" ) );
FEATUREMGR->registerFeature( MFT_NormalsOut, new NormalsOutFeatGLSL );

View file

@ -141,6 +141,8 @@ void AccuTexFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
// get the accu pixel color
meta->addStatement( new GenOp( " @ = tex2D(@, @ * @);\r\n", colorAccuDecl, accuMap, inTex, accuScale ) );
if (!fd.features[MFT_Imposter])
meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", accuColor, accuColor));
// scale up normals
meta->addStatement( new GenOp( " @.xyz = @.xyz * 2.0 - 0.5;\r\n", bumpNorm, bumpNorm ) );

View file

@ -826,6 +826,12 @@ Var* ShaderFeatureHLSL::addOutDetailTexCoord( Vector<ShaderComponent*> &compon
// Base Texture
//****************************************************************************
DiffuseMapFeatHLSL::DiffuseMapFeatHLSL()
: mTorqueDep("shaders/common/torque.hlsl")
{
addDependency(&mTorqueDep);
}
void DiffuseMapFeatHLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
@ -853,30 +859,30 @@ void DiffuseMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
diffuseMap->sampler = true;
diffuseMap->constNum = Var::getTexUnitNum(); // used as texture unit num here
// create sample color
Var *diffColor = new Var;
diffColor->setType("float4");
diffColor->setName("diffuseColor");
LangElement *colorDecl = new DecOp(diffColor);
MultiLine * meta = new MultiLine;
output = meta;
if ( fd.features[MFT_CubeMap] )
{
MultiLine * meta = new MultiLine;
// create sample color
Var *diffColor = new Var;
diffColor->setType( "float4" );
diffColor->setName( "diffuseColor" );
LangElement *colorDecl = new DecOp( diffColor );
meta->addStatement( new GenOp( " @ = tex2D(@, @);\r\n",
colorDecl,
diffuseMap,
inTex ) );
if (!fd.features[MFT_Imposter])
meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor));
meta->addStatement( new GenOp( " @;\r\n", assignColor( diffColor, Material::Mul ) ) );
output = meta;
}
else if(fd.features[MFT_DiffuseMapAtlas])
{
// Handle atlased textures
// http://www.infinity-universe.com/Infinity/index.php?option=com_content&task=view&id=65&Itemid=47
MultiLine * meta = new MultiLine;
output = meta;
Var *atlasedTex = new Var;
atlasedTex->setName("atlasedTexCoord");
@ -932,11 +938,6 @@ void DiffuseMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
// For the rest of the feature...
inTex = atlasedTex;
// create sample color var
Var *diffColor = new Var;
diffColor->setType("float4");
diffColor->setName("diffuseColor");
// To dump out UV coords...
//#define DEBUG_ATLASED_UV_COORDS
#ifdef DEBUG_ATLASED_UV_COORDS
@ -958,15 +959,18 @@ void DiffuseMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
meta->addStatement(new GenOp( " @ = tex2D(@, @);\r\n",
new DecOp(diffColor), diffuseMap, inTex));
}
if (!fd.features[MFT_Imposter])
meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor));
meta->addStatement(new GenOp( " @;\r\n", assignColor(diffColor, Material::Mul)));
}
else
{
LangElement *statement = new GenOp( "tex2D(@, @)", diffuseMap, inTex );
output = new GenOp( " @;\r\n", assignColor( statement, Material::Mul ) );
meta->addStatement(new GenOp("@ = tex2D(@, @);\r\n", colorDecl, diffuseMap, inTex));
if (!fd.features[MFT_Imposter])
meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", diffColor, diffColor));
meta->addStatement(new GenOp(" @;\r\n", assignColor(diffColor, Material::Mul)));
}
}
ShaderFeature::Resources DiffuseMapFeatHLSL::getResources( const MaterialFeatureData &fd )

View file

@ -236,7 +236,12 @@ public:
/// Base texture
class DiffuseMapFeatHLSL : public ShaderFeatureHLSL
{
protected:
ShaderIncludeDependency mTorqueDep;
public:
DiffuseMapFeatHLSL();
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );

View file

@ -70,6 +70,7 @@ void _initShaderGenHLSL( ShaderGen *shaderGen )
FEATUREMGR->registerFeature( MFT_GlossMap, new NamedFeatureHLSL( "Gloss Map" ) );
FEATUREMGR->registerFeature( MFT_LightbufferMRT, new NamedFeatureHLSL( "Lightbuffer MRT" ) );
FEATUREMGR->registerFeature( MFT_RenderTarget1_Zero, new RenderTargetZeroHLSL( ShaderFeature::RenderTarget1 ) );
FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) );
FEATUREMGR->registerFeature( MFT_DiffuseMapAtlas, new NamedFeatureHLSL( "Diffuse Map Atlas" ) );
FEATUREMGR->registerFeature( MFT_NormalMapAtlas, new NamedFeatureHLSL( "Normal Map Atlas" ) );

View file

@ -64,6 +64,12 @@ MODULE_BEGIN( TerrainFeatGLSL )
MODULE_END;
TerrainFeatGLSL::TerrainFeatGLSL()
: mTorqueDep( "shaders/common/gl/torque.glsl" )
{
addDependency( &mTorqueDep );
}
Var* TerrainFeatGLSL::_getUniformVar( const char *name, const char *type, ConstantSortPosition csp )
{
Var *theVar = (Var*)LangElement::find( name );
@ -262,6 +268,7 @@ 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));
meta->addStatement( new GenOp( " @;\r\n", assignColor( baseColor, Material::Mul ) ) );
output = meta;

View file

@ -36,7 +36,10 @@
class TerrainFeatGLSL : public ShaderFeatureGLSL
{
protected:
ShaderIncludeDependency mTorqueDep;
public:
TerrainFeatGLSL();
Var* _getInDetailCoord(Vector<ShaderComponent*> &componentList );
Var* _getInMacroCoord(Vector<ShaderComponent*> &componentList );

View file

@ -64,6 +64,12 @@ MODULE_BEGIN( TerrainFeatHLSL )
MODULE_END;
TerrainFeatHLSL::TerrainFeatHLSL()
: mTorqueDep( "shaders/common/torque.hlsl" )
{
addDependency( &mTorqueDep );
}
Var* TerrainFeatHLSL::_getUniformVar( const char *name, const char *type, ConstantSortPosition csp )
{
Var *theVar = (Var*)LangElement::find( name );
@ -262,6 +268,7 @@ void TerrainBaseMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentLis
baseColor->setType( "float4" );
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));
meta->addStatement( new GenOp( " @;\r\n", assignColor( baseColor, Material::Mul ) ) );
output = meta;

View file

@ -37,6 +37,10 @@ class TerrainFeatHLSL : public ShaderFeatureHLSL
{
protected:
ShaderIncludeDependency mTorqueDep;
public:
TerrainFeatHLSL();
Var* _getInDetailCoord(Vector<ShaderComponent*> &componentList );
Var* _getInMacroCoord(Vector<ShaderComponent*> &componentList );

View file

@ -136,6 +136,7 @@ void ImposterCaptureMaterialHook::_overrideFeatures( ProcessedMaterial *mat,
fd.features.addFeature( MFT_NormalsOut );
fd.features.addFeature( MFT_ForwardShading );
fd.features.addFeature( MFT_Imposter );
}
ImposterCaptureMaterialHook* ImposterCaptureMaterialHook::_getOrCreateHook( BaseMatInstance *inMat )