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

@ -64,14 +64,14 @@ void BumpFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
output = meta;
// Get the texture coord.
Var *texCoord = getInTexCoord( "out_texCoord", "vec2", true, componentList );
Var *texCoord = getInTexCoord( "texCoord", "vec2", true, componentList );
// Sample the bumpmap.
Var *bumpMap = getNormalMapTex();
LangElement *texOp = NULL;
//Handle atlased textures
// http://www.infinity-universe.com/Infinity/index.php?option=com_content&task=view&id=65&Itemid=47
if(fd.features[MFT_NormalMapAtlas])
{
// This is a big block of code, so put a comment in the shader code
@ -79,52 +79,49 @@ void BumpFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
Var *atlasedTex = new Var;
atlasedTex->setName("atlasedBumpCoord");
atlasedTex->setType("vec2");
atlasedTex->setType( "vec2" );
LangElement *atDecl = new DecOp(atlasedTex);
// Parameters of the texture atlas
Var *atParams = new Var;
atParams->setType("vec4");
atParams->setType( "float4" );
atParams->setName("bumpAtlasParams");
atParams->uniform = true;
atParams->constSortPos = cspPotentialPrimitive;
// Parameters of the texture (tile) this object is using in the atlas
Var *tileParams = new Var;
tileParams->setType("vec4");
tileParams->setType( "float4" );
tileParams->setName("bumpAtlasTileParams");
tileParams->uniform = true;
tileParams->constSortPos = cspPotentialPrimitive;
const bool is_sm3 = (GFX->getPixelShaderVersion() > 2.0f);
// getPixelShaderVersion() on Mac currently returns 2.0,
// or 3.0 if Advanced Lighting is enabled
if(is_sm3)
{
// Figure out the mip level
meta->addStatement(new GenOp(" vec2 _dx_bump = dFdx(@ * @.z);\r\n", texCoord, atParams));
meta->addStatement(new GenOp(" vec2 _dy_bump = dFdy(@ * @.z);\r\n", texCoord, atParams));
meta->addStatement(new GenOp(" float mipLod_bump = 0.5 * log2(max(dot(_dx_bump, _dx_bump), dot(_dy_bump, _dy_bump)));\r\n"));
meta->addStatement(new GenOp(" mipLod_bump = clamp(mipLod_bump, 0.0, @.w);\r\n", atParams));
meta->addStatement( new GenOp( " float2 _dx_bump = ddx(@ * @.z);\r\n", texCoord, atParams ) );
meta->addStatement( new GenOp( " float2 _dy_bump = ddy(@ * @.z);\r\n", texCoord, atParams ) );
meta->addStatement( new GenOp( " float mipLod_bump = 0.5 * log2(max(dot(_dx_bump, _dx_bump), dot(_dy_bump, _dy_bump)));\r\n"));
meta->addStatement( new GenOp( " mipLod_bump = clamp(mipLod_bump, 0.0, @.w);\r\n", atParams));
// And the size of the mip level
meta->addStatement(new GenOp(" float mipPixSz_bump = pow(2.0, @.w - mipLod_bump);\r\n", atParams));
meta->addStatement(new GenOp(" vec2 mipSz_bump = mipPixSz_bump / @.xy;\r\n", atParams));
meta->addStatement( new GenOp( " float2 mipSz_bump = mipPixSz_bump / @.xy;\r\n", atParams ) );
}
else
{
meta->addStatement(new GenOp(" vec2 mipSz = float2(1.0, 1.0);\r\n"));
meta->addStatement(new GenOp(" float2 mipSz = float2(1.0, 1.0);\r\n"));
}
// Tiling mode
// TODO: Select wrap or clamp somehow
if( true ) // Wrap
meta->addStatement(new GenOp(" @ = fract(@);\r\n", atDecl, texCoord));
meta->addStatement( new GenOp( " @ = frac(@);\r\n", atDecl, texCoord ) );
else // Clamp
meta->addStatement(new GenOp(" @ = saturate(@);\r\n", atDecl, texCoord));
// Finally scale/offset, and correct for filtering
meta->addStatement(new GenOp(" @ = @ * ((mipSz_bump * @.xy - 1.0) / mipSz_bump) + 0.5 / mipSz_bump + @.xy * @.xy;\r\n",
meta->addStatement( new GenOp( " @ = @ * ((mipSz_bump * @.xy - 1.0) / mipSz_bump) + 0.5 / mipSz_bump + @.xy * @.xy;\r\n",
atlasedTex, atlasedTex, atParams, atParams, tileParams));
// Add a newline
@ -132,19 +129,19 @@ void BumpFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
if(is_sm3)
{
texOp = new GenOp( "texture2DLod(@, vec4(@, 0.0, mipLod_bump)", bumpMap, texCoord );
texOp = new GenOp( "tex2Dlod(@, float4(@, 0.0, mipLod_bump))", bumpMap, texCoord );
}
else
{
texOp = new GenOp( "texture2D(@, @)", bumpMap, texCoord );
texOp = new GenOp( "tex2D(@, @)", bumpMap, texCoord );
}
}
else
{
texOp = new GenOp( "texture2D(@, @)", bumpMap, texCoord );
texOp = new GenOp( "tex2D(@, @)", bumpMap, texCoord );
}
Var *bumpNorm = new Var( "bumpNormal", "vec4" );
Var *bumpNorm = new Var( "bumpNormal", "float4" );
meta->addStatement( expandNormalMap( texOp, new DecOp( bumpNorm ), bumpNorm, fd ) );
// If we have a detail normal map we add the xy coords of
@ -160,11 +157,11 @@ void BumpFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
bumpMap->constNum = Var::getTexUnitNum();
texCoord = getInTexCoord( "detCoord", "vec2", true, componentList );
texOp = new GenOp( "texture2D(@, @)", bumpMap, texCoord );
texOp = new GenOp( "tex2D(@, @)", bumpMap, texCoord );
Var *detailBump = new Var;
detailBump->setName( "detailBump" );
detailBump->setType( "vec4" );
detailBump->setType( "float4" );
meta->addStatement( expandNormalMap( texOp, new DecOp( detailBump ), detailBump, fd ) );
Var *detailBumpScale = new Var;
@ -175,13 +172,11 @@ void BumpFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
meta->addStatement( new GenOp( " @.xy += @.xy * @;\r\n", bumpNorm, detailBump, detailBumpScale ) );
}
// We transform it into world space by reversing the
// multiplication by the worldToTanget transform.
Var *wsNormal = new Var( "wsNormal", "vec3" );
Var *worldToTanget = getInWorldToTangent( componentList );
meta->addStatement( new GenOp( " @ = normalize( vec3( @.xyz * @ ) );\r\n", new DecOp( wsNormal ), bumpNorm, worldToTanget ) );
meta->addStatement( new GenOp( " @ = normalize( tMul( @.xyz, @ ) );\r\n", new DecOp( wsNormal ), bumpNorm, worldToTanget ) );
}
ShaderFeature::Resources BumpFeatGLSL::getResources( const MaterialFeatureData &fd )
@ -227,20 +222,26 @@ void BumpFeatGLSL::setTexData( Material::StageData &stageDat,
if ( fd.features[MFT_NormalMap] )
{
passData.mTexType[ texIndex ] = Material::Bump;
passData.mSamplerNames[ texIndex ] = "bumpMap";
passData.mTexSlot[ texIndex++ ].texObject = stageDat.getTex( MFT_NormalMap );
}
if ( fd.features[ MFT_DetailNormalMap ] )
{
passData.mTexType[ texIndex ] = Material::DetailBump;
passData.mSamplerNames[ texIndex ] = "detailBumpMap";
passData.mTexSlot[ texIndex++ ].texObject = stageDat.getTex( MFT_DetailNormalMap );
}
}
//
Var* ParallaxFeatGLSL::_getUniformVar( const char *name, const char *type )
ParallaxFeatGLSL::ParallaxFeatGLSL()
: mIncludeDep( "shaders/common/gl/torque.glsl" )
{
addDependency( &mIncludeDep );
}
Var* ParallaxFeatGLSL::_getUniformVar( const char *name, const char *type, ConstantSortPosition csp )
{
Var *theVar = (Var*)LangElement::find( name );
if ( !theVar )
@ -249,7 +250,7 @@ Var* ParallaxFeatGLSL::_getUniformVar( const char *name, const char *type )
theVar->setType( type );
theVar->setName( name );
theVar->uniform = true;
theVar->constSortPos = cspPass;
theVar->constSortPos = csp;
}
return theVar;
@ -259,13 +260,13 @@ void ParallaxFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
AssertFatal( GFX->getPixelShaderVersion() >= 2.0,
"ParallaxFeatGLSL::processVert - We don't support SM 1.x!" );
"ParallaxFeatGLSL::processVert - We don't support SM 1.x!" );
MultiLine *meta = new MultiLine;
// Add the texture coords.
getOutTexCoord( "texCoord",
"vec2",
"vec2",
true,
fd.features[MFT_TexAnim],
meta,
@ -276,18 +277,36 @@ void ParallaxFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
if ( !inPos )
inPos = (Var*)LangElement::find( "position" );
// Get the object space eye position and the world
// to tangent transform.
Var *eyePos = _getUniformVar( "eyePos", "vec3" );
// Get the object space eye position and the
// object to tangent space transform.
Var *eyePos = _getUniformVar( "eyePos", "vec3", cspPrimitive );
Var *objToTangentSpace = getOutObjToTangentSpace( componentList, meta, fd );
// send transform to pixel shader
// Now send the negative view vector in tangent space to the pixel shader.
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *outViewTS = connectComp->getElement( RT_TEXCOORD, 1 );
outViewTS->setName( "outViewTS" );
outViewTS->setType( "vec3" );
meta->addStatement( new GenOp( " @ = ( @ - @.xyz ) * transpose( @ );\r\n",
outViewTS, inPos, eyePos, objToTangentSpace ) );
Var *outNegViewTS = connectComp->getElement( RT_TEXCOORD );
outNegViewTS->setName( "outNegViewTS" );
outNegViewTS->setStructName( "OUT" );
outNegViewTS->setType( "vec3" );
meta->addStatement( new GenOp( " @ = tMul( @, float3( @.xyz - @ ) );\r\n",
outNegViewTS, objToTangentSpace, inPos, eyePos ) );
// TODO: I'm at a loss at why i need to flip the binormal/y coord
// to get a good view vector for parallax. Lighting works properly
// with the TS matrix as is... but parallax does not.
//
// Someone figure this out!
//
meta->addStatement( new GenOp( " @.y = -@.y;\r\n", outNegViewTS, outNegViewTS ) );
// If we have texture anim matrix the tangent
// space view vector may need to be rotated.
Var *texMat = (Var*)LangElement::find( "texMat" );
if ( texMat )
{
meta->addStatement( new GenOp( " @ = tMul(@, float4(@,0)).xyz;\r\n",
outNegViewTS, texMat, outNegViewTS ) );
}
output = meta;
}
@ -296,7 +315,7 @@ void ParallaxFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
AssertFatal( GFX->getPixelShaderVersion() >= 2.0,
"ParallaxFeatGLSL::processPix - We don't support SM 1.x!" );
"ParallaxFeatGLSL::processPix - We don't support SM 1.x!" );
MultiLine *meta = new MultiLine;
@ -310,38 +329,28 @@ void ParallaxFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
Var *negViewTS = (Var*)LangElement::find( "negViewTS" );
if ( !negViewTS )
{
Var *inViewTS = (Var*)LangElement::find( "outViewTS" );
if ( !inViewTS )
Var *inNegViewTS = (Var*)LangElement::find( "outNegViewTS" );
if ( !inNegViewTS )
{
inViewTS = connectComp->getElement( RT_TEXCOORD, 1 );
inViewTS->setName( "outViewTS" );
inViewTS->setType( "vec3" );
inNegViewTS = connectComp->getElement( RT_TEXCOORD );
inNegViewTS->setName( "outNegViewTS" );
inNegViewTS->setStructName( "IN" );
inNegViewTS->setType( "vec3" );
}
negViewTS = new Var( "negViewTS", "vec3" );
meta->addStatement( new GenOp( " @ = -normalize( @ );\r\n", new DecOp( negViewTS ), inViewTS ) );
meta->addStatement( new GenOp( " @ = normalize( @ );\r\n", new DecOp( negViewTS ), inNegViewTS ) );
}
// Get the rest of our inputs.
Var *parallaxInfo = _getUniformVar( "parallaxInfo", "float" );
Var *parallaxInfo = _getUniformVar( "parallaxInfo", "float", cspPotentialPrimitive );
Var *normalMap = getNormalMapTex();
// Do 3 parallax samples to get acceptable
// quality without too much overhead.
Var *pdepth = findOrCreateLocal( "pdepth", "float", meta );
Var *poffset = findOrCreateLocal( "poffset", "vec2", meta );
meta->addStatement( new GenOp( " @ = texture2D( @, @.xy ).a;\r\n", pdepth, normalMap, texCoord ) );
meta->addStatement( new GenOp( " @ = @.xy * ( @ * @ );\r\n", poffset, negViewTS, pdepth, parallaxInfo ) );
meta->addStatement( new GenOp( " @ = ( @ + texture2D( @, @.xy + @ ).a ) * 0.5;\r\n", pdepth, pdepth, normalMap, texCoord, poffset ) );
meta->addStatement( new GenOp( " @ = @.xy * ( @ * @ );\r\n", poffset, negViewTS, pdepth, parallaxInfo ) );
meta->addStatement( new GenOp( " @ = ( @ + texture2D( @, @.xy + @ ).a ) * 0.5;\r\n", pdepth, pdepth, normalMap, texCoord, poffset ) );
meta->addStatement( new GenOp( " @ = @.xy * ( @ * @ );\r\n", poffset, negViewTS, pdepth, parallaxInfo ) );
meta->addStatement( new GenOp( " @.xy += @;\r\n", texCoord, poffset ) );
// Call the library function to do the rest.
meta->addStatement( new GenOp( " @.xy += parallaxOffset( @, @.xy, @, @ );\r\n",
texCoord, normalMap, texCoord, negViewTS, parallaxInfo ) );
// TODO: Fix second UV.
// TODO: Fix second UV maybe?
output = meta;
}
@ -349,7 +358,7 @@ void ParallaxFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
ShaderFeature::Resources ParallaxFeatGLSL::getResources( const MaterialFeatureData &fd )
{
AssertFatal( GFX->getPixelShaderVersion() >= 2.0,
"ParallaxFeatGLSL::getResources - We don't support SM 1.x!" );
"ParallaxFeatGLSL::getResources - We don't support SM 1.x!" );
Resources res;
@ -370,7 +379,7 @@ void ParallaxFeatGLSL::setTexData( Material::StageData &stageDat,
U32 &texIndex )
{
AssertFatal( GFX->getPixelShaderVersion() >= 2.0,
"ParallaxFeatGLSL::setTexData - We don't support SM 1.x!" );
"ParallaxFeatGLSL::setTexData - We don't support SM 1.x!" );
GFXTextureObject *tex = stageDat.getTex( MFT_NormalMap );
if ( tex )
@ -381,7 +390,6 @@ void ParallaxFeatGLSL::setTexData( Material::StageData &stageDat,
}
//
void NormalsOutFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
@ -397,6 +405,7 @@ void NormalsOutFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
Var *outNormal = connectComp->getElement( RT_TEXCOORD );
outNormal->setName( "wsNormal" );
outNormal->setStructName( "OUT" );
outNormal->setType( "vec3" );
outNormal->mapsToSampler = false;
@ -406,13 +415,13 @@ void NormalsOutFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
{
// Transform the normal to world space.
Var *objTrans = getObjTrans( componentList, fd.features[MFT_UseInstancing], meta );
meta->addStatement( new GenOp( " @ = @ * normalize( @ );\r\n", outNormal, objTrans, inNormal ) );
meta->addStatement( new GenOp( " @ = tMul( @, normalize( vec4(@, 0.0) ) ).xyz;\r\n", outNormal, objTrans, inNormal ) );
}
else
{
// If we don't have a vertex normal... just pass the
// camera facing normal to the pixel shader.
meta->addStatement( new GenOp( " @ = vec3( 0.0, 0.0, 1.0 );\r\n", outNormal ) );
meta->addStatement( new GenOp( " @ = float3( 0.0, 0.0, 1.0 );\r\n", outNormal ) );
}
}
@ -428,20 +437,26 @@ void NormalsOutFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
wsNormal = connectComp->getElement( RT_TEXCOORD );
wsNormal->setName( "wsNormal" );
wsNormal->setStructName( "IN" );
wsNormal->setType( "vec3" );
// If we loaded the normal its our resposibility
// to normalize it... the interpolators won't.
//
meta->addStatement( new GenOp( " @ = normalize( @ );\r\n", wsNormal, wsNormal ) );
// Note we cast to half here to get partial precision
// optimized code which is an acceptable loss of
// precision for normals and performs much better
// on older Geforce cards.
//
meta->addStatement( new GenOp( " @ = normalize( half3( @ ) );\r\n", wsNormal, wsNormal ) );
}
LangElement *normalOut;
Var *outColor = (Var*)LangElement::find( "col" );
if ( outColor )
normalOut = new GenOp( "vec4( ( -@ + 1 ) * 0.5, @.a )", wsNormal, outColor );
if ( outColor && !fd.features[MFT_AlphaTest] )
normalOut = new GenOp( "float4( ( -@ + 1 ) * 0.5, @.a )", wsNormal, outColor );
else
normalOut = new GenOp( "vec4( ( -@ + 1 ) * 0.5, 1 )", wsNormal );
normalOut = new GenOp( "float4( ( -@ + 1 ) * 0.5, 1 )", wsNormal );
meta->addStatement( new GenOp( " @;\r\n",
assignColor( normalOut, Material::None ) ) );

View file

@ -26,6 +26,9 @@
#ifndef _SHADERGEN_GLSL_SHADERFEATUREGLSL_H_
#include "shaderGen/GLSL/shaderFeatureGLSL.h"
#endif
#ifndef _LANG_ELEMENT_H_
#include "shaderGen/langElement.h"
#endif
struct RenderPassData;
class MultiLine;
@ -50,7 +53,6 @@ public:
const MaterialFeatureData &fd,
RenderPassData &passData,
U32 &texIndex );
virtual String getName() { return "Bumpmap"; }
};
@ -62,10 +64,16 @@ class ParallaxFeatGLSL : public ShaderFeatureGLSL
{
protected:
static Var* _getUniformVar( const char *name, const char *type );
static Var* _getUniformVar( const char *name,
const char *type,
ConstantSortPosition csp );
ShaderIncludeDependency mIncludeDep;
public:
ParallaxFeatGLSL();
// ShaderFeatureGLSL
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
@ -80,7 +88,6 @@ public:
};
/// This feature is used to render normals to the
/// diffuse target for imposter rendering.
class NormalsOutFeatGLSL : public ShaderFeatureGLSL

View file

@ -24,36 +24,36 @@
#include "shaderGen/GLSL/depthGLSL.h"
#include "materials/materialFeatureTypes.h"
#include "materials/materialFeatureData.h"
void EyeSpaceDepthOutGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
MultiLine *meta = new MultiLine;
MultiLine *meta = new MultiLine;
output = meta;
// grab output
// grab output
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *outWSEyeVec = connectComp->getElement( RT_TEXCOORD );
outWSEyeVec->setName( "outWSEyeVec" );
// grab incoming vert position
Var *wsPosition = new Var( "depthPos", "vec3" );
outWSEyeVec->setName( "wsEyeVec" );
outWSEyeVec->setStructName( "OUT" );
// grab incoming vert position
Var *wsPosition = new Var( "depthPos", "float3" );
getWsPosition( componentList, fd.features[MFT_UseInstancing], meta, new DecOp( wsPosition ) );
Var *eyePos = (Var*)LangElement::find( "eyePosWorld" );
if( !eyePos )
{
eyePos = new Var;
eyePos->setType("vec3");
eyePos->setType("float3");
eyePos->setName("eyePosWorld");
eyePos->uniform = true;
eyePos->constSortPos = cspPass;
}
meta->addStatement( new GenOp( " @ = vec4( @.xyz - @, 1 );\r\n", outWSEyeVec, wsPosition, eyePos ) );
meta->addStatement( new GenOp( " @ = float4( @.xyz - @, 1 );\r\n", outWSEyeVec, wsPosition, eyePos ) );
}
void EyeSpaceDepthOutGLSL::processPix( Vector<ShaderComponent*> &componentList,
@ -64,14 +64,15 @@ void EyeSpaceDepthOutGLSL::processPix( Vector<ShaderComponent*> &componentList,
// grab connector position
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *wsEyeVec = connectComp->getElement( RT_TEXCOORD );
wsEyeVec->setName( "outWSEyeVec" );
wsEyeVec->setType( "vec4" );
wsEyeVec->setName( "wsEyeVec" );
wsEyeVec->setStructName( "IN" );
wsEyeVec->setType( "float4" );
wsEyeVec->mapsToSampler = false;
wsEyeVec->uniform = false;
// get shader constants
Var *vEye = new Var;
vEye->setType("vec3");
vEye->setType("float3");
vEye->setName("vEye");
vEye->uniform = true;
vEye->constSortPos = cspPass;
@ -83,12 +84,27 @@ void EyeSpaceDepthOutGLSL::processPix( Vector<ShaderComponent*> &componentList,
LangElement *depthOutDecl = new DecOp( depthOut );
meta->addStatement( new GenOp( "#ifndef CUBE_SHADOW_MAP\r\n" ) );
meta->addStatement( new GenOp( " @ = dot(@, (@.xyz / @.w));\r\n", depthOutDecl, vEye, wsEyeVec, wsEyeVec ) );
meta->addStatement( new GenOp( "#else\r\n" ) );
Var *farDist = (Var*)Var::find( "oneOverFarplane" );
if ( !farDist )
{
farDist = new Var;
farDist->setType("float4");
farDist->setName("oneOverFarplane");
farDist->uniform = true;
farDist->constSortPos = cspPass;
}
meta->addStatement( new GenOp( " @ = length( @.xyz / @.w ) * @.x;\r\n", depthOutDecl, wsEyeVec, wsEyeVec, farDist ) );
meta->addStatement( new GenOp( "#endif\r\n" ) );
// If there isn't an output conditioner for the pre-pass, than just write
// out the depth to rgba and return.
if( !fd.features[MFT_PrePassConditioner] )
meta->addStatement( new GenOp( " @;\r\n", assignColor( new GenOp( "vec4(@)", depthOut ), Material::None ) ) );
meta->addStatement( new GenOp( " @;\r\n", assignColor( new GenOp( "float4(float3(@),1)", depthOut ), Material::None ) ) );
output = meta;
}
@ -111,11 +127,12 @@ void DepthOutGLSL::processVert( Vector<ShaderComponent*> &componentList,
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
// Grab the output vert.
Var *outPosition = (Var*)LangElement::find( "gl_Position" );
Var *outPosition = (Var*)LangElement::find( "gl_Position" ); //hpos
// Grab our output depth.
Var *outDepth = connectComp->getElement( RT_TEXCOORD );
outDepth->setName( "outDepth" );
outDepth->setName( "depth" );
outDepth->setStructName( "OUT" );
outDepth->setType( "float" );
output = new GenOp( " @ = @.z / @.w;\r\n", outDepth, outPosition, outPosition );
@ -128,7 +145,8 @@ void DepthOutGLSL::processPix( Vector<ShaderComponent*> &componentList,
// grab connector position
Var *depthVar = connectComp->getElement( RT_TEXCOORD );
depthVar->setName( "outDepth" );
depthVar->setName( "depth" );
depthVar->setStructName( "IN" );
depthVar->setType( "float" );
depthVar->mapsToSampler = false;
depthVar->uniform = false;
@ -140,7 +158,7 @@ void DepthOutGLSL::processPix( Vector<ShaderComponent*> &componentList,
depthOut->setName(getOutputVarName());
*/
LangElement *depthOut = new GenOp( "vec4( @, @ * @, 0, 1 )", depthVar, depthVar, depthVar );
LangElement *depthOut = new GenOp( "float4( @, 0, 0, 1 )", depthVar );
output = new GenOp( " @;\r\n", assignColor( depthOut, Material::None ) );
}

View file

@ -54,7 +54,7 @@ public:
virtual Resources getResources( const MaterialFeatureData &fd );
virtual String getName() { return "Depth (Out)"; }
virtual Material::BlendOp getBlendOp() { return Material::None; }
virtual const char* getOutputVarName() const { return "outDepth"; }
virtual const char* getOutputVarName() const { return "IN_depth"; }
};
#endif // _DEPTH_GLSL_H_

View file

@ -65,7 +65,7 @@ void ParaboloidVertTransformGLSL::processVert( Vector<ShaderComponent*> &compon
// http://www.gamedev.net/reference/articles/article2308.asp
// Swizzle z and y post-transform
meta->addStatement( new GenOp( " @ = vec4(@ * vec4(@.xyz,1)).xzyw;\r\n", outPosition, worldViewOnly, inPosition ) );
meta->addStatement( new GenOp( " @ = tMul(@, float4(@.xyz,1)).xzyw;\r\n", outPosition, worldViewOnly, inPosition ) );
meta->addStatement( new GenOp( " float L = length(@.xyz);\r\n", outPosition ) );
if ( isSinglePass )
@ -73,7 +73,8 @@ void ParaboloidVertTransformGLSL::processVert( Vector<ShaderComponent*> &compon
// Flip the z in the back case
Var *outIsBack = connectComp->getElement( RT_TEXCOORD );
outIsBack->setType( "float" );
outIsBack->setName( "outIsBack" );
outIsBack->setName( "isBack" );
outIsBack->setStructName( "OUT" );
meta->addStatement( new GenOp( " bool isBack = @.z < 0.0;\r\n", outPosition ) );
meta->addStatement( new GenOp( " @ = isBack ? -1.0 : 1.0;\r\n", outIsBack ) );
@ -94,15 +95,16 @@ void ParaboloidVertTransformGLSL::processVert( Vector<ShaderComponent*> &compon
// TODO: If we change other shadow shaders to write out
// linear depth, than fix this as well!
//
// (L - 1.0)/(lightParams.x - 1.0);
// (L - zNear)/(lightParams.x - zNear);
//
meta->addStatement( new GenOp( " @.z = L / @.x;\r\n", outPosition, lightParams ) );
meta->addStatement( new GenOp( " @.w = 1.0;\r\n", outPosition ) );
// Pass unmodified to pixel shader to allow it to clip properly.
Var *outPosXY = connectComp->getElement( RT_TEXCOORD );
outPosXY->setType( "vec2" );
outPosXY->setName( "outPosXY" );
outPosXY->setType( "float2" );
outPosXY->setName( "posXY" );
outPosXY->setStructName( "OUT" );
meta->addStatement( new GenOp( " @ = @.xy;\r\n", outPosXY, outPosition ) );
// Scale and offset so it shows up in the atlas properly.
@ -136,16 +138,18 @@ void ParaboloidVertTransformGLSL::processPix( Vector<ShaderComponent*> &compon
{
// Cull things on the back side of the map.
Var *isBack = connectComp->getElement( RT_TEXCOORD );
isBack->setName( "outIsBack" );
isBack->setName( "isBack" );
isBack->setStructName( "IN" );
isBack->setType( "float" );
meta->addStatement( new GenOp( " if ( ( abs( @ ) - 0.999 ) < 0 ) discard;\r\n", isBack ) );
}
// Cull pixels outside of the valid paraboloid.
Var *posXY = connectComp->getElement( RT_TEXCOORD );
posXY->setName( "outPosXY" );
posXY->setType( "vec2" );
meta->addStatement( new GenOp( " if ( ( 1.0 - length( @ ) ) < 0 ) discard;\r\n", posXY ) );
posXY->setName( "posXY" );
posXY->setStructName( "IN" );
posXY->setType( "float2" );
meta->addStatement( new GenOp( " clip( 1.0 - abs(@.x) );\r\n", posXY ) );
output = meta;
}

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;
}
}

View file

@ -53,7 +53,6 @@ public:
}
};
/// A texture source for the PixSpecular feature
class SpecularMapGLSL : public ShaderFeatureGLSL
{
@ -75,5 +74,4 @@ public:
}
};
#endif // _PIXSPECULAR_GLSL_H_
#endif // _PIXSPECULAR_HLSL_H_

View file

@ -38,7 +38,7 @@ Var * AppVertConnectorGLSL::getElement( RegisterType type,
{
Var *newVar = new Var;
mElementList.push_back( newVar );
newVar->setConnectName( "gl_Vertex" );
newVar->setConnectName( "vPosition" );
return newVar;
}
@ -46,28 +46,49 @@ Var * AppVertConnectorGLSL::getElement( RegisterType type,
{
Var *newVar = new Var;
mElementList.push_back( newVar );
newVar->setConnectName( "gl_Normal" );
newVar->setConnectName( "vNormal" );
return newVar;
}
case RT_BINORMAL:
{
Var *newVar = new Var;
mElementList.push_back( newVar );
newVar->setConnectName( "vBinormal" );
return newVar;
}
case RT_COLOR:
{
Var *newVar = new Var;
mElementList.push_back( newVar );
newVar->setConnectName( "gl_Color" );
newVar->setConnectName( "vColor" );
return newVar;
}
case RT_TANGENT:
{
Var *newVar = new Var;
mElementList.push_back( newVar );
newVar->setConnectName( "vTangent" );
return newVar;
}
case RT_TANGENTW:
{
Var *newVar = new Var;
mElementList.push_back( newVar );
newVar->setConnectName( "vTangentW" );
return newVar;
}
case RT_TEXCOORD:
case RT_BINORMAL:
case RT_TANGENT:
{
Var *newVar = new Var;
mElementList.push_back( newVar );
char out[32];
dSprintf( (char*)out, sizeof(out), "gl_MultiTexCoord%d", mCurTexElem );
dSprintf( (char*)out, sizeof(out), "vTexCoord%d", mCurTexElem );
newVar->setConnectName( out );
newVar->constNum = mCurTexElem;
newVar->arraySize = numElements;
@ -108,29 +129,55 @@ void AppVertConnectorGLSL::reset()
mCurTexElem = 0;
}
void AppVertConnectorGLSL::print( Stream &stream )
void AppVertConnectorGLSL::print( Stream &stream, bool isVertexShader )
{
// print out elements
if(!isVertexShader)
return;
U8 output[256];
// print struct
dSprintf( (char*)output, sizeof(output), "struct VertexData\r\n" );
stream.write( dStrlen((char*)output), output );
dSprintf( (char*)output, sizeof(output), "{\r\n" );
stream.write( dStrlen((char*)output), output );
for( U32 i=0; i<mElementList.size(); i++ )
{
Var *var = mElementList[i];
U8 output[256];
const char* swizzle;
if(!dStrcmp((const char*)var->type, "float"))
swizzle = "x";
else if(!dStrcmp((const char*)var->type, "vec2"))
swizzle = "xy";
else if(!dStrcmp((const char*)var->type, "vec3"))
swizzle = "xyz";
if( var->arraySize == 1)
{
dSprintf( (char*)output, sizeof(output), " %s %s;\r\n", var->type, (char*)var->name );
stream.write( dStrlen((char*)output), output );
}
else
swizzle = "xyzw";
{
dSprintf( (char*)output, sizeof(output), " %s %s[%d];\r\n", var->type, (char*)var->name, var->arraySize );
stream.write( dStrlen((char*)output), output );
}
}
// This is ugly. We use #defines to match user defined names with
// built in vars. There is no cleaner way to do this.
dSprintf( (char*)output, sizeof(output), "#define %s %s.%s\r\n", var->name, var->connectName, swizzle );
dSprintf( (char*)output, sizeof(output), "} IN;\r\n\r\n" );
stream.write( dStrlen((char*)output), output );
// print in elements
for( U32 i=0; i<mElementList.size(); i++ )
{
Var *var = mElementList[i];
for(int j = 0; j < var->arraySize; ++j)
{
const char *name = j == 0 ? var->connectName : avar("vTexCoord%d", var->constNum + j) ;
dSprintf( (char*)output, sizeof(output), "in %s %s;\r\n", var->type, name );
stream.write( dStrlen((char*)output), output );
}
dSprintf( (char*)output, sizeof(output), "#define IN_%s IN.%s\r\n", var->name, var->name ); // TODO REMOVE
stream.write( dStrlen((char*)output), output );
}
const char* newLine ="\r\n";
stream.write( dStrlen((char*)newLine), newLine );
}
Var * VertPixelConnectorGLSL::getElement( RegisterType type,
@ -140,14 +187,45 @@ Var * VertPixelConnectorGLSL::getElement( RegisterType type,
switch( type )
{
case RT_POSITION:
{
Var *newVar = new Var;
mElementList.push_back( newVar );
newVar->setConnectName( "POSITION" );
return newVar;
}
case RT_NORMAL:
{
Var *newVar = new Var;
mElementList.push_back( newVar );
newVar->setConnectName( "NORMAL" );
return newVar;
}
case RT_COLOR:
{
Var *newVar = new Var;
mElementList.push_back( newVar );
newVar->setConnectName( "COLOR" );
return newVar;
}
/*case RT_BINORMAL:
{
Var *newVar = new Var;
mElementList.push_back( newVar );
newVar->setConnectName( "BINORMAL" );
return newVar;
}
case RT_TANGENT:
{
Var *newVar = new Var;
mElementList.push_back( newVar );
newVar->setConnectName( "TANGENT" );
return newVar;
} */
case RT_TEXCOORD:
case RT_BINORMAL:
case RT_TANGENT:
@ -155,6 +233,10 @@ Var * VertPixelConnectorGLSL::getElement( RegisterType type,
Var *newVar = new Var;
newVar->arraySize = numElements;
char out[32];
dSprintf( (char*)out, sizeof(out), "TEXCOORD%d", mCurTexElem );
newVar->setConnectName( out );
if ( numRegisters != -1 )
mCurTexElem += numRegisters;
else
@ -192,7 +274,7 @@ void VertPixelConnectorGLSL::reset()
mCurTexElem = 0;
}
void VertPixelConnectorGLSL::print( Stream &stream )
void VertPixelConnectorGLSL::print( Stream &stream, bool isVerterShader )
{
// print out elements
for( U32 i=0; i<mElementList.size(); i++ )
@ -204,15 +286,138 @@ void VertPixelConnectorGLSL::print( Stream &stream )
continue;
if(var->arraySize <= 1)
dSprintf((char*)output, sizeof(output), "varying %s %s;\r\n", var->type, var->name);
dSprintf((char*)output, sizeof(output), "%s %s _%s_;\r\n", (isVerterShader ? "out" : "in"), var->type, var->connectName);
else
dSprintf((char*)output, sizeof(output), "varying %s %s[%d];\r\n", var->type, var->name, var->arraySize);
dSprintf((char*)output, sizeof(output), "%s %s _%s_[%d];\r\n", (isVerterShader ? "out" : "in"),var->type, var->connectName, var->arraySize);
stream.write( dStrlen((char*)output), output );
}
printStructDefines(stream, !isVerterShader);
}
void VertexParamsDefGLSL::print( Stream &stream )
void VertPixelConnectorGLSL::printOnMain( Stream &stream, bool isVerterShader )
{
if(isVerterShader)
return;
const char *newLine = "\r\n";
const char *header = " //-------------------------\r\n";
stream.write( dStrlen((char*)newLine), newLine );
stream.write( dStrlen((char*)header), header );
// print out elements
for( U32 i=0; i<mElementList.size(); i++ )
{
U8 output[256];
Var *var = mElementList[i];
if(!dStrcmp((const char*)var->name, "gl_Position"))
continue;
dSprintf((char*)output, sizeof(output), " %s IN_%s = _%s_;\r\n", var->type, var->name, var->connectName);
stream.write( dStrlen((char*)output), output );
}
stream.write( dStrlen((char*)header), header );
stream.write( dStrlen((char*)newLine), newLine );
}
void AppVertConnectorGLSL::printOnMain( Stream &stream, bool isVerterShader )
{
if(!isVerterShader)
return;
const char *newLine = "\r\n";
const char *header = " //-------------------------\r\n";
stream.write( dStrlen((char*)newLine), newLine );
stream.write( dStrlen((char*)header), header );
// print out elements
for( U32 i=0; i<mElementList.size(); i++ )
{
Var *var = mElementList[i];
U8 output[256];
if(var->arraySize <= 1)
{
dSprintf((char*)output, sizeof(output), " IN.%s = %s;\r\n", var->name, var->connectName);
stream.write( dStrlen((char*)output), output );
}
else
{
for(int j = 0; j < var->arraySize; ++j)
{
const char *name = j == 0 ? var->connectName : avar("vTexCoord%d", var->constNum + j) ;
dSprintf((char*)output, sizeof(output), " IN.%s[%d] = %s;\r\n", var->name, j, name );
stream.write( dStrlen((char*)output), output );
}
}
}
stream.write( dStrlen((char*)header), header );
stream.write( dStrlen((char*)newLine), newLine );
}
Vector<String> initDeprecadedDefines()
{
Vector<String> vec;
vec.push_back( "isBack");
return vec;
}
void VertPixelConnectorGLSL::printStructDefines( Stream &stream, bool in )
{
const char* connectionDir;
if(in)
{
connectionDir = "IN";
}
else
{
connectionDir = "OUT";
}
static Vector<String> deprecatedDefines = initDeprecadedDefines();
const char *newLine = "\r\n";
const char *header = "// Struct defines\r\n";
stream.write( dStrlen((char*)newLine), newLine );
stream.write( dStrlen((char*)header), header );
// print out elements
for( U32 i=0; i<mElementList.size(); i++ )
{
U8 output[256];
Var *var = mElementList[i];
if(!dStrcmp((const char*)var->name, "gl_Position"))
continue;
if(!in)
{
dSprintf((char*)output, sizeof(output), "#define %s_%s _%s_\r\n", connectionDir, var->name, var->connectName);
stream.write( dStrlen((char*)output), output );
}
if( deprecatedDefines.contains((char*)var->name))
continue;
dSprintf((char*)output, sizeof(output), "#define %s %s_%s\r\n", var->name, connectionDir, var->name);
stream.write( dStrlen((char*)output), output );
}
stream.write( dStrlen((char*)newLine), newLine );
}
void VertexParamsDefGLSL::print( Stream &stream, bool isVerterShader )
{
// find all the uniform variables and print them out
for( U32 i=0; i<LangElement::elementList.size(); i++)
@ -237,7 +442,7 @@ void VertexParamsDefGLSL::print( Stream &stream )
stream.write( dStrlen(closer), closer );
}
void PixelParamsDefGLSL::print( Stream &stream )
void PixelParamsDefGLSL::print( Stream &stream, bool isVerterShader )
{
// find all the uniform variables and print them out
for( U32 i=0; i<LangElement::elementList.size(); i++)
@ -260,4 +465,22 @@ void PixelParamsDefGLSL::print( Stream &stream )
const char *closer = "\r\nvoid main()\r\n{\r\n";
stream.write( dStrlen(closer), closer );
for( U32 i=0; i<LangElement::elementList.size(); i++)
{
Var *var = dynamic_cast<Var*>(LangElement::elementList[i]);
if( var )
{
if( var->uniform && !var->sampler)
{
U8 output[256];
if(var->arraySize <= 1)
dSprintf((char*)output, sizeof(output), " %s %s = %s;\r\n", var->type, var->name, var->name);
else
dSprintf((char*)output, sizeof(output), " %s %s[%d] = %s;\r\n", var->type, var->name, var->arraySize, var->name);
stream.write( dStrlen((char*)output), output );
}
}
}
}

View file

@ -40,7 +40,9 @@ public:
virtual void reset();
virtual void sortVars();
virtual void print( Stream &stream );
virtual void print( Stream &stream, bool isVerterShader );
void printStructDefines( Stream &stream, bool in );
virtual void printOnMain( Stream &stream, bool isVerterShader );
};
class AppVertConnectorGLSL : public ShaderConnector
@ -53,21 +55,22 @@ public:
virtual void reset();
virtual void sortVars();
virtual void print( Stream &stream );
virtual void print( Stream &stream, bool isVerterShader );
virtual void printOnMain( Stream &stream, bool isVerterShader );
};
class VertexParamsDefGLSL : public ParamsDef
{
public:
virtual void print( Stream &stream );
virtual void print( Stream &stream, bool isVerterShader );
};
class PixelParamsDefGLSL : public ParamsDef
{
public:
virtual void print( Stream &stream );
virtual void print( Stream &stream, bool isVerterShader );
};
#endif // _SHADERCOMP_GLSL_H_

File diff suppressed because it is too large Load diff

View file

@ -25,9 +25,6 @@
#ifndef _SHADERFEATURE_H_
#include "shaderGen/shaderFeature.h"
#endif
#ifndef _MATERIALFEATUREDATA_H_
#include "materials/materialFeatureData.h"
#endif
struct LangElement;
struct MaterialFeatureData;
@ -54,13 +51,25 @@ public:
bool mapsToSampler,
Vector<ShaderComponent*> &componentList );
static Var* getInColor( const char *name,
const char *type,
Vector<ShaderComponent*> &componentList );
///
static Var* addOutVpos( MultiLine *meta,
Vector<ShaderComponent*> &componentList );
/// Returns the VPOS input register for the pixel shader.
static Var* getInVpos( MultiLine *meta,
Vector<ShaderComponent*> &componentList );
/// Returns the "objToTangentSpace" transform or creates one if this
/// is the first feature to need it.
Var* getOutObjToTangentSpace( Vector<ShaderComponent*> &componentList,
MultiLine *meta,
const MaterialFeatureData &fd );
/// Returns the existing output "worldToTangent" transform or
/// Returns the existing output "outWorldToTangent" transform or
/// creates one if this is the first feature to need it.
Var* getOutWorldToTangent( Vector<ShaderComponent*> &componentList,
MultiLine *meta,
@ -70,7 +79,7 @@ public:
/// adding it to the input connector if it doesn't exist.
static Var* getInWorldToTangent( Vector<ShaderComponent*> &componentList );
/// Returns the existing output "viewToTangent" transform or
/// Returns the existing output "outViewToTangent" transform or
/// creates one if this is the first feature to need it.
Var* getOutViewToTangent( Vector<ShaderComponent*> &componentList,
MultiLine *meta,
@ -81,17 +90,16 @@ public:
static Var* getInViewToTangent( Vector<ShaderComponent*> &componentList );
/// Calculates the world space position in the vertex shader and
/// assigns it to the passed language element. It does not pass /// it across the connector to the pixel shader.
/// assigns it to the passed language element. It does not pass
/// it across the connector to the pixel shader.
/// @see addOutWsPosition
void getWsPosition( Vector<ShaderComponent*> &componentList,
bool useInstancing,
MultiLine *meta,
LangElement *wsPosition );
/// Adds the "wsPosition" to the input connector if it doesn't exist.
Var* addOutWsPosition( Vector<ShaderComponent*> &componentList,
bool useInstancing,
MultiLine *meta );
@ -129,7 +137,6 @@ public:
bool useInstancing,
MultiLine *meta );
// ShaderFeature
Var* getVertTexCoord( const String &name );
LangElement* setupTexSpaceMat( Vector<ShaderComponent*> &componentList, Var **texSpaceMat );
@ -151,25 +158,27 @@ public:
virtual String getName() { return mName; }
};
class RenderTargetZeroGLSL : public ShaderFeatureGLSL
{
protected: ShaderFeature::OutputTarget mOutputTargetMask;
protected:
ShaderFeature::OutputTarget mOutputTargetMask;
String mFeatureName;
public:
RenderTargetZeroGLSL( const ShaderFeature::OutputTarget target )
: mOutputTargetMask( target )
{
char buffer[256]; dSprintf(buffer, sizeof(buffer), "Render Target Output = 0.0, output mask %04b", mOutputTargetMask);
mFeatureName = buffer; }
char buffer[256];
dSprintf(buffer, sizeof(buffer), "Render Target Output = 0.0, output mask %04b", mOutputTargetMask);
mFeatureName = buffer;
}
virtual String getName() { return mFeatureName; }
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return
mOutputTargetMask; }
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return mOutputTargetMask; }
};
@ -190,11 +199,7 @@ public:
U32 stageNum,
const FeatureType &type,
const FeatureSet &features,
MaterialFeatureData *outFeatureData )
{
// This feature is always on!
outFeatureData->features.addFeature( type );
}
MaterialFeatureData *outFeatureData );
};
@ -297,7 +302,6 @@ public:
}
};
/// Diffuse vertex color
class DiffuseVertColorFeatureGLSL : public ShaderFeatureGLSL
{
@ -316,7 +320,6 @@ public:
}
};
/// Lightmap
class LightmapFeatGLSL : public ShaderFeatureGLSL
{
@ -491,7 +494,14 @@ public:
/// Visibility
class VisibilityFeatGLSL : public ShaderFeatureGLSL
{
protected:
ShaderIncludeDependency mTorqueDep;
public:
VisibilityFeatGLSL();
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
@ -500,11 +510,6 @@ public:
virtual Resources getResources( const MaterialFeatureData &fd );
virtual void setTexData( Material::StageData &stageDat,
const MaterialFeatureData &fd,
RenderPassData &passData,
U32 &texIndex );
virtual Material::BlendOp getBlendOp() { return Material::None; }
virtual String getName()
@ -547,10 +552,10 @@ public:
}
};
/// This should be the final feature on most pixel shaders which
/// encodes the color for the current HDR target format.
/// @see HDRPostFx/// @see LightManager
/// @see HDRPostFx
/// @see LightManager
/// @see torque.glsl
class HDROutGLSL : public ShaderFeatureGLSL
{
@ -570,9 +575,9 @@ public:
virtual String getName() { return "HDR Output"; }
};
///
class FoliageFeatureGLSL : public ShaderFeatureGLSL{
class FoliageFeatureGLSL : public ShaderFeatureGLSL
{
protected:
ShaderIncludeDependency mDep;
@ -583,6 +588,7 @@ public:
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
@ -597,11 +603,10 @@ public:
const FeatureType &type,
const FeatureSet &features,
MaterialFeatureData *outFeatureData );
virtual ShaderFeatureConstHandles* createConstHandles( GFXShader *shader, SimObject *userObject );
};
///
class ParticleNormalFeatureGLSL : public ShaderFeatureGLSL
{
public:
@ -616,6 +621,9 @@ public:
};
/// Special feature for unpacking imposter verts.
/// @see RenderImposterMgr
class ImposterVertFeatureGLSL : public ShaderFeatureGLSL
{
protected:
@ -623,9 +631,12 @@ protected:
ShaderIncludeDependency mDep;
public:
ImposterVertFeatureGLSL();
ImposterVertFeatureGLSL();
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );

View file

@ -56,7 +56,9 @@ void ShaderGenPrinterGLSL::printMainComment( Stream& stream )
void ShaderGenPrinterGLSL::printVertexShaderCloser( Stream& stream )
{
const char *closer = "}\r\n";
// We are render OpenGL upside down for use DX9 texture coords.
// Must be the last vertex feature.
const char *closer = " gl_Position.y *= -1;\r\n}\r\n";
stream.write( dStrlen(closer), closer );
}
@ -67,7 +69,7 @@ void ShaderGenPrinterGLSL::printPixelShaderOutputStruct( Stream& stream, const M
void ShaderGenPrinterGLSL::printPixelShaderCloser( Stream& stream )
{
const char *closer = " gl_FragColor = col;\r\n}\r\n";
const char *closer = " OUT_FragColor0 = col;\r\n}\r\n";
stream.write( dStrlen(closer), closer );
}
@ -124,6 +126,11 @@ ShaderComponent* ShaderGenComponentFactoryGLSL::createVertexInputConnector( cons
var = vertComp->getElement( RT_TANGENT );
var->setName( "T" );
}
else if ( element.isSemantic( GFXSemantic::TANGENTW ) )
{
var = vertComp->getElement( RT_TANGENTW );
var->setName( "tangentW" );
}
else if ( element.isSemantic( GFXSemantic::BINORMAL ) )
{
var = vertComp->getElement( RT_BINORMAL );
@ -152,7 +159,7 @@ ShaderComponent* ShaderGenComponentFactoryGLSL::createVertexInputConnector( cons
if ( !var )
continue;
var->setStructName( "" );
var->setStructName( "IN" );
var->setType( typeToString( element.getType() ) );
}

View file

@ -76,6 +76,8 @@ void _initShaderGenGLSL( ShaderGen *shaderGen )
FEATUREMGR->registerFeature( MFT_ParaboloidVertTransform, new ParaboloidVertTransformGLSL );
FEATUREMGR->registerFeature( MFT_IsSinglePassParaboloid, new NamedFeatureGLSL( "Single Pass Paraboloid" ) );
FEATUREMGR->registerFeature( MFT_UseInstancing, new NamedFeatureGLSL( "Hardware Instancing" ) );
FEATUREMGR->registerFeature( MFT_RenderTarget1_Zero, new RenderTargetZeroGLSL
( ShaderFeature::RenderTarget1 ) );
@ -89,6 +91,10 @@ void _initShaderGenGLSL( ShaderGen *shaderGen )
FEATUREMGR->registerFeature( MFT_ImposterVert, new ImposterVertFeatureGLSL );
//FEATUREMGR->registerFeature( MFT_LightbufferMRT, new NamedFeatureGLSL( "Lightbuffer MRT" ) );
//FEATUREMGR->registerFeature( MFT_IsTranslucentZWrite, new NamedFeatureGLSL( "Translucent ZWrite" ) );
//FEATUREMGR->registerFeature( MFT_InterlacedPrePass, new NamedFeatureGLSL( "Interlaced Pre Pass" ) );
}
MODULE_BEGIN( ShaderGenGLSL )