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

@ -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" ) );