123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705 |
- //-----------------------------------------------------------------------------
- // 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
- struct LangElement;
- struct MaterialFeatureData;
- struct RenderPassData;
- class ShaderFeatureGLSL : public ShaderFeature
- {
- public:
- ShaderFeatureGLSL();
- ///
- Var* getOutTexCoord( const char *name,
- const char *type,
- 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,
- 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 "outWorldToTangent" 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 "outViewToTangent" 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,
- bool useFoliageTexCoord);
- ///
- 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 );
- Var* getSurface(Vector<ShaderComponent*>& componentList, MultiLine* meta, const MaterialFeatureData& fd);
- Var* getInWorldNormal(Vector<ShaderComponent*>& componentList);
-
- // 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 );
- };
- /// 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
- {
- protected:
- ShaderIncludeDependency mTorqueDep;
- public:
- DiffuseMapFeatGLSL();
- virtual void processVert( Vector<ShaderComponent*> &componentList,
- const MaterialFeatureData &fd );
- virtual void processPix( Vector<ShaderComponent*> &componentList,
- const MaterialFeatureData &fd );
- virtual U32 getOutputTargets(const MaterialFeatureData &fd) const;
- 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 U32 getOutputTargets(const MaterialFeatureData &fd) const;
- 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
- {
- protected:
- ShaderIncludeDependency mTorqueDep;
- public:
- VisibilityFeatGLSL();
- 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::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";
- }
-
- };
- /// Special feature for unpacking imposter verts.
- /// @see RenderImposterMgr
- 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 );
- };
- /// Hardware Skinning
- class HardwareSkinningFeatureGLSL : public ShaderFeatureGLSL
- {
- protected:
- public:
- virtual void processVert(Vector<ShaderComponent*> &componentList,
- const MaterialFeatureData &fd);
- virtual String getName() { return "Hardware Skinning"; }
- };
- /// Reflection Probes
- class ReflectionProbeFeatGLSL : public ShaderFeatureGLSL
- {
- protected:
- ShaderIncludeDependency mDep;
- public:
- ReflectionProbeFeatGLSL();
- 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 "Reflection Probes";
- }
- };
- #endif // _SHADERGEN_GLSL_SHADERFEATUREGLSL_H_
|