mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-16 00:54:54 +00:00
Groundwork for other shaders
Adds the ground work for geometry shaders Expands shaderData and gfxShader to allow for more shader types note: when building a GFXShader in source you have to call setShaderStageFile with the shaderStage and the filepath for that stage. Once we add compute shaders this will become more apparent as compute shaders are a stage of their own and do not require vertex and pixel files whereas other shaders sometimes do.
This commit is contained in:
parent
949f788a0a
commit
808e2f4200
7 changed files with 220 additions and 161 deletions
|
|
@ -59,13 +59,18 @@ bool GFXShader::init( const Torque::Path &vertFile,
|
|||
}
|
||||
#endif
|
||||
|
||||
bool GFXShader::init( const Torque::Path &vertFile,
|
||||
const Torque::Path &pixFile,
|
||||
F32 pixVersion,
|
||||
bool GFXShader::init( F32 pixVersion,
|
||||
const Vector<GFXShaderMacro> ¯os,
|
||||
const Vector<String> &samplerNames,
|
||||
GFXVertexFormat *instanceFormat)
|
||||
{
|
||||
// early out.
|
||||
if (mVertexFile.isEmpty() && mPixelFile.isEmpty() && mGeometryFile.isEmpty())
|
||||
{
|
||||
Con::errorf("Shader files empty, please call setShaderStageFile from shaderData");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Take care of instancing
|
||||
if (instanceFormat)
|
||||
{
|
||||
|
|
@ -74,8 +79,6 @@ bool GFXShader::init( const Torque::Path &vertFile,
|
|||
}
|
||||
|
||||
// Store the inputs for use in reloading.
|
||||
mVertexFile = vertFile;
|
||||
mPixelFile = pixFile;
|
||||
mPixVersion = pixVersion;
|
||||
mMacros = macros;
|
||||
mSamplerNamesOrdered = samplerNames;
|
||||
|
|
@ -91,8 +94,12 @@ bool GFXShader::init( const Torque::Path &vertFile,
|
|||
_updateDesc();
|
||||
|
||||
// Add file change notifications for reloads.
|
||||
Torque::FS::AddChangeNotification( mVertexFile, this, &GFXShader::_onFileChanged );
|
||||
Torque::FS::AddChangeNotification( mPixelFile, this, &GFXShader::_onFileChanged );
|
||||
if(!mVertexFile.isEmpty())
|
||||
Torque::FS::AddChangeNotification( mVertexFile, this, &GFXShader::_onFileChanged );
|
||||
if(!mPixelFile.isEmpty())
|
||||
Torque::FS::AddChangeNotification( mPixelFile, this, &GFXShader::_onFileChanged );
|
||||
if(!mGeometryFile.isEmpty())
|
||||
Torque::FS::AddChangeNotification( mGeometryFile, this, &GFXShader::_onFileChanged);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -161,6 +168,24 @@ bool GFXShader::removeGlobalMacro( const String &name )
|
|||
return false;
|
||||
}
|
||||
|
||||
void GFXShader::setShaderStageFile(const GFXShaderStage stage, const Torque::Path& filePath)
|
||||
{
|
||||
switch (stage)
|
||||
{
|
||||
case GFXShaderStage::VERTEX_SHADER:
|
||||
mVertexFile = filePath;
|
||||
break;
|
||||
case GFXShaderStage::PIXEL_SHADER:
|
||||
mPixelFile = filePath;
|
||||
break;
|
||||
case GFXShaderStage::GEOMETRY_SHADER:
|
||||
mGeometryFile = filePath;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GFXShader::_unlinkBuffer( GFXShaderConstBuffer *buf )
|
||||
{
|
||||
Vector<GFXShaderConstBuffer*>::iterator iter = mActiveBuffers.begin();
|
||||
|
|
|
|||
|
|
@ -249,6 +249,9 @@ protected:
|
|||
/// The pixel shader file.
|
||||
Torque::Path mPixelFile;
|
||||
|
||||
// the geometry shader file.
|
||||
Torque::Path mGeometryFile;
|
||||
|
||||
/// The macros to be passed to the shader.
|
||||
Vector<GFXShaderMacro> mMacros;
|
||||
|
||||
|
|
@ -322,9 +325,7 @@ public:
|
|||
#endif
|
||||
|
||||
///
|
||||
bool init( const Torque::Path &vertFile,
|
||||
const Torque::Path &pixFile,
|
||||
F32 pixVersion,
|
||||
bool init( F32 pixVersion,
|
||||
const Vector<GFXShaderMacro> ¯os,
|
||||
const Vector<String> &samplerNames,
|
||||
GFXVertexFormat *instanceFormat = NULL );
|
||||
|
|
@ -364,6 +365,8 @@ public:
|
|||
/// the shader disassembly.
|
||||
virtual bool getDisassembly( String &outStr ) const { return false; }
|
||||
|
||||
void setShaderStageFile(const GFXShaderStage stage, const Torque::Path& filePath);
|
||||
|
||||
/// Returns the vertex shader file path.
|
||||
const String& getVertexShaderFile() const { return mVertexFile.getFullPath(); }
|
||||
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ void GuiShaderEditor::onPreRender()
|
|||
setUpdate();
|
||||
}
|
||||
|
||||
void GuiShaderEditor::drawThickLine(const Point2I& pt1, const Point2I& pt2, U32 thickness = 2, ColorI col1 = ColorI(255, 255, 255), ColorI col2 = ColorI(255, 255, 255))
|
||||
void GuiShaderEditor::drawThickLine(const Point2I& pt1, const Point2I& pt2, U32 thickness, ColorI col1, ColorI col2)
|
||||
{
|
||||
Point2F dir = Point2F(pt2.x - pt1.x, pt2.y - pt1.y);
|
||||
if (dir == Point2F::Zero)
|
||||
|
|
@ -292,7 +292,7 @@ void GuiShaderEditor::renderConnections(Point2I offset, const RectI& updateRect)
|
|||
start += Point2I(mNodeSize / 2, mNodeSize / 2);
|
||||
end += Point2I(mNodeSize / 2, mNodeSize / 2);
|
||||
|
||||
drawThickLine(start, end);
|
||||
drawThickLine(start, end, mNodeSize/3);
|
||||
}
|
||||
|
||||
// Restore the clip rect to what it was at the start
|
||||
|
|
@ -328,7 +328,7 @@ void GuiShaderEditor::onRender(Point2I offset, const RectI& updateRect)
|
|||
|
||||
RectI sockActive(start, Point2I(mNodeSize, mNodeSize));
|
||||
start += Point2I(mNodeSize / 2, mNodeSize / 2);
|
||||
drawThickLine(start, mLastMousePos + offset);
|
||||
drawThickLine(start, mLastMousePos + offset, mNodeSize/3);
|
||||
|
||||
// draw socket overlay over the top of the line.
|
||||
sockActive.inset(1, 1);
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ public:
|
|||
virtual void onRemove() override;
|
||||
|
||||
virtual void onPreRender() override;
|
||||
void drawThickLine(const Point2I& pt1, const Point2I& pt2, U32 thickness, ColorI col1, ColorI col2);
|
||||
void drawThickLine(const Point2I& pt1, const Point2I& pt2, U32 thickness = 2, ColorI col1 = ColorI(255, 255, 255), ColorI col2 = ColorI(255, 255, 255));
|
||||
virtual void onRender(Point2I offset, const RectI& updateRect) override;
|
||||
|
||||
// interaction
|
||||
|
|
|
|||
|
|
@ -48,10 +48,12 @@ ConsoleDocClass( ShaderData,
|
|||
"// Used for the procedural clould system\n"
|
||||
"singleton ShaderData( CloudLayerShader )\n"
|
||||
"{\n"
|
||||
" DXVertexShaderFile = $Core::CommonShaderPath @ \"/cloudLayerV.hlsl\";\n"
|
||||
" DXPixelShaderFile = $Core::CommonShaderPath @ \"/cloudLayerP.hlsl\";\n"
|
||||
" OGLVertexShaderFile = $Core::CommonShaderPath @ \"/gl/cloudLayerV.glsl\";\n"
|
||||
" OGLPixelShaderFile = $Core::CommonShaderPath @ \"/gl/cloudLayerP.glsl\";\n"
|
||||
" DXVertexShaderFile = $Core::CommonShaderPath @ \"/cloudLayerV.hlsl\";\n"
|
||||
" DXPixelShaderFile = $Core::CommonShaderPath @ \"/cloudLayerP.hlsl\";\n"
|
||||
" DXGeometryShaderFile = $Core::CommonShaderPath @ \"/cloudLayerG.hlsl\";\n"
|
||||
" OGLVertexShaderFile = $Core::CommonShaderPath @ \"/gl/cloudLayerV.glsl\";\n"
|
||||
" OGLPixelShaderFile = $Core::CommonShaderPath @ \"/gl/cloudLayerP.glsl\";\n"
|
||||
" OGLGeometryShaderFile = $Core::CommonShaderPath @ \"/gl/cloudLayerG.glsl\";\n"
|
||||
" pixVersion = 2.0;\n"
|
||||
"};\n"
|
||||
"@endtsexample\n\n"
|
||||
|
|
@ -67,70 +69,87 @@ ShaderData::ShaderData()
|
|||
|
||||
for( int i = 0; i < NumTextures; ++i)
|
||||
mRTParams[i] = false;
|
||||
|
||||
mDXVertexShaderName = StringTable->EmptyString();
|
||||
mDXPixelShaderName = StringTable->EmptyString();
|
||||
mDXGeometryShaderName = StringTable->EmptyString();
|
||||
|
||||
mOGLVertexShaderName = StringTable->EmptyString();
|
||||
mOGLPixelShaderName = StringTable->EmptyString();
|
||||
mOGLGeometryShaderName = StringTable->EmptyString();
|
||||
}
|
||||
|
||||
void ShaderData::initPersistFields()
|
||||
{
|
||||
docsURL;
|
||||
addField("DXVertexShaderFile", TypeStringFilename, Offset(mDXVertexShaderName, ShaderData),
|
||||
"@brief %Path to the DirectX vertex shader file to use for this ShaderData.\n\n"
|
||||
"It must contain only one program and no pixel shader, just the vertex shader."
|
||||
"It can be either an HLSL or assembly level shader. HLSL's must have a "
|
||||
"filename extension of .hlsl, otherwise its assumed to be an assembly file.");
|
||||
addField("DXVertexShaderFile", TypeStringFilename, Offset(mDXVertexShaderName, ShaderData),
|
||||
"@brief %Path to the DirectX vertex shader file to use for this ShaderData.\n\n"
|
||||
"It must contain only one program and no pixel shader, just the vertex shader."
|
||||
"It can be either an HLSL or assembly level shader. HLSL's must have a "
|
||||
"filename extension of .hlsl, otherwise its assumed to be an assembly file.");
|
||||
|
||||
addField("DXPixelShaderFile", TypeStringFilename, Offset(mDXPixelShaderName, ShaderData),
|
||||
"@brief %Path to the DirectX pixel shader file to use for this ShaderData.\n\n"
|
||||
"It must contain only one program and no vertex shader, just the pixel "
|
||||
"shader. It can be either an HLSL or assembly level shader. HLSL's "
|
||||
"must have a filename extension of .hlsl, otherwise its assumed to be an assembly file.");
|
||||
addField("DXPixelShaderFile", TypeStringFilename, Offset(mDXPixelShaderName, ShaderData),
|
||||
"@brief %Path to the DirectX pixel shader file to use for this ShaderData.\n\n"
|
||||
"It must contain only one program and no vertex shader, just the pixel "
|
||||
"shader. It can be either an HLSL or assembly level shader. HLSL's "
|
||||
"must have a filename extension of .hlsl, otherwise its assumed to be an assembly file.");
|
||||
|
||||
addField("OGLVertexShaderFile", TypeStringFilename, Offset(mOGLVertexShaderName, ShaderData),
|
||||
"@brief %Path to an OpenGL vertex shader file to use for this ShaderData.\n\n"
|
||||
"It must contain only one program and no pixel shader, just the vertex shader.");
|
||||
addField("DXGeometryShaderFile", TypeStringFilename, Offset(mDXGeometryShaderName, ShaderData),
|
||||
"@brief %Path to the DirectX geometry shader file to use for this ShaderData.\n\n"
|
||||
"It can be either an HLSL or assembly level shader. HLSL's must have a "
|
||||
"filename extension of .hlsl, otherwise its assumed to be an assembly file.");
|
||||
|
||||
addField("OGLPixelShaderFile", TypeStringFilename, Offset(mOGLPixelShaderName, ShaderData),
|
||||
"@brief %Path to an OpenGL pixel shader file to use for this ShaderData.\n\n"
|
||||
"It must contain only one program and no vertex shader, just the pixel "
|
||||
"shader.");
|
||||
addField("OGLVertexShaderFile", TypeStringFilename, Offset(mOGLVertexShaderName, ShaderData),
|
||||
"@brief %Path to an OpenGL vertex shader file to use for this ShaderData.\n\n"
|
||||
"It must contain only one program and no pixel shader, just the vertex shader.");
|
||||
|
||||
addField("useDevicePixVersion", TypeBool, Offset(mUseDevicePixVersion, ShaderData),
|
||||
"@brief If true, the maximum pixel shader version offered by the graphics card will be used.\n\n"
|
||||
"Otherwise, the script-defined pixel shader version will be used.\n\n");
|
||||
addField("OGLPixelShaderFile", TypeStringFilename, Offset(mOGLPixelShaderName, ShaderData),
|
||||
"@brief %Path to an OpenGL pixel shader file to use for this ShaderData.\n\n"
|
||||
"It must contain only one program and no vertex shader, just the pixel "
|
||||
"shader.");
|
||||
|
||||
addField("pixVersion", TypeF32, Offset(mPixVersion, ShaderData),
|
||||
"@brief Indicates target level the shader should be compiled.\n\n"
|
||||
"Valid numbers at the time of this writing are 1.1, 1.4, 2.0, and 3.0. "
|
||||
"The shader will not run properly if the hardware does not support the "
|
||||
"level of shader compiled.");
|
||||
addField("OGLGeometryShaderFile", TypeStringFilename, Offset(mOGLGeometryShaderName, ShaderData),
|
||||
"@brief %Path to the OpenGL Geometry shader file to use for this ShaderData.\n\n");
|
||||
|
||||
addField("defines", TypeRealString, Offset(mDefines, ShaderData),
|
||||
"@brief String of case-sensitive defines passed to the shader compiler.\n\n"
|
||||
addField("useDevicePixVersion", TypeBool, Offset(mUseDevicePixVersion, ShaderData),
|
||||
"@brief If true, the maximum pixel shader version offered by the graphics card will be used.\n\n"
|
||||
"Otherwise, the script-defined pixel shader version will be used.\n\n");
|
||||
|
||||
addField("pixVersion", TypeF32, Offset(mPixVersion, ShaderData),
|
||||
"@brief Indicates target level the shader should be compiled.\n\n"
|
||||
"Valid numbers at the time of this writing are 1.1, 1.4, 2.0, and 3.0. "
|
||||
"The shader will not run properly if the hardware does not support the "
|
||||
"level of shader compiled.");
|
||||
|
||||
addField("defines", TypeRealString, Offset(mDefines, ShaderData),
|
||||
"@brief String of case-sensitive defines passed to the shader compiler.\n\n"
|
||||
"The string should be delimited by a semicolon, tab, or newline character."
|
||||
|
||||
"@tsexample\n"
|
||||
"singleton ShaderData( FlashShader )\n"
|
||||
"{\n"
|
||||
"DXVertexShaderFile = $shaderGen::cachePath @ \"/postFx/flashV.hlsl\";\n"
|
||||
"DXPixelShaderFile = $shaderGen::cachePath @ \"/postFx/flashP.hlsl\";\n\n"
|
||||
" //Define setting the color of WHITE_COLOR.\n"
|
||||
"defines = \"WHITE_COLOR=float4(1.0,1.0,1.0,0.0)\";\n\n"
|
||||
"pixVersion = 2.0\n"
|
||||
"}\n"
|
||||
"singleton ShaderData( FlashShader )\n"
|
||||
"{\n"
|
||||
"DXVertexShaderFile = $shaderGen::cachePath @ \"/postFx/flashV.hlsl\";\n"
|
||||
"DXPixelShaderFile = $shaderGen::cachePath @ \"/postFx/flashP.hlsl\";\n\n"
|
||||
"DXGeometryShaderFile = $shaderGen::cachePath @ \"/postFx/flashG.hlsl\";\n\n"
|
||||
" //Define setting the color of WHITE_COLOR.\n"
|
||||
"defines = \"WHITE_COLOR=float4(1.0,1.0,1.0,0.0)\";\n\n"
|
||||
"pixVersion = 2.0\n"
|
||||
"}\n"
|
||||
"@endtsexample\n\n"
|
||||
);
|
||||
);
|
||||
|
||||
addField("samplerNames", TypeRealString, Offset(mSamplerNames, ShaderData), NumTextures,
|
||||
addField("samplerNames", TypeRealString, Offset(mSamplerNames, ShaderData), NumTextures,
|
||||
"@brief Indicates names of samplers present in shader. Order is important.\n\n"
|
||||
"Order of sampler names are used to assert correct sampler register/location"
|
||||
"Order of sampler names are used to assert correct sampler register/location"
|
||||
"Other objects (GFXStateBlockData, PostEffect...) use index number to link samplers."
|
||||
);
|
||||
);
|
||||
|
||||
addField("rtParams", TypeBool, Offset(mRTParams, ShaderData), NumTextures, "");
|
||||
addField("rtParams", TypeBool, Offset(mRTParams, ShaderData), NumTextures, "");
|
||||
|
||||
Parent::initPersistFields();
|
||||
|
||||
// Make sure we get activation signals.
|
||||
LightManager::smActivateSignal.notify( &ShaderData::_onLMActivate );
|
||||
LightManager::smActivateSignal.notify(&ShaderData::_onLMActivate);
|
||||
}
|
||||
|
||||
bool ShaderData::onAdd()
|
||||
|
|
@ -237,9 +256,13 @@ GFXShader* ShaderData::_createShader( const Vector<GFXShaderMacro> ¯os )
|
|||
{
|
||||
case Direct3D11:
|
||||
{
|
||||
success = shader->init( mDXVertexShaderName,
|
||||
mDXPixelShaderName,
|
||||
pixver,
|
||||
if (mDXVertexShaderName != String::EmptyString)
|
||||
shader->setShaderStageFile(GFXShaderStage::VERTEX_SHADER, mDXVertexShaderName);
|
||||
if (mDXPixelShaderName != String::EmptyString)
|
||||
shader->setShaderStageFile(GFXShaderStage::PIXEL_SHADER, mDXPixelShaderName);
|
||||
if (mDXGeometryShaderName != String::EmptyString)
|
||||
shader->setShaderStageFile(GFXShaderStage::GEOMETRY_SHADER, mDXGeometryShaderName);
|
||||
success = shader->init( pixver,
|
||||
macros,
|
||||
samplers);
|
||||
break;
|
||||
|
|
@ -247,9 +270,14 @@ GFXShader* ShaderData::_createShader( const Vector<GFXShaderMacro> ¯os )
|
|||
|
||||
case OpenGL:
|
||||
{
|
||||
success = shader->init( mOGLVertexShaderName,
|
||||
mOGLPixelShaderName,
|
||||
pixver,
|
||||
if(mOGLVertexShaderName != String::EmptyString)
|
||||
shader->setShaderStageFile(GFXShaderStage::VERTEX_SHADER, mOGLVertexShaderName);
|
||||
if (mOGLPixelShaderName != String::EmptyString)
|
||||
shader->setShaderStageFile(GFXShaderStage::PIXEL_SHADER, mOGLPixelShaderName);
|
||||
if (mOGLGeometryShaderName != String::EmptyString)
|
||||
shader->setShaderStageFile(GFXShaderStage::GEOMETRY_SHADER, mOGLGeometryShaderName);
|
||||
|
||||
success = shader->init( pixver,
|
||||
macros,
|
||||
samplers);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ protected:
|
|||
///
|
||||
static Vector<ShaderData*> smAllShaderData;
|
||||
|
||||
typedef HashTable<String,GFXShaderRef> ShaderCache;
|
||||
typedef HashTable<String, GFXShaderRef> ShaderCache;
|
||||
|
||||
ShaderCache mShaders;
|
||||
|
||||
|
|
@ -56,12 +56,12 @@ protected:
|
|||
F32 mPixVersion;
|
||||
|
||||
StringTableEntry mDXVertexShaderName;
|
||||
|
||||
StringTableEntry mDXPixelShaderName;
|
||||
StringTableEntry mDXGeometryShaderName;
|
||||
|
||||
StringTableEntry mOGLVertexShaderName;
|
||||
|
||||
StringTableEntry mOGLPixelShaderName;
|
||||
StringTableEntry mOGLGeometryShaderName;
|
||||
|
||||
/// A semicolon, tab, or newline delimited string of case
|
||||
/// sensitive defines that are passed to the shader compiler.
|
||||
|
|
@ -82,14 +82,14 @@ protected:
|
|||
|
||||
/// Helper for converting an array of macros
|
||||
/// into a formatted string.
|
||||
void _stringizeMacros( const Vector<GFXShaderMacro> ¯os,
|
||||
String *outString );
|
||||
void _stringizeMacros(const Vector<GFXShaderMacro>& macros,
|
||||
String* outString);
|
||||
|
||||
/// Creates a new shader returning NULL on error.
|
||||
GFXShader* _createShader( const Vector<GFXShaderMacro> ¯os );
|
||||
GFXShader* _createShader(const Vector<GFXShaderMacro>& macros);
|
||||
|
||||
/// @see LightManager::smActivateSignal
|
||||
static void _onLMActivate( const char *lm, bool activate );
|
||||
static void _onLMActivate(const char* lm, bool activate);
|
||||
|
||||
enum
|
||||
{
|
||||
|
|
@ -99,21 +99,21 @@ protected:
|
|||
String mSamplerNames[NumTextures];
|
||||
bool mRTParams[NumTextures];
|
||||
|
||||
bool _checkDefinition(GFXShader *shader);
|
||||
bool _checkDefinition(GFXShader* shader);
|
||||
|
||||
public:
|
||||
|
||||
void setSamplerName(const String &name, int idx) { mSamplerNames[idx] = name; }
|
||||
void setSamplerName(const String& name, int idx) { mSamplerNames[idx] = name; }
|
||||
String getSamplerName(int idx) const { return mSamplerNames[idx]; }
|
||||
|
||||
bool hasSamplerDef(const String &samplerName, int &pos) const;
|
||||
bool hasSamplerDef(const String& samplerName, int& pos) const;
|
||||
bool hasRTParamsDef(const int pos) const { return mRTParams[pos]; }
|
||||
|
||||
ShaderData();
|
||||
|
||||
/// Returns an initialized shader instance or NULL
|
||||
/// if the shader failed to be created.
|
||||
GFXShader* getShader( const Vector<GFXShaderMacro> ¯os = Vector<GFXShaderMacro>() );
|
||||
GFXShader* getShader(const Vector<GFXShaderMacro>& macros = Vector<GFXShaderMacro>());
|
||||
|
||||
/// Forces a reinitialization of all the instanced shaders.
|
||||
void reloadShaders();
|
||||
|
|
|
|||
|
|
@ -493,7 +493,10 @@ GFXShader* ShaderGen::getShader( const MaterialFeatureData &featureData, const G
|
|||
generateShader( featureData, vertFile, pixFile, &pixVersion, vertexFormat, cacheKey, shaderMacros );
|
||||
|
||||
GFXShader *shader = GFX->createShader();
|
||||
if (!shader->init(vertFile, pixFile, pixVersion, shaderMacros, samplers, &mInstancingFormat))
|
||||
shader->setShaderStageFile(GFXShaderStage::VERTEX_SHADER, vertFile);
|
||||
shader->setShaderStageFile(GFXShaderStage::PIXEL_SHADER, pixFile);
|
||||
|
||||
if (!shader->init(pixVersion, shaderMacros, samplers, &mInstancingFormat))
|
||||
{
|
||||
delete shader;
|
||||
return NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue