mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-26 01:53:47 +00:00
Blinn-Phong Specular Changes
Based on the work done here: http://www.garagegames.com/community/blogs/view/21032
This commit is contained in:
parent
f5246bb809
commit
17113d3ba5
25 changed files with 167 additions and 26 deletions
|
|
@ -51,7 +51,7 @@ Var *AdvancedLightBufferConditioner::_conditionOutput( Var *unconditionedOutput,
|
|||
if(getBufferFormat() == GFXFormatR16G16B16A16)
|
||||
meta->addStatement( new GenOp( " @ = max(4.0, (float4(lightColor, specular) * NL_att + float4(bufferSample.rgb, 0.0)) / 4.0);\r\n", outputDecl ) );
|
||||
else
|
||||
meta->addStatement( new GenOp( " @ = float4(lightColor, specular) * NL_att + float4(bufferSample.rgb, 0.0);\r\n", outputDecl ) );
|
||||
meta->addStatement( new GenOp( " @ = float4(lightColor, 0) * NL_att + float4(bufferSample.rgb, specular);\r\n", outputDecl ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -80,7 +80,7 @@ Var *AdvancedLightBufferConditioner::_unconditionInput( Var *conditionedInput, M
|
|||
meta->addStatement( new GenOp( " NL_att = @.b;\r\n", conditionedInput ) );
|
||||
meta->addStatement( new GenOp( " lightColor = DecodeLuv(float3(saturate(NL_att), @.rg * 0.62));\r\n", conditionedInput ) );
|
||||
}
|
||||
meta->addStatement( new GenOp( " specular = max(@.a / NL_att, 0.00001f);\r\n", conditionedInput ) );
|
||||
meta->addStatement( new GenOp( " specular = @.a;\r\n", conditionedInput ) );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -517,6 +517,12 @@ void DeferredPixelSpecularGLSL::processPix( Vector<ShaderComponent*> &component
|
|||
specPow->constSortPos = cspPotentialPrimitive;
|
||||
}
|
||||
|
||||
Var *specStrength = new Var;
|
||||
specStrength->setType( "float" );
|
||||
specStrength->setName( "specularStrength" );
|
||||
specStrength->uniform = true;
|
||||
specStrength->constSortPos = cspPotentialPrimitive;
|
||||
|
||||
Var *constSpecPow = new Var;
|
||||
constSpecPow->setType( "float" );
|
||||
constSpecPow->setName( "constantSpecularPower" );
|
||||
|
|
@ -527,7 +533,7 @@ void DeferredPixelSpecularGLSL::processPix( Vector<ShaderComponent*> &component
|
|||
AssertFatal( lightInfoSamp, "Something hosed the deferred features! Can't find lightInfoSample" );
|
||||
|
||||
// (a^m)^n = a^(m*n)
|
||||
meta->addStatement( new GenOp( " @ = pow(d_specular, ceil(@ / @)) * d_NL_Att;\r\n", specDecl, specPow, constSpecPow ) );
|
||||
meta->addStatement( new GenOp( " @ = pow(d_specular, ceil(@ / @)) * @;\r\n", specDecl, specPow, constSpecPow, specStrength ) );
|
||||
|
||||
LangElement *specMul = new GenOp( "@ * @", specCol, specular );
|
||||
LangElement *final = specMul;
|
||||
|
|
@ -539,8 +545,7 @@ void DeferredPixelSpecularGLSL::processPix( Vector<ShaderComponent*> &component
|
|||
final = new GenOp( "@ * @.a", final, bumpSample );
|
||||
}
|
||||
|
||||
// add to color
|
||||
meta->addStatement( new GenOp( " @;\r\n", assignColor( final, Material::Add ) ) );
|
||||
// add to color meta->addStatement( new GenOp( " @;\r\n", assignColor( final, Material::Add ) ) );
|
||||
|
||||
output = meta;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -465,6 +465,12 @@ void DeferredPixelSpecularHLSL::processPix( Vector<ShaderComponent*> &component
|
|||
specPow->constSortPos = cspPotentialPrimitive;
|
||||
}
|
||||
|
||||
Var *specStrength = new Var;
|
||||
specStrength->setType( "float" );
|
||||
specStrength->setName( "specularStrength" );
|
||||
specStrength->uniform = true;
|
||||
specStrength->constSortPos = cspPotentialPrimitive;
|
||||
|
||||
Var *lightInfoSamp = (Var *)LangElement::find( "lightInfoSample" );
|
||||
Var *d_specular = (Var*)LangElement::find( "d_specular" );
|
||||
Var *d_NL_Att = (Var*)LangElement::find( "d_NL_Att" );
|
||||
|
|
@ -474,7 +480,7 @@ void DeferredPixelSpecularHLSL::processPix( Vector<ShaderComponent*> &component
|
|||
|
||||
// (a^m)^n = a^(m*n)
|
||||
meta->addStatement( new GenOp( " @ = pow( @, ceil(@ / AL_ConstantSpecularPower)) * @;\r\n",
|
||||
specDecl, d_specular, specPow, d_NL_Att ) );
|
||||
specDecl, d_specular, specPow, specStrength ) );
|
||||
|
||||
LangElement *specMul = new GenOp( "float4( @.rgb, 0 ) * @", specCol, specular );
|
||||
LangElement *final = specMul;
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ Material::Material()
|
|||
mSpecular[i].set( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||
|
||||
mSpecularPower[i] = 8.0f;
|
||||
mSpecularStrength[i] = 1.0f;
|
||||
mPixelSpecular[i] = false;
|
||||
|
||||
mParallaxScale[i] = 0.0f;
|
||||
|
|
@ -239,7 +240,10 @@ void Material::initPersistFields()
|
|||
"The color of the specular highlight when not using a specularMap." );
|
||||
|
||||
addField("specularPower", TypeF32, Offset(mSpecularPower, Material), MAX_STAGES,
|
||||
"The intensity of the specular highlight when not using a specularMap." );
|
||||
"The hardness of the specular highlight when not using a specularMap." );
|
||||
|
||||
addField("specularStrength", TypeF32, Offset(mSpecularStrength, Material), MAX_STAGES,
|
||||
"The strength of the specular highlight when not using a specularMap." );
|
||||
|
||||
addField("pixelSpecular", TypeBool, Offset(mPixelSpecular, Material), MAX_STAGES,
|
||||
"This enables per-pixel specular highlights controlled by the alpha channel of the "
|
||||
|
|
|
|||
|
|
@ -223,6 +223,7 @@ public:
|
|||
ColorF mSpecular[MAX_STAGES];
|
||||
|
||||
F32 mSpecularPower[MAX_STAGES];
|
||||
F32 mSpecularStrength[MAX_STAGES];
|
||||
bool mPixelSpecular[MAX_STAGES];
|
||||
|
||||
bool mVertLit[MAX_STAGES];
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ void ShaderConstHandles::init( GFXShader *shader, CustomMaterial* mat /*=NULL*/
|
|||
mToneMapTexSC = shader->getShaderConstHandle(ShaderGenVars::toneMap);
|
||||
mSpecularColorSC = shader->getShaderConstHandle(ShaderGenVars::specularColor);
|
||||
mSpecularPowerSC = shader->getShaderConstHandle(ShaderGenVars::specularPower);
|
||||
mSpecularStrengthSC = shader->getShaderConstHandle(ShaderGenVars::specularStrength);
|
||||
mParallaxInfoSC = shader->getShaderConstHandle("$parallaxInfo");
|
||||
mFogDataSC = shader->getShaderConstHandle(ShaderGenVars::fogData);
|
||||
mFogColorSC = shader->getShaderConstHandle(ShaderGenVars::fogColor);
|
||||
|
|
@ -993,6 +994,7 @@ void ProcessedShaderMaterial::_setShaderConstants(SceneRenderState * state, cons
|
|||
|
||||
shaderConsts->setSafe(handles->mSpecularColorSC, mMaterial->mSpecular[stageNum]);
|
||||
shaderConsts->setSafe(handles->mSpecularPowerSC, mMaterial->mSpecularPower[stageNum]);
|
||||
shaderConsts->setSafe(handles->mSpecularStrengthSC, mMaterial->mSpecularStrength[stageNum]);
|
||||
|
||||
shaderConsts->setSafe(handles->mParallaxInfoSC, mMaterial->mParallaxScale[stageNum]);
|
||||
shaderConsts->setSafe(handles->mMinnaertConstantSC, mMaterial->mMinnaertConstant[stageNum]);
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ public:
|
|||
GFXShaderConstHandle* mTexMatSC;
|
||||
GFXShaderConstHandle* mSpecularColorSC;
|
||||
GFXShaderConstHandle* mSpecularPowerSC;
|
||||
GFXShaderConstHandle* mSpecularStrengthSC;
|
||||
GFXShaderConstHandle* mParallaxInfoSC;
|
||||
GFXShaderConstHandle* mFogDataSC;
|
||||
GFXShaderConstHandle* mFogColorSC;
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ const String ShaderGenVars::lightSpotAngle("$inLightSpotAngle");
|
|||
const String ShaderGenVars::lightSpotFalloff("$inLightSpotFalloff");
|
||||
const String ShaderGenVars::specularColor("$specularColor");
|
||||
const String ShaderGenVars::specularPower("$specularPower");
|
||||
const String ShaderGenVars::specularStrength("$specularStrength");
|
||||
|
||||
// These are ignored by the D3D layers.
|
||||
const String ShaderGenVars::fogMap("$fogMap");
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ struct ShaderGenVars
|
|||
const static String lightSpotFalloff;
|
||||
const static String specularColor;
|
||||
const static String specularPower;
|
||||
const static String specularStrength;
|
||||
|
||||
// Textures
|
||||
const static String fogMap;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue