Update GLSL Shadergen. Not used on DX9.

This commit is contained in:
LuisAntonRebollo 2014-04-17 17:44:49 +02:00
parent ba36617aec
commit 9221b4dd10
20 changed files with 1944 additions and 1128 deletions

View file

@ -38,98 +38,35 @@ PixelSpecularGLSL::PixelSpecularGLSL()
void PixelSpecularGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
/*
AssertFatal( fd.features[MFT_RTLighting],
"PixelSpecularHLSL requires RTLighting to be enabled!" );
MultiLine *meta = new MultiLine;
// Get the eye world position.
Var *eyePos = (Var*)LangElement::find( "eyePosWorld" );
if( !eyePos )
{
eyePos = new Var;
eyePos->setType( "float3" );
eyePos->setName( "eyePosWorld" );
eyePos->uniform = true;
eyePos->constSortPos = cspPass;
}
// Grab a register for passing the
// world space view vector.
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *wsView = connectComp->getElement( RT_TEXCOORD );
wsView->setName( "wsView" );
wsView->setStructName( "OUT" );
wsView->setType( "float3" );
// Get the input position.
Var *position = (Var*)LangElement::find( "inPosition" );
if ( !position )
position = (Var*)LangElement::find( "position" );
// Get the object to world transform.
Var *objTrans = (Var*) LangElement::find( "objTrans" );
if ( !objTrans )
{
objTrans = new Var;
objTrans->setType( "float4x4" );
objTrans->setName( "objTrans" );
objTrans->uniform = true;
objTrans->constSortPos = cspPrimitive;
}
meta->addStatement( new GenOp( " @ = @ - mul( @, float4( @.xyz,1 ) ).xyz;\r\n",
wsView, eyePos, objTrans, position ) );
output = meta;
*/
// Nothing to do here... MFT_RTLighting should have
// taken care of passing everything to the pixel shader.
}
void PixelSpecularGLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
/*
{
AssertFatal( fd.features[MFT_RTLighting],
"PixelSpecularHLSL requires RTLighting to be enabled!" );
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
// RTLighting should have spit out the 4 specular
// powers for the 4 potential lights on this pass.
//
// This can sometimes be NULL if RTLighting skips out
// on us for lightmaps or missing normals.
Var *specular = (Var*)LangElement::find( "specular" );
if ( !specular )
return;
MultiLine *meta = new MultiLine;
// Get the normal and light vectors from which the
// RTLighting feature should have already setup.
Var *wsNormal = (Var*)LangElement::find( "wsNormal" );
Var *inLightVec = (Var*)LangElement::find( "inLightVec" );
// Grab the world space position to eye vector.
Var *wsView = connectComp->getElement( RT_TEXCOORD );
wsView->setName( "wsView" );
wsView->setStructName( "IN" );
wsView->setType( "float3" );
// Get the specular power and color.
Var *specPow = new Var( "specularPower", "float" );
specPow->uniform = true;
specPow->constSortPos = cspPass;
Var *specCol = (Var*)LangElement::find("specularColor");
if(specCol == NULL)
{
specCol = new Var( "specularColor", "vec4" );
specCol->uniform = true;
specCol->constSortPos = cspPass;
}
// Calcuate the specular factor.
Var *specular = new Var( "specular", "float" );
meta->addStatement( new GenOp( " @ = calcSpecular( -@, normalize( @ ), normalize( @ ), @ );\r\n",
new DecOp( specular ), inLightVec, wsNormal, wsView, specPow ) );
LangElement *specMul = new GenOp( "float4(@.rgb,0) * @", specCol, specular );
LangElement *specMul = new GenOp( "@", specular );
LangElement *final = specMul;
// mask out with lightmap if present
if( fd.features[MFT_LightMap] )
if ( fd.features[MFT_LightMap] )
{
LangElement *lmColor = NULL;
@ -141,37 +78,44 @@ void PixelSpecularGLSL::processPix( Vector<ShaderComponent*> &componentList,
LangElement * lightMap = LangElement::find( "lightMap" );
LangElement * lmCoord = LangElement::find( "texCoord2" );
lmColor = new GenOp( "tex2D(@, @)", lightMap, lmCoord );
lmColor = new GenOp( "texture(@, @)", lightMap, lmCoord );
}
final = new GenOp( "@ * float4(@.rgb,0)", specMul, lmColor );
final = new GenOp( "@ * vec4(@.rgb,0)", specMul, lmColor );
}
// We we have a normal map then mask the specular
if ( !fd.features[MFT_SpecularMap] && fd.features[MFT_NormalMap] )
// If we have a normal map then mask the specular
if ( fd.features[MFT_SpecularMap] )
{
Var *specularColor = (Var*)LangElement::find( "specularColor" );
if (specularColor)
final = new GenOp( "@ * @", final, specularColor );
}
else if ( fd.features[MFT_NormalMap] && !fd.features[MFT_IsDXTnm] )
{
Var *bumpColor = (Var*)LangElement::find( "bumpNormal" );
final = new GenOp( "@ * @.a", final, bumpColor );
}
// Add the specular to the final color.
meta->addStatement( new GenOp( " @;\r\n", assignColor( final, Material::Add ) ) );
// Add the specular to the final color.
// search for color var
Var *color = (Var*)LangElement::find( "col" );
meta->addStatement( new GenOp( " @.rgb += ( @ ).rgb;\r\n", color, final ) );
output = meta;
*/
}
ShaderFeature::Resources PixelSpecularGLSL::getResources( const MaterialFeatureData &fd )
{
Resources res;
res.numTexReg = 1;
return res;
}
void SpecularMapGLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
{
// Get the texture coord.
Var *texCoord = getInTexCoord( "out_texCoord", "vec2", true, componentList );
Var *texCoord = getInTexCoord( "texCoord", "vec2", true, componentList );
// create texture var
Var *specularMap = new Var;
@ -180,7 +124,7 @@ void SpecularMapGLSL::processPix( Vector<ShaderComponent*> &componentList, const
specularMap->uniform = true;
specularMap->sampler = true;
specularMap->constNum = Var::getTexUnitNum();
LangElement *texOp = new GenOp( "texture2D(@, @)", specularMap, texCoord );
LangElement *texOp = new GenOp( "texture(@, @)", specularMap, texCoord );
Var *specularColor = new Var( "specularColor", "vec4" );
@ -203,6 +147,7 @@ void SpecularMapGLSL::setTexData( Material::StageData &stageDat,
if ( tex )
{
passData.mTexType[ texIndex ] = Material::Standard;
passData.mSamplerNames[ texIndex ] = "specularMap";
passData.mTexSlot[ texIndex++ ].texObject = tex;
}
}