Engine directory for ticket #1

This commit is contained in:
DavidWyand-GG 2012-09-19 11:15:01 -04:00
parent 352279af7a
commit 7dbfe6994d
3795 changed files with 1363358 additions and 0 deletions

View file

@ -0,0 +1,448 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "shaderGen/GLSL/bumpGLSL.h"
#include "shaderGen/shaderOp.h"
#include "gfx/gfxDevice.h"
#include "materials/matInstance.h"
#include "materials/processedMaterial.h"
#include "materials/materialFeatureTypes.h"
#include "shaderGen/shaderGenVars.h"
void BumpFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
MultiLine *meta = new MultiLine;
output = meta;
const bool useTexAnim = fd.features[MFT_TexAnim];
// Output the texture coord.
getOutTexCoord( "texCoord",
"vec2",
true,
useTexAnim,
meta,
componentList );
if ( fd.features.hasFeature( MFT_DetailNormalMap ) )
addOutDetailTexCoord( componentList,
meta,
useTexAnim );
// Also output the worldToTanget transform which
// we use to create the world space normal.
getOutWorldToTangent( componentList, meta, fd );
}
void BumpFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
MultiLine *meta = new MultiLine;
output = meta;
// Get the texture coord.
Var *texCoord = getInTexCoord( "out_texCoord", "vec2", true, componentList );
// Sample the bumpmap.
Var *bumpMap = getNormalMapTex();
LangElement *texOp = NULL;
//Handle atlased textures
if(fd.features[MFT_NormalMapAtlas])
{
// This is a big block of code, so put a comment in the shader code
meta->addStatement( new GenOp( " // Atlased texture coordinate calculation (see BumpFeat*LSL for details)\r\n") );
Var *atlasedTex = new Var;
atlasedTex->setName("atlasedBumpCoord");
atlasedTex->setType("vec2");
LangElement *atDecl = new DecOp(atlasedTex);
// Parameters of the texture atlas
Var *atParams = new Var;
atParams->setType("vec4");
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->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));
// 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));
}
else
{
meta->addStatement(new GenOp(" vec2 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));
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",
atlasedTex, atlasedTex, atParams, atParams, tileParams));
// Add a newline
meta->addStatement(new GenOp( "\r\n"));
if(is_sm3)
{
texOp = new GenOp( "texture2DLod(@, vec4(@, 0.0, mipLod_bump)", bumpMap, texCoord );
}
else
{
texOp = new GenOp( "texture2D(@, @)", bumpMap, texCoord );
}
}
else
{
texOp = new GenOp( "texture2D(@, @)", bumpMap, texCoord );
}
Var *bumpNorm = new Var( "bumpNormal", "vec4" );
meta->addStatement( expandNormalMap( texOp, new DecOp( bumpNorm ), bumpNorm, fd ) );
// If we have a detail normal map we add the xy coords of
// it to the base normal map. This gives us the effect we
// want with few instructions and minial artifacts.
if ( fd.features.hasFeature( MFT_DetailNormalMap ) )
{
bumpMap = new Var;
bumpMap->setType( "sampler2D" );
bumpMap->setName( "detailBumpMap" );
bumpMap->uniform = true;
bumpMap->sampler = true;
bumpMap->constNum = Var::getTexUnitNum();
texCoord = getInTexCoord( "detCoord", "vec2", true, componentList );
texOp = new GenOp( "texture2D(@, @)", bumpMap, texCoord );
Var *detailBump = new Var;
detailBump->setName( "detailBump" );
detailBump->setType( "vec4" );
meta->addStatement( expandNormalMap( texOp, new DecOp( detailBump ), detailBump, fd ) );
Var *detailBumpScale = new Var;
detailBumpScale->setType( "float" );
detailBumpScale->setName( "detailBumpStrength" );
detailBumpScale->uniform = true;
detailBumpScale->constSortPos = cspPass;
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 ) );
}
ShaderFeature::Resources BumpFeatGLSL::getResources( const MaterialFeatureData &fd )
{
Resources res;
// If we have no parallax then we bring on the normal tex.
if ( !fd.features[MFT_Parallax] )
res.numTex = 1;
// Only the parallax or diffuse map will add texture
// coords other than us.
if ( !fd.features[MFT_Parallax] &&
!fd.features[MFT_DiffuseMap] &&
!fd.features[MFT_OverlayMap] &&
!fd.features[MFT_DetailMap] )
res.numTexReg++;
// We pass the world to tanget space transform.
res.numTexReg += 3;
// Do we have detail normal mapping?
if ( fd.features[MFT_DetailNormalMap] )
{
res.numTex++;
if ( !fd.features[MFT_DetailMap] )
res.numTexReg++;
}
return res;
}
void BumpFeatGLSL::setTexData( Material::StageData &stageDat,
const MaterialFeatureData &fd,
RenderPassData &passData,
U32 &texIndex )
{
// If we had a parallax feature then it takes
// care of hooking up the normal map texture.
if ( fd.features[MFT_Parallax] )
return;
if ( fd.features[MFT_NormalMap] )
{
passData.mTexType[ texIndex ] = Material::Bump;
passData.mTexSlot[ texIndex++ ].texObject = stageDat.getTex( MFT_NormalMap );
}
if ( fd.features[ MFT_DetailNormalMap ] )
{
passData.mTexType[ texIndex ] = Material::DetailBump;
passData.mTexSlot[ texIndex++ ].texObject = stageDat.getTex( MFT_DetailNormalMap );
}
}
//
Var* ParallaxFeatGLSL::_getUniformVar( const char *name, const char *type )
{
Var *theVar = (Var*)LangElement::find( name );
if ( !theVar )
{
theVar = new Var;
theVar->setType( type );
theVar->setName( name );
theVar->uniform = true;
theVar->constSortPos = cspPass;
}
return theVar;
}
void ParallaxFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
AssertFatal( GFX->getPixelShaderVersion() >= 2.0,
"ParallaxFeatGLSL::processVert - We don't support SM 1.x!" );
MultiLine *meta = new MultiLine;
// Add the texture coords.
getOutTexCoord( "texCoord",
"vec2",
true,
fd.features[MFT_TexAnim],
meta,
componentList );
// Grab the input position.
Var *inPos = (Var*)LangElement::find( "inPosition" );
if ( !inPos )
inPos = (Var*)LangElement::find( "position" );
// Get the object space eye position and the world
// to tangent transform.
Var *eyePos = _getUniformVar( "eyePos", "vec3" );
Var *objToTangentSpace = getOutObjToTangentSpace( componentList, meta, fd );
// send transform to 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 ) );
output = meta;
}
void ParallaxFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
AssertFatal( GFX->getPixelShaderVersion() >= 2.0,
"ParallaxFeatGLSL::processPix - We don't support SM 1.x!" );
MultiLine *meta = new MultiLine;
// Order matters... get this first!
Var *texCoord = getInTexCoord( "texCoord", "vec2", true, componentList );
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
// We need the negative tangent space view vector
// as in parallax mapping we step towards the camera.
Var *negViewTS = (Var*)LangElement::find( "negViewTS" );
if ( !negViewTS )
{
Var *inViewTS = (Var*)LangElement::find( "outViewTS" );
if ( !inViewTS )
{
inViewTS = connectComp->getElement( RT_TEXCOORD, 1 );
inViewTS->setName( "outViewTS" );
inViewTS->setType( "vec3" );
}
negViewTS = new Var( "negViewTS", "vec3" );
meta->addStatement( new GenOp( " @ = -normalize( @ );\r\n", new DecOp( negViewTS ), inViewTS ) );
}
// Get the rest of our inputs.
Var *parallaxInfo = _getUniformVar( "parallaxInfo", "float" );
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 ) );
// TODO: Fix second UV.
output = meta;
}
ShaderFeature::Resources ParallaxFeatGLSL::getResources( const MaterialFeatureData &fd )
{
AssertFatal( GFX->getPixelShaderVersion() >= 2.0,
"ParallaxFeatGLSL::getResources - We don't support SM 1.x!" );
Resources res;
// We add the outViewTS to the outputstructure.
res.numTexReg = 1;
// If this isn't a prepass then we will be
// creating the normal map here.
if ( !fd.features.hasFeature( MFT_PrePassConditioner ) )
res.numTex = 1;
return res;
}
void ParallaxFeatGLSL::setTexData( Material::StageData &stageDat,
const MaterialFeatureData &fd,
RenderPassData &passData,
U32 &texIndex )
{
AssertFatal( GFX->getPixelShaderVersion() >= 2.0,
"ParallaxFeatGLSL::setTexData - We don't support SM 1.x!" );
GFXTextureObject *tex = stageDat.getTex( MFT_NormalMap );
if ( tex )
{
passData.mTexType[ texIndex ] = Material::Bump;
passData.mTexSlot[ texIndex++ ].texObject = tex;
}
}
//
void NormalsOutFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
// If we have normal maps then we can count
// on it to generate the world space normal.
if ( fd.features[MFT_NormalMap] )
return;
MultiLine *meta = new MultiLine;
output = meta;
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *outNormal = connectComp->getElement( RT_TEXCOORD );
outNormal->setName( "wsNormal" );
outNormal->setType( "vec3" );
outNormal->mapsToSampler = false;
// Find the incoming vertex normal.
Var *inNormal = (Var*)LangElement::find( "normal" );
if ( inNormal )
{
// 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 ) );
}
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 ) );
}
}
void NormalsOutFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
MultiLine *meta = new MultiLine;
output = meta;
Var *wsNormal = (Var*)LangElement::find( "wsNormal" );
if ( !wsNormal )
{
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
wsNormal = connectComp->getElement( RT_TEXCOORD );
wsNormal->setName( "wsNormal" );
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 ) );
}
LangElement *normalOut;
Var *outColor = (Var*)LangElement::find( "col" );
if ( outColor )
normalOut = new GenOp( "vec4( ( -@ + 1 ) * 0.5, @.a )", wsNormal, outColor );
else
normalOut = new GenOp( "vec4( ( -@ + 1 ) * 0.5, 1 )", wsNormal );
meta->addStatement( new GenOp( " @;\r\n",
assignColor( normalOut, Material::None ) ) );
}

View file

@ -0,0 +1,99 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _BUMP_GLSL_H_
#define _BUMP_GLSL_H_
#ifndef _SHADERGEN_GLSL_SHADERFEATUREGLSL_H_
#include "shaderGen/GLSL/shaderFeatureGLSL.h"
#endif
struct RenderPassData;
class MultiLine;
/// The Bumpmap feature will read the normal map and
/// transform it by the inverse of the worldToTanget
/// matrix. This normal is then used by subsequent
/// shader features.
class BumpFeatGLSL : public ShaderFeatureGLSL
{
public:
// ShaderFeatureGLSL
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Material::BlendOp getBlendOp(){ return Material::LerpAlpha; }
virtual Resources getResources( const MaterialFeatureData &fd );
virtual void setTexData( Material::StageData &stageDat,
const MaterialFeatureData &fd,
RenderPassData &passData,
U32 &texIndex );
virtual String getName() { return "Bumpmap"; }
};
/// This feature either generates the cheap yet effective offset
/// mapping style parallax or the much more expensive occlusion
/// mapping technique based on the enabled feature flags.
class ParallaxFeatGLSL : public ShaderFeatureGLSL
{
protected:
static Var* _getUniformVar( const char *name, const char *type );
public:
// ShaderFeatureGLSL
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Resources getResources( const MaterialFeatureData &fd );
virtual void setTexData( Material::StageData &stageDat,
const MaterialFeatureData &fd,
RenderPassData &passData,
U32 &texIndex );
virtual String getName() { return "Parallax"; }
};
/// This feature is used to render normals to the
/// diffuse target for imposter rendering.
class NormalsOutFeatGLSL : public ShaderFeatureGLSL
{
public:
// ShaderFeatureGLSL
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Material::BlendOp getBlendOp(){ return Material::LerpAlpha; }
virtual String getName() { return "NormalsOut"; }
};
#endif // _BUMP_GLSL_H_

View file

@ -0,0 +1,155 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "shaderGen/GLSL/depthGLSL.h"
#include "materials/materialFeatureTypes.h"
void EyeSpaceDepthOutGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
MultiLine *meta = new MultiLine;
output = meta;
// 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" );
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->setName("eyePosWorld");
eyePos->uniform = true;
eyePos->constSortPos = cspPass;
}
meta->addStatement( new GenOp( " @ = vec4( @.xyz - @, 1 );\r\n", outWSEyeVec, wsPosition, eyePos ) );
}
void EyeSpaceDepthOutGLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
MultiLine *meta = new MultiLine;
// grab connector position
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *wsEyeVec = connectComp->getElement( RT_TEXCOORD );
wsEyeVec->setName( "outWSEyeVec" );
wsEyeVec->setType( "vec4" );
wsEyeVec->mapsToSampler = false;
wsEyeVec->uniform = false;
// get shader constants
Var *vEye = new Var;
vEye->setType("vec3");
vEye->setName("vEye");
vEye->uniform = true;
vEye->constSortPos = cspPass;
// Expose the depth to the depth format feature
Var *depthOut = new Var;
depthOut->setType("float");
depthOut->setName(getOutputVarName());
LangElement *depthOutDecl = new DecOp( depthOut );
meta->addStatement( new GenOp( " @ = dot(@, (@.xyz / @.w));\r\n", depthOutDecl, vEye, wsEyeVec, wsEyeVec ) );
// 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 ) ) );
output = meta;
}
ShaderFeature::Resources EyeSpaceDepthOutGLSL::getResources( const MaterialFeatureData &fd )
{
Resources temp;
// Passing from VS->PS:
// - world space position (wsPos)
temp.numTexReg = 1;
return temp;
}
void DepthOutGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
// Grab the output vert.
Var *outPosition = (Var*)LangElement::find( "gl_Position" );
// Grab our output depth.
Var *outDepth = connectComp->getElement( RT_TEXCOORD );
outDepth->setName( "outDepth" );
outDepth->setType( "float" );
output = new GenOp( " @ = @.z / @.w;\r\n", outDepth, outPosition, outPosition );
}
void DepthOutGLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
// grab connector position
Var *depthVar = connectComp->getElement( RT_TEXCOORD );
depthVar->setName( "outDepth" );
depthVar->setType( "float" );
depthVar->mapsToSampler = false;
depthVar->uniform = false;
/*
// Expose the depth to the depth format feature
Var *depthOut = new Var;
depthOut->setType("float");
depthOut->setName(getOutputVarName());
*/
LangElement *depthOut = new GenOp( "vec4( @, @ * @, 0, 1 )", depthVar, depthVar, depthVar );
output = new GenOp( " @;\r\n", assignColor( depthOut, Material::None ) );
}
ShaderFeature::Resources DepthOutGLSL::getResources( const MaterialFeatureData &fd )
{
// We pass the depth to the pixel shader.
Resources temp;
temp.numTexReg = 1;
return temp;
}

View file

@ -0,0 +1,60 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _DEPTH_GLSL_H_
#define _DEPTH_GLSL_H_
#ifndef _SHADERGEN_GLSL_SHADERFEATUREGLSL_H_
#include "shaderGen/GLSL/shaderFeatureGLSL.h"
#endif
#ifndef _SHADEROP_H_
#include "shaderGen/shaderOp.h"
#endif
class EyeSpaceDepthOutGLSL : public ShaderFeatureGLSL
{
public:
// ShaderFeature
virtual void processVert( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd );
virtual Resources getResources( const MaterialFeatureData &fd );
virtual String getName() { return "Eye Space Depth (Out)"; }
virtual Material::BlendOp getBlendOp() { return Material::None; }
virtual const char* getOutputVarName() const { return "eyeSpaceDepth"; }
};
class DepthOutGLSL : public ShaderFeatureGLSL
{
public:
// ShaderFeature
virtual void processVert( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd );
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"; }
};
#endif // _DEPTH_GLSL_H_

View file

@ -0,0 +1,158 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "shaderGen/GLSL/paraboloidGLSL.h"
#include "lighting/lightInfo.h"
#include "materials/sceneData.h"
#include "materials/materialFeatureTypes.h"
#include "materials/materialFeatureData.h"
#include "gfx/gfxShader.h"
void ParaboloidVertTransformGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
MultiLine *meta = new MultiLine;
// First check for an input position from a previous feature
// then look for the default vertex position.
Var *inPosition = (Var*)LangElement::find( "inPosition" );
if ( !inPosition )
inPosition = (Var*)LangElement::find( "position" );
const bool isSinglePass = fd.features[ MFT_IsSinglePassParaboloid ];
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
// Grab connector out position.
Var *outPosition = connectComp->getElement( RT_POSITION );
outPosition->setName( "gl_Position" );
// Get the atlas scale.
Var *atlasScale = new Var;
atlasScale->setType( "vec2" );
atlasScale->setName( "atlasScale" );
atlasScale->uniform = true;
atlasScale->constSortPos = cspPass;
// Transform into camera space
Var *worldViewOnly = getWorldView( componentList, fd.features[MFT_UseInstancing], meta );
// So what we're doing here is transforming into camera space, and
// then directly manipulate into shadowmap space.
//
// 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( " float L = length(@.xyz);\r\n", outPosition ) );
if ( isSinglePass )
{
// Flip the z in the back case
Var *outIsBack = connectComp->getElement( RT_TEXCOORD );
outIsBack->setType( "float" );
outIsBack->setName( "outIsBack" );
meta->addStatement( new GenOp( " bool isBack = @.z < 0.0;\r\n", outPosition ) );
meta->addStatement( new GenOp( " @ = isBack ? -1.0 : 1.0;\r\n", outIsBack ) );
meta->addStatement( new GenOp( " if ( isBack ) @.z = -@.z;\r\n", outPosition, outPosition ) );
}
meta->addStatement( new GenOp( " @ /= L;\r\n", outPosition ) );
meta->addStatement( new GenOp( " @.z = @.z + 1.0;\r\n", outPosition, outPosition ) );
meta->addStatement( new GenOp( " @.xy /= @.z;\r\n", outPosition, outPosition ) );
// Get the light parameters.
Var *lightParams = new Var;
lightParams->setType( "vec4" );
lightParams->setName( "lightParams" );
lightParams->uniform = true;
lightParams->constSortPos = cspPass;
// TODO: If we change other shadow shaders to write out
// linear depth, than fix this as well!
//
// (L - 1.0)/(lightParams.x - 1.0);
//
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" );
meta->addStatement( new GenOp( " @ = @.xy;\r\n", outPosXY, outPosition ) );
// Scale and offset so it shows up in the atlas properly.
meta->addStatement( new GenOp( " @.xy *= @.xy;\r\n", outPosition, atlasScale ) );
if ( isSinglePass )
meta->addStatement( new GenOp( " @.x += isBack ? 0.5 : -0.5;\r\n", outPosition ) );
else
{
Var *atlasOffset = new Var;
atlasOffset->setType( "vec2" );
atlasOffset->setName( "atlasXOffset" );
atlasOffset->uniform = true;
atlasOffset->constSortPos = cspPass;
meta->addStatement( new GenOp( " @.xy += @;\r\n", outPosition, atlasOffset ) );
}
output = meta;
}
void ParaboloidVertTransformGLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
MultiLine *meta = new MultiLine;
const bool isSinglePass = fd.features[ MFT_IsSinglePassParaboloid ];
if ( isSinglePass )
{
// Cull things on the back side of the map.
Var *isBack = connectComp->getElement( RT_TEXCOORD );
isBack->setName( "outIsBack" );
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 ) );
output = meta;
}
ShaderFeature::Resources ParaboloidVertTransformGLSL::getResources( const MaterialFeatureData &fd )
{
Resources temp;
temp.numTexReg = 2;
return temp;
}

View file

@ -0,0 +1,48 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _PARABOLOID_GLSL_H_
#define _PARABOLOID_GLSL_H_
#ifndef _SHADERGEN_GLSL_SHADERFEATUREGLSL_H_
#include "shaderGen/GLSL/shaderFeatureGLSL.h"
#endif
#ifndef _SHADEROP_H_
#include "shaderGen/shaderOp.h"
#endif
class GFXShaderConstHandle;
class ParaboloidVertTransformGLSL : public ShaderFeatureGLSL
{
public:
// ShaderFeature
virtual void processVert( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd );
virtual Resources getResources( const MaterialFeatureData &fd );
virtual String getName() { return "Paraboloid Vert Transform"; }
virtual Material::BlendOp getBlendOp() { return Material::None; }
};
#endif // _PARABOLOID_GLSL_H_

View file

@ -0,0 +1,208 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "shaderGen/GLSL/pixSpecularGLSL.h"
#include "materials/processedMaterial.h"
#include "materials/materialFeatureTypes.h"
#include "shaderGen/shaderOp.h"
#include "shaderGen/shaderGenVars.h"
#include "gfx/gfxStructs.h"
PixelSpecularGLSL::PixelSpecularGLSL()
: mDep( "shaders/common/gl/lighting.glsl" )
{
addDependency( &mDep );
}
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;
*/
}
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] );
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 *final = specMul;
// mask out with lightmap if present
if( fd.features[MFT_LightMap] )
{
LangElement *lmColor = NULL;
// find lightmap color
lmColor = LangElement::find( "lmColor" );
if ( !lmColor )
{
LangElement * lightMap = LangElement::find( "lightMap" );
LangElement * lmCoord = LangElement::find( "texCoord2" );
lmColor = new GenOp( "tex2D(@, @)", lightMap, lmCoord );
}
final = new GenOp( "@ * float4(@.rgb,0)", specMul, lmColor );
}
// We we have a normal map then mask the specular
if ( !fd.features[MFT_SpecularMap] && fd.features[MFT_NormalMap] )
{
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 ) ) );
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 );
// create texture var
Var *specularMap = new Var;
specularMap->setType( "sampler2D" );
specularMap->setName( "specularMap" );
specularMap->uniform = true;
specularMap->sampler = true;
specularMap->constNum = Var::getTexUnitNum();
LangElement *texOp = new GenOp( "texture2D(@, @)", specularMap, texCoord );
Var *specularColor = new Var( "specularColor", "vec4" );
output = new GenOp( " @ = @;\r\n", new DecOp( specularColor ), texOp );
}
ShaderFeature::Resources SpecularMapGLSL::getResources( const MaterialFeatureData &fd )
{
Resources res;
res.numTex = 1;
return res;
}
void SpecularMapGLSL::setTexData( Material::StageData &stageDat,
const MaterialFeatureData &fd,
RenderPassData &passData,
U32 &texIndex )
{
GFXTextureObject *tex = stageDat.getTex( MFT_SpecularMap );
if ( tex )
{
passData.mTexType[ texIndex ] = Material::Standard;
passData.mTexSlot[ texIndex++ ].texObject = tex;
}
}

View file

@ -0,0 +1,79 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _PIXSPECULAR_GLSL_H_
#define _PIXSPECULAR_GLSL_H_
#ifndef _SHADERGEN_GLSL_SHADERFEATUREGLSL_H_
#include "shaderGen/GLSL/shaderFeatureGLSL.h"
#endif
/// A per-pixel specular feature.
class PixelSpecularGLSL : public ShaderFeatureGLSL
{
protected:
ShaderIncludeDependency mDep;
public:
PixelSpecularGLSL();
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Resources getResources( const MaterialFeatureData &fd );
virtual String getName()
{
return "Pixel Specular";
}
};
/// A texture source for the PixSpecular feature
class SpecularMapGLSL : public ShaderFeatureGLSL
{
public:
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Resources getResources( const MaterialFeatureData &fd );
virtual void setTexData( Material::StageData &stageDat,
const MaterialFeatureData &fd,
RenderPassData &passData,
U32 &texIndex );
virtual String getName()
{
return "Specular Map";
}
};
#endif // _PIXSPECULAR_GLSL_H_

View file

@ -0,0 +1,263 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "shaderGen/GLSL/shaderCompGLSL.h"
#include "shaderGen/shaderComp.h"
#include "shaderGen/langElement.h"
#include "gfx/gfxDevice.h"
Var * AppVertConnectorGLSL::getElement( RegisterType type,
U32 numElements,
U32 numRegisters )
{
switch( type )
{
case RT_POSITION:
{
Var *newVar = new Var;
mElementList.push_back( newVar );
newVar->setConnectName( "gl_Vertex" );
return newVar;
}
case RT_NORMAL:
{
Var *newVar = new Var;
mElementList.push_back( newVar );
newVar->setConnectName( "gl_Normal" );
return newVar;
}
case RT_COLOR:
{
Var *newVar = new Var;
mElementList.push_back( newVar );
newVar->setConnectName( "gl_Color" );
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 );
newVar->setConnectName( out );
newVar->constNum = mCurTexElem;
newVar->arraySize = numElements;
if ( numRegisters != -1 )
mCurTexElem += numRegisters;
else
mCurTexElem += numElements;
return newVar;
}
default:
break;
}
return NULL;
}
void AppVertConnectorGLSL::sortVars()
{
// Not required in GLSL
}
void AppVertConnectorGLSL::setName( char *newName )
{
dStrcpy( (char*)mName, newName );
}
void AppVertConnectorGLSL::reset()
{
for( U32 i=0; i<mElementList.size(); i++ )
{
mElementList[i] = NULL;
}
mElementList.setSize( 0 );
mCurTexElem = 0;
}
void AppVertConnectorGLSL::print( Stream &stream )
{
// print out elements
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";
else
swizzle = "xyzw";
// 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 );
stream.write( dStrlen((char*)output), output );
}
}
Var * VertPixelConnectorGLSL::getElement( RegisterType type,
U32 numElements,
U32 numRegisters )
{
switch( type )
{
case RT_POSITION:
case RT_NORMAL:
case RT_COLOR:
{
Var *newVar = new Var;
mElementList.push_back( newVar );
return newVar;
}
case RT_TEXCOORD:
case RT_BINORMAL:
case RT_TANGENT:
{
Var *newVar = new Var;
newVar->arraySize = numElements;
if ( numRegisters != -1 )
mCurTexElem += numRegisters;
else
mCurTexElem += numElements;
mElementList.push_back( newVar );
return newVar;
}
default:
break;
}
return NULL;
}
void VertPixelConnectorGLSL::sortVars()
{
// Not needed in GLSL
}
void VertPixelConnectorGLSL::setName( char *newName )
{
dStrcpy( (char*)mName, newName );
}
void VertPixelConnectorGLSL::reset()
{
for( U32 i=0; i<mElementList.size(); i++ )
{
mElementList[i] = NULL;
}
mElementList.setSize( 0 );
mCurTexElem = 0;
}
void VertPixelConnectorGLSL::print( Stream &stream )
{
// 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(var->arraySize <= 1)
dSprintf((char*)output, sizeof(output), "varying %s %s;\r\n", var->type, var->name);
else
dSprintf((char*)output, sizeof(output), "varying %s %s[%d];\r\n", var->type, var->name, var->arraySize);
stream.write( dStrlen((char*)output), output );
}
}
void VertexParamsDefGLSL::print( Stream &stream )
{
// find all the uniform variables and print them out
for( U32 i=0; i<LangElement::elementList.size(); i++)
{
Var *var = dynamic_cast<Var*>(LangElement::elementList[i]);
if( var )
{
if( var->uniform )
{
U8 output[256];
if(var->arraySize <= 1)
dSprintf((char*)output, sizeof(output), "uniform %-8s %-15s;\r\n", var->type, var->name);
else
dSprintf((char*)output, sizeof(output), "uniform %-8s %-15s[%d];\r\n", var->type, var->name, var->arraySize);
stream.write( dStrlen((char*)output), output );
}
}
}
const char *closer = "\r\n\r\nvoid main()\r\n{\r\n";
stream.write( dStrlen(closer), closer );
}
void PixelParamsDefGLSL::print( Stream &stream )
{
// find all the uniform variables and print them out
for( U32 i=0; i<LangElement::elementList.size(); i++)
{
Var *var = dynamic_cast<Var*>(LangElement::elementList[i]);
if( var )
{
if( var->uniform )
{
U8 output[256];
if(var->arraySize <= 1)
dSprintf((char*)output, sizeof(output), "uniform %-8s %-15s;\r\n", var->type, var->name);
else
dSprintf((char*)output, sizeof(output), "uniform %-8s %-15s[%d];\r\n", var->type, var->name, var->arraySize);
stream.write( dStrlen((char*)output), output );
}
}
}
const char *closer = "\r\nvoid main()\r\n{\r\n";
stream.write( dStrlen(closer), closer );
}

View file

@ -0,0 +1,73 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _SHADERCOMP_GLSL_H_
#define _SHADERCOMP_GLSL_H_
#ifndef _SHADERCOMP_H_
#include "shaderGen/shaderComp.h"
#endif
class VertPixelConnectorGLSL : public ShaderConnector
{
public:
// ShaderConnector
virtual Var* getElement( RegisterType type,
U32 numElements = 1,
U32 numRegisters = -1 );
virtual void setName( char *newName );
virtual void reset();
virtual void sortVars();
virtual void print( Stream &stream );
};
class AppVertConnectorGLSL : public ShaderConnector
{
public:
virtual Var* getElement( RegisterType type,
U32 numElements = 1,
U32 numRegisters = -1 );
virtual void setName( char *newName );
virtual void reset();
virtual void sortVars();
virtual void print( Stream &stream );
};
class VertexParamsDefGLSL : public ParamsDef
{
public:
virtual void print( Stream &stream );
};
class PixelParamsDefGLSL : public ParamsDef
{
public:
virtual void print( Stream &stream );
};
#endif // _SHADERCOMP_GLSL_H_

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,643 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _SHADERGEN_GLSL_SHADERFEATUREGLSL_H_
#define _SHADERGEN_GLSL_SHADERFEATUREGLSL_H_
#ifndef _SHADERFEATURE_H_
#include "shaderGen/shaderFeature.h"
#endif
#ifndef _MATERIALFEATUREDATA_H_
#include "materials/materialFeatureData.h"
#endif
struct LangElement;
struct MaterialFeatureData;
struct RenderPassData;
class ShaderFeatureGLSL : public ShaderFeature
{
public:
ShaderFeatureGLSL();
///
Var* getOutTexCoord( const char *name,
const char *type,
bool mapsToSampler,
bool useTexAnim,
MultiLine *meta,
Vector<ShaderComponent*> &componentList );
/// Returns an input texture coord by name adding it
/// to the input connector if it doesn't exist.
static Var* getInTexCoord( const char *name,
const char *type,
bool mapsToSampler,
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
/// creates one if this is the first feature to need it.
Var* getOutWorldToTangent( Vector<ShaderComponent*> &componentList,
MultiLine *meta,
const MaterialFeatureData &fd );
/// Returns the input "worldToTanget" space transform
/// adding it to the input connector if it doesn't exist.
static Var* getInWorldToTangent( Vector<ShaderComponent*> &componentList );
/// Returns the existing output "viewToTangent" transform or
/// creates one if this is the first feature to need it.
Var* getOutViewToTangent( Vector<ShaderComponent*> &componentList,
MultiLine *meta,
const MaterialFeatureData &fd );
/// Returns the input "viewToTangent" space transform
/// adding it to the input connector if it doesn't exist.
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.
/// @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 );
/// Returns the input world space position from the connector.
static Var* getInWsPosition( Vector<ShaderComponent*> &componentList );
/// Returns the world space view vector from the wsPosition.
static Var* getWsView( Var *wsPosition, MultiLine *meta );
/// Returns the input normal map texture.
static Var* getNormalMapTex();
///
Var* addOutDetailTexCoord( Vector<ShaderComponent*> &componentList,
MultiLine *meta,
bool useTexAnim );
///
Var* getObjTrans( Vector<ShaderComponent*> &componentList,
bool useInstancing,
MultiLine *meta );
///
Var* getModelView( Vector<ShaderComponent*> &componentList,
bool useInstancing,
MultiLine *meta );
///
Var* getWorldView( Vector<ShaderComponent*> &componentList,
bool useInstancing,
MultiLine *meta );
///
Var* getInvWorldView( Vector<ShaderComponent*> &componentList,
bool useInstancing,
MultiLine *meta );
// ShaderFeature
Var* getVertTexCoord( const String &name );
LangElement* setupTexSpaceMat( Vector<ShaderComponent*> &componentList, Var **texSpaceMat );
LangElement* assignColor( LangElement *elem, Material::BlendOp blend, LangElement *lerpElem = NULL, ShaderFeature::OutputTarget outputTarget = ShaderFeature::DefaultTarget );
LangElement* expandNormalMap( LangElement *sampleNormalOp, LangElement *normalDecl, LangElement *normalVar, const MaterialFeatureData &fd );
};
class NamedFeatureGLSL : public ShaderFeatureGLSL
{
protected:
String mName;
public:
NamedFeatureGLSL( const String &name )
: mName( name )
{}
virtual String getName() { return mName; }
};
class RenderTargetZeroGLSL : public ShaderFeatureGLSL
{
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; }
virtual String getName() { return mFeatureName; }
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return
mOutputTargetMask; }
};
/// Vertex position
class VertPositionGLSL : public ShaderFeatureGLSL
{
public:
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual String getName()
{
return "Vert Position";
}
virtual void determineFeature( Material *material,
const GFXVertexFormat *vertexFormat,
U32 stageNum,
const FeatureType &type,
const FeatureSet &features,
MaterialFeatureData *outFeatureData )
{
// This feature is always on!
outFeatureData->features.addFeature( type );
}
};
/// Vertex lighting based on the normal and the light
/// direction passed through the vertex color.
class RTLightingFeatGLSL : public ShaderFeatureGLSL
{
protected:
ShaderIncludeDependency mDep;
public:
RTLightingFeatGLSL();
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Material::BlendOp getBlendOp(){ return Material::None; }
virtual Resources getResources( const MaterialFeatureData &fd );
virtual String getName()
{
return "RT Lighting";
}
};
/// Base texture
class DiffuseMapFeatGLSL : public ShaderFeatureGLSL
{
public:
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Material::BlendOp getBlendOp(){ return Material::LerpAlpha; }
virtual Resources getResources( const MaterialFeatureData &fd );
// Sets textures and texture flags for current pass
virtual void setTexData( Material::StageData &stageDat,
const MaterialFeatureData &fd,
RenderPassData &passData,
U32 &texIndex );
virtual String getName()
{
return "Base Texture";
}
};
/// Overlay texture
class OverlayTexFeatGLSL : public ShaderFeatureGLSL
{
public:
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Material::BlendOp getBlendOp(){ return Material::LerpAlpha; }
virtual Resources getResources( const MaterialFeatureData &fd );
// Sets textures and texture flags for current pass
virtual void setTexData( Material::StageData &stageDat,
const MaterialFeatureData &fd,
RenderPassData &passData,
U32 &texIndex );
virtual String getName()
{
return "Overlay Texture";
}
};
/// Diffuse color
class DiffuseFeatureGLSL : public ShaderFeatureGLSL
{
public:
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Material::BlendOp getBlendOp(){ return Material::None; }
virtual String getName()
{
return "Diffuse Color";
}
};
/// Diffuse vertex color
class DiffuseVertColorFeatureGLSL : public ShaderFeatureGLSL
{
public:
virtual void processVert( Vector< ShaderComponent* >& componentList,
const MaterialFeatureData& fd );
virtual void processPix( Vector< ShaderComponent* >&componentList,
const MaterialFeatureData& fd );
virtual Material::BlendOp getBlendOp(){ return Material::None; }
virtual String getName()
{
return "Diffuse Vertex Color";
}
};
/// Lightmap
class LightmapFeatGLSL : public ShaderFeatureGLSL
{
public:
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Material::BlendOp getBlendOp(){ return Material::LerpAlpha; }
virtual Resources getResources( const MaterialFeatureData &fd );
// Sets textures and texture flags for current pass
virtual void setTexData( Material::StageData &stageDat,
const MaterialFeatureData &fd,
RenderPassData &passData,
U32 &texIndex );
virtual String getName()
{
return "Lightmap";
}
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const;
};
/// Tonemap
class TonemapFeatGLSL : public ShaderFeatureGLSL
{
public:
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Material::BlendOp getBlendOp(){ return Material::LerpAlpha; }
virtual Resources getResources( const MaterialFeatureData &fd );
// Sets textures and texture flags for current pass
virtual void setTexData( Material::StageData &stageDat,
const MaterialFeatureData &fd,
RenderPassData &passData,
U32 &texIndex );
virtual String getName()
{
return "Tonemap";
}
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const;
};
/// Baked lighting stored on the vertex color
class VertLitGLSL : public ShaderFeatureGLSL
{
public:
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Material::BlendOp getBlendOp(){ return Material::None; }
virtual String getName()
{
return "Vert Lit";
}
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const;
};
/// Detail map
class DetailFeatGLSL : public ShaderFeatureGLSL
{
public:
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Resources getResources( const MaterialFeatureData &fd );
virtual Material::BlendOp getBlendOp(){ return Material::Mul; }
// Sets textures and texture flags for current pass
virtual void setTexData( Material::StageData &stageDat,
const MaterialFeatureData &fd,
RenderPassData &passData,
U32 &texIndex );
virtual String getName()
{
return "Detail";
}
};
/// Reflect Cubemap
class ReflectCubeFeatGLSL : public ShaderFeatureGLSL
{
public:
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Resources getResources( const MaterialFeatureData &fd );
// Sets textures and texture flags for current pass
virtual void setTexData( Material::StageData &stageDat,
const MaterialFeatureData &fd,
RenderPassData &passData,
U32 &texIndex );
virtual String getName()
{
return "Reflect Cube";
}
};
/// Fog
class FogFeatGLSL : public ShaderFeatureGLSL
{
protected:
ShaderIncludeDependency mFogDep;
public:
FogFeatGLSL();
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Resources getResources( const MaterialFeatureData &fd );
virtual Material::BlendOp getBlendOp() { return Material::LerpAlpha; }
virtual String getName()
{
return "Fog";
}
};
/// Tex Anim
class TexAnimGLSL : public ShaderFeatureGLSL
{
public:
virtual Material::BlendOp getBlendOp() { return Material::None; }
virtual String getName()
{
return "Texture Animation";
}
};
/// Visibility
class VisibilityFeatGLSL : public ShaderFeatureGLSL
{
public:
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
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()
{
return "Visibility";
}
};
///
class AlphaTestGLSL : public ShaderFeatureGLSL
{
public:
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Material::BlendOp getBlendOp() { return Material::None; }
virtual String getName()
{
return "Alpha Test";
}
};
/// Special feature used to mask out the RGB color for
/// non-glow passes of glow materials.
/// @see RenderGlowMgr
class GlowMaskGLSL : public ShaderFeatureGLSL
{
public:
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Material::BlendOp getBlendOp() { return Material::None; }
virtual String getName()
{
return "Glow Mask";
}
};
/// 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 torque.glsl
class HDROutGLSL : public ShaderFeatureGLSL
{
protected:
ShaderIncludeDependency mTorqueDep;
public:
HDROutGLSL();
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual Material::BlendOp getBlendOp() { return Material::None; }
virtual String getName() { return "HDR Output"; }
};
///
class FoliageFeatureGLSL : public ShaderFeatureGLSL{
protected:
ShaderIncludeDependency mDep;
public:
FoliageFeatureGLSL();
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual String getName()
{
return "Foliage Feature";
}
virtual void determineFeature( Material *material,
const GFXVertexFormat *vertexFormat,
U32 stageNum,
const FeatureType &type,
const FeatureSet &features,
MaterialFeatureData *outFeatureData );
virtual ShaderFeatureConstHandles* createConstHandles( GFXShader *shader, SimObject *userObject );
};
///
class ParticleNormalFeatureGLSL : public ShaderFeatureGLSL
{
public:
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual String getName()
{
return "Particle Normal Generation Feature";
}
};
class ImposterVertFeatureGLSL : public ShaderFeatureGLSL
{
protected:
ShaderIncludeDependency mDep;
public:
ImposterVertFeatureGLSL();
virtual void processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual String getName() { return "Imposter Vert"; }
virtual void determineFeature( Material *material,
const GFXVertexFormat *vertexFormat,
U32 stageNum,
const FeatureType &type,
const FeatureSet &features,
MaterialFeatureData *outFeatureData );
};
#endif // _SHADERGEN_GLSL_SHADERFEATUREGLSL_H_

View file

@ -0,0 +1,179 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "shaderGen/GLSL/shaderGenGLSL.h"
#include "shaderGen/GLSL/shaderCompGLSL.h"
void ShaderGenPrinterGLSL::printShaderHeader( Stream& stream )
{
const char *header1 = "//*****************************************************************************\r\n";
const char *header2 = "// Torque -- GLSL procedural shader\r\n";
stream.write( dStrlen(header1), header1 );
stream.write( dStrlen(header2), header2 );
stream.write( dStrlen(header1), header1 );
// Cheap HLSL compatibility.
const char* header3 = "#include \"shaders/common/gl/hlslCompat.glsl\"\r\n";
stream.write( dStrlen(header3), header3 );
const char* header4 = "\r\n";
stream.write( dStrlen(header4), header4 );
}
void ShaderGenPrinterGLSL::printMainComment( Stream& stream )
{
// Print out main function definition
const char * header5 = "// Main \r\n";
const char * line = "//-----------------------------------------------------------------------------\r\n";
stream.write( dStrlen(line), line );
stream.write( dStrlen(header5), header5 );
stream.write( dStrlen(line), line );
}
void ShaderGenPrinterGLSL::printVertexShaderCloser( Stream& stream )
{
const char *closer = "}\r\n";
stream.write( dStrlen(closer), closer );
}
void ShaderGenPrinterGLSL::printPixelShaderOutputStruct( Stream& stream, const MaterialFeatureData &featureData )
{
// Nothing here
}
void ShaderGenPrinterGLSL::printPixelShaderCloser( Stream& stream )
{
const char *closer = " gl_FragColor = col;\r\n}\r\n";
stream.write( dStrlen(closer), closer );
}
void ShaderGenPrinterGLSL::printLine(Stream& stream, const String& line)
{
stream.write(line.length(), line.c_str());
const char* end = "\r\n";
stream.write(dStrlen(end), end);
}
const char* ShaderGenComponentFactoryGLSL::typeToString( GFXDeclType type )
{
switch ( type )
{
default:
case GFXDeclType_Float:
return "float";
case GFXDeclType_Float2:
return "vec2";
case GFXDeclType_Float3:
return "vec3";
case GFXDeclType_Float4:
case GFXDeclType_Color:
return "vec4";
}
}
ShaderComponent* ShaderGenComponentFactoryGLSL::createVertexInputConnector( const GFXVertexFormat &vertexFormat )
{
AppVertConnectorGLSL *vertComp = new AppVertConnectorGLSL;
// Loop thru the vertex format elements.
for ( U32 i=0; i < vertexFormat.getElementCount(); i++ )
{
const GFXVertexElement &element = vertexFormat.getElement( i );
Var *var = NULL;
if ( element.isSemantic( GFXSemantic::POSITION ) )
{
var = vertComp->getElement( RT_POSITION );
var->setName( "position" );
}
else if ( element.isSemantic( GFXSemantic::NORMAL ) )
{
var = vertComp->getElement( RT_NORMAL );
var->setName( "normal" );
}
else if ( element.isSemantic( GFXSemantic::TANGENT ) )
{
var = vertComp->getElement( RT_TANGENT );
var->setName( "T" );
}
else if ( element.isSemantic( GFXSemantic::BINORMAL ) )
{
var = vertComp->getElement( RT_BINORMAL );
var->setName( "B" );
}
else if ( element.isSemantic( GFXSemantic::COLOR ) )
{
var = vertComp->getElement( RT_COLOR );
var->setName( "diffuse" );
}
else if ( element.isSemantic( GFXSemantic::TEXCOORD ) )
{
var = vertComp->getElement( RT_TEXCOORD );
if ( element.getSemanticIndex() == 0 )
var->setName( "texCoord" );
else
var->setName( String::ToString( "texCoord%d", element.getSemanticIndex() + 1 ) );
}
else
{
// Everything else is a texcoord!
var = vertComp->getElement( RT_TEXCOORD );
var->setName( "tc" + element.getSemantic() );
}
if ( !var )
continue;
var->setStructName( "" );
var->setType( typeToString( element.getType() ) );
}
return vertComp;
}
ShaderComponent* ShaderGenComponentFactoryGLSL::createVertexPixelConnector()
{
VertPixelConnectorGLSL* comp = new VertPixelConnectorGLSL;
return comp;
}
ShaderComponent* ShaderGenComponentFactoryGLSL::createVertexParamsDef()
{
VertexParamsDefGLSL* comp = new VertexParamsDefGLSL;
return comp;
}
ShaderComponent* ShaderGenComponentFactoryGLSL::createPixelParamsDef()
{
PixelParamsDefGLSL* comp = new PixelParamsDefGLSL;
return comp;
}

View file

@ -0,0 +1,59 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _SHADERGEN_GLSL_H_
#define _SHADERGEN_GLSL_H_
#ifndef _SHADERGEN_H_
#include "shaderGen/shaderGen.h"
#endif
class ShaderGenPrinterGLSL : public ShaderGenPrinter
{
public:
// ShaderGenPrinter
virtual void printShaderHeader(Stream& stream);
virtual void printMainComment(Stream& stream);
virtual void printVertexShaderCloser(Stream& stream);
virtual void printPixelShaderOutputStruct(Stream& stream, const MaterialFeatureData &featureData);
virtual void printPixelShaderCloser(Stream& stream);
virtual void printLine(Stream& stream, const String& line);
};
class ShaderGenComponentFactoryGLSL : public ShaderGenComponentFactory
{
public:
/// Helper function for converting a vertex decl
/// type to an GLSL type string.
static const char* typeToString( GFXDeclType type );
// ShaderGenComponentFactory
virtual ShaderComponent* createVertexInputConnector( const GFXVertexFormat &vertexFormat );
virtual ShaderComponent* createVertexPixelConnector();
virtual ShaderComponent* createVertexParamsDef();
virtual ShaderComponent* createPixelParamsDef();
};
#endif

View file

@ -0,0 +1,105 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "shaderGen/shaderGen.h"
#include "shaderGen/GLSL/shaderGenGLSL.h"
#include "shaderGen/GLSL/shaderFeatureGLSL.h"
#include "shaderGen/featureMgr.h"
#include "shaderGen/GLSL/bumpGLSL.h"
#include "shaderGen/GLSL/pixSpecularGLSL.h"
#include "shaderGen/GLSL/depthGLSL.h"
#include "shaderGen/GLSL/paraboloidGLSL.h"
#include "materials/materialFeatureTypes.h"
#include "core/module.h"
static ShaderGen::ShaderGenInitDelegate sInitDelegate;
void _initShaderGenGLSL( ShaderGen *shaderGen )
{
shaderGen->setPrinter( new ShaderGenPrinterGLSL );
shaderGen->setComponentFactory( new ShaderGenComponentFactoryGLSL );
shaderGen->setFileEnding( "glsl" );
FEATUREMGR->registerFeature( MFT_VertTransform, new VertPositionGLSL );
FEATUREMGR->registerFeature( MFT_RTLighting, new RTLightingFeatGLSL );
FEATUREMGR->registerFeature( MFT_IsDXTnm, new NamedFeatureGLSL( "DXTnm" ) );
FEATUREMGR->registerFeature( MFT_TexAnim, new TexAnimGLSL );
FEATUREMGR->registerFeature( MFT_DiffuseMap, new DiffuseMapFeatGLSL );
FEATUREMGR->registerFeature( MFT_OverlayMap, new OverlayTexFeatGLSL );
FEATUREMGR->registerFeature( MFT_DiffuseColor, new DiffuseFeatureGLSL );
FEATUREMGR->registerFeature( MFT_DiffuseVertColor, new DiffuseVertColorFeatureGLSL );
FEATUREMGR->registerFeature( MFT_AlphaTest, new AlphaTestGLSL );
FEATUREMGR->registerFeature( MFT_GlowMask, new GlowMaskGLSL );
FEATUREMGR->registerFeature( MFT_LightMap, new LightmapFeatGLSL );
FEATUREMGR->registerFeature( MFT_ToneMap, new TonemapFeatGLSL );
FEATUREMGR->registerFeature( MFT_VertLit, new VertLitGLSL );
FEATUREMGR->registerFeature( MFT_Parallax, new ParallaxFeatGLSL );
FEATUREMGR->registerFeature( MFT_NormalMap, new BumpFeatGLSL );
FEATUREMGR->registerFeature( MFT_DetailNormalMap, new NamedFeatureGLSL( "Detail Normal Map" ) );
FEATUREMGR->registerFeature( MFT_DetailMap, new DetailFeatGLSL );
FEATUREMGR->registerFeature( MFT_CubeMap, new ReflectCubeFeatGLSL );
FEATUREMGR->registerFeature( MFT_PixSpecular, new PixelSpecularGLSL );
FEATUREMGR->registerFeature( MFT_SpecularMap, new SpecularMapGLSL );
FEATUREMGR->registerFeature( MFT_GlossMap, new NamedFeatureGLSL( "Gloss Map" ) );
FEATUREMGR->registerFeature( MFT_IsTranslucent, new NamedFeatureGLSL( "Translucent" ) );
FEATUREMGR->registerFeature( MFT_Visibility, new VisibilityFeatGLSL );
FEATUREMGR->registerFeature( MFT_Fog, new FogFeatGLSL );
FEATUREMGR->registerFeature( MFT_NormalsOut, new NormalsOutFeatGLSL );
FEATUREMGR->registerFeature( MFT_DepthOut, new DepthOutGLSL );
FEATUREMGR->registerFeature(MFT_EyeSpaceDepthOut, new EyeSpaceDepthOutGLSL());
FEATUREMGR->registerFeature( MFT_HDROut, new HDROutGLSL );
FEATUREMGR->registerFeature( MFT_ParaboloidVertTransform, new ParaboloidVertTransformGLSL );
FEATUREMGR->registerFeature( MFT_IsSinglePassParaboloid, new NamedFeatureGLSL( "Single Pass Paraboloid" ) );
FEATUREMGR->registerFeature( MFT_RenderTarget1_Zero, new RenderTargetZeroGLSL
( ShaderFeature::RenderTarget1 ) );
FEATUREMGR->registerFeature( MFT_DiffuseMapAtlas, new NamedFeatureGLSL( "Diffuse Map Atlas" ) );
FEATUREMGR->registerFeature( MFT_NormalMapAtlas, new NamedFeatureGLSL( "Normal Map Atlas" ) );
FEATUREMGR->registerFeature( MFT_Foliage, new FoliageFeatureGLSL );
FEATUREMGR->registerFeature( MFT_ParticleNormal, new ParticleNormalFeatureGLSL );
FEATUREMGR->registerFeature( MFT_ForwardShading, new NamedFeatureGLSL( "Forward Shaded Material" ) );
FEATUREMGR->registerFeature( MFT_ImposterVert, new ImposterVertFeatureGLSL );
}
MODULE_BEGIN( ShaderGenGLSL )
MODULE_INIT_AFTER( ShaderGen )
MODULE_INIT_AFTER( ShaderGenFeatureMgr )
MODULE_INIT
{
sInitDelegate.bind( &_initShaderGenGLSL );
SHADERGEN->registerInitDelegate(OpenGL, sInitDelegate);
}
MODULE_END;