mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 19:53:48 +00:00
diffuse/albedo texture linearization
http://http.developer.nvidia.com/GPUGems3/gpugems3_ch24.html
This commit is contained in:
parent
51b6469922
commit
ce2964d2d0
31 changed files with 396 additions and 107 deletions
|
|
@ -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 ) );
|
||||
|
|
|
|||
|
|
@ -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 )
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
||||
|
|
|
|||
|
|
@ -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 ) );
|
||||
|
|
|
|||
|
|
@ -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 )
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
||||
|
|
|
|||
|
|
@ -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" ) );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue