Torque3D/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h
Areloch fdc50ac8be Moved unneeded modules to Templates/Modules
Added templated getObjectsByClass to Scene for easier engine-side polling of objects, including nested checks for subscenes
Proper init'ing of mGamemodeName in LevelAsset, as well as proper fieldType for mIsSubLevel
D3D11 added logic to handle scaling down of textures in cubemap arrays for lower texture resolution preferences
Added ability to collapse groups programmatically to GuiVariableInspector
Upped PSSM shadowmap max size to 4096
Caught GL deferred lighting/probes up to D3D11
Temporarily disabled forward lighting/probes on GL materials until conversion finished
Upped smMaxInstancingVerts to 2000 from 200 to support slightly more detailed meshes being instanced
Reordered project settings so they load ahead of core modules, so that core modules can actually use project settings
Established current preset file for PostFXManager to use for reverting
WIP logic for forcing probes to update as part of level lighting load step in loading process
Streamlined PostFXManager code, removing unnecessary/redundant files
Coverted HDR, Lightrays and SSAO and ExamplePostEffect to use new PostFX Manager/Editor paradigm
PostFX manager now enacts callbacks so that postFXs' can process their own settings as well as provide editor fields
Changed PostFX editor to work with new callbacks via using VariableInspector
Updated PostEffectAsset's template file so new PostFX's will now automatically register with the PostFXManager and have the needed new callbacks for integration
Made HDR on by default, removed enable field from editing
Made probe bake resolution a project setting
Updated many GL postFX shaders to have proper case for PostFx.glsl
Example module now loads ExampleGUI and ExamplePostEffect during init'ing
Removed unneeded autoload definitions from ExampleModule's module file
Fixed Graphics Adapter settings field to properly display as well as apply setting
Updated many referenced profiles in tools folder to use the Tools specific gui profiles to make theming more consistent
Fixed coloration of tools button bitmap to make theming more consistent
Updated a few theme settings for improved visibility with theme, particularly selected/highlighted text
Moved AssetBrowser field types to separated folder/files
Updated new module creation to properly utilize template file instead of overriding it with a programmatic script generation.
Removed unneded default autoload definitions from new modules
Added WIP for editing Module/Asset dependencies
Updated the PostEffectAsset to properly generate glsl and hlsl files from templates
Updated module editor window to display only necessary fields
Added WIP of TerrainAsset
Added shaderCache gitignore file so folder isn't lost
2019-09-29 06:44:43 -05:00

703 lines
20 KiB
C++

//-----------------------------------------------------------------------------
// 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 );
///
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);
// 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_