mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-29 16:25:42 +00:00
Implement of the shader consts binding.
This commit is contained in:
parent
6f8e4cb3ee
commit
ccdc93fc25
12 changed files with 137 additions and 7 deletions
|
|
@ -305,7 +305,9 @@ bool TSStatic::onAdd()
|
||||||
mCubeReflector.unregisterReflector();
|
mCubeReflector.unregisterReflector();
|
||||||
|
|
||||||
if ( reflectorDesc )
|
if ( reflectorDesc )
|
||||||
mCubeReflector.registerReflector( this, reflectorDesc );
|
mCubeReflector.registerReflector( this, reflectorDesc );
|
||||||
|
|
||||||
|
strudelCSB = new CustomShaderBindingData();
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateShouldTick();
|
_updateShouldTick();
|
||||||
|
|
@ -627,6 +629,11 @@ void TSStatic::prepRenderImage( SceneRenderState* state )
|
||||||
// Acculumation
|
// Acculumation
|
||||||
rdata.setAccuTex(mAccuTex);
|
rdata.setAccuTex(mAccuTex);
|
||||||
|
|
||||||
|
//Various arbitrary shader render bits to add
|
||||||
|
strudelCSB->setFloat("strudel", 0.25);
|
||||||
|
|
||||||
|
rdata.addCustomShaderBinding(strudelCSB);
|
||||||
|
|
||||||
// If we have submesh culling enabled then prepare
|
// If we have submesh culling enabled then prepare
|
||||||
// the object space frustum to pass to the shape.
|
// the object space frustum to pass to the shape.
|
||||||
Frustum culler;
|
Frustum culler;
|
||||||
|
|
|
||||||
|
|
@ -236,6 +236,8 @@ public:
|
||||||
|
|
||||||
const Vector<S32>& getLOSDetails() const { return mLOSDetails; }
|
const Vector<S32>& getLOSDetails() const { return mLOSDetails; }
|
||||||
|
|
||||||
|
CustomShaderBindingData* strudelCSB;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef TSStatic::MeshType TSMeshType;
|
typedef TSStatic::MeshType TSMeshType;
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,8 @@
|
||||||
#include "gfx/util/screenspace.h"
|
#include "gfx/util/screenspace.h"
|
||||||
#include "math/util/matrixSet.h"
|
#include "math/util/matrixSet.h"
|
||||||
|
|
||||||
|
#include "ts/tsRenderState.h"
|
||||||
|
|
||||||
// We need to include customMaterialDefinition for ShaderConstHandles::init
|
// We need to include customMaterialDefinition for ShaderConstHandles::init
|
||||||
#include "materials/customMaterialDefinition.h"
|
#include "materials/customMaterialDefinition.h"
|
||||||
|
|
||||||
|
|
@ -118,6 +120,21 @@ void ShaderConstHandles::init( GFXShader *shader, CustomMaterial* mat /*=NULL*/
|
||||||
mMatInfoFlagsSC = shader->getShaderConstHandle(ShaderGenVars::matInfoFlags);
|
mMatInfoFlagsSC = shader->getShaderConstHandle(ShaderGenVars::matInfoFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CustomFeatureShaderConstHandles::init(GFXShader *shader, Vector<CustomShaderFeatureData*> customFeatureData)
|
||||||
|
{
|
||||||
|
for (U32 f = 0; f < customFeatureData.size(); ++f)
|
||||||
|
{
|
||||||
|
for (U32 i = 0; i < customFeatureData[f]->mAddedShaderConstants.size(); ++i)
|
||||||
|
{
|
||||||
|
handleData newSC;
|
||||||
|
newSC.handle = shader->getShaderConstHandle(customFeatureData[f]->mAddedShaderConstants[i]);
|
||||||
|
newSC.handleName = customFeatureData[f]->mAddedShaderConstants[i];
|
||||||
|
|
||||||
|
mHandles.push_back(newSC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// ShaderRenderPassData
|
/// ShaderRenderPassData
|
||||||
///
|
///
|
||||||
|
|
@ -659,6 +676,9 @@ bool ProcessedShaderMaterial::_addPass( ShaderRenderPassData &rpd,
|
||||||
return false;
|
return false;
|
||||||
rpd.shaderHandles.init( rpd.shader );
|
rpd.shaderHandles.init( rpd.shader );
|
||||||
|
|
||||||
|
//Store our customShaderFeature handles
|
||||||
|
rpd.customFeatureShaderHandles.init(rpd.shader, mMaterial->mCustomShaderFeatures);
|
||||||
|
|
||||||
// If a pass glows, we glow
|
// If a pass glows, we glow
|
||||||
if( rpd.mGlow )
|
if( rpd.mGlow )
|
||||||
mHasGlow = true;
|
mHasGlow = true;
|
||||||
|
|
@ -1297,6 +1317,20 @@ void ProcessedShaderMaterial::setSceneInfo(SceneRenderState * state, const Scene
|
||||||
for ( U32 i=0; i < rpd->featureShaderHandles.size(); i++ )
|
for ( U32 i=0; i < rpd->featureShaderHandles.size(); i++ )
|
||||||
rpd->featureShaderHandles[i]->setConsts( state, sgData, shaderConsts );
|
rpd->featureShaderHandles[i]->setConsts( state, sgData, shaderConsts );
|
||||||
|
|
||||||
|
for (U32 i = 0; i < sgData.customShaderData.size(); i++)
|
||||||
|
{
|
||||||
|
//roll through and try setting our data!
|
||||||
|
for (U32 h = 0; h < rpd->customFeatureShaderHandles.mHandles.size(); ++h)
|
||||||
|
{
|
||||||
|
if (rpd->customFeatureShaderHandles.mHandles[h].handleName == sgData.customShaderData[i]->getHandleName())
|
||||||
|
{
|
||||||
|
if(sgData.customShaderData[i]->getType() == CustomShaderBindingData::Float)
|
||||||
|
shaderConsts->setSafe(rpd->customFeatureShaderHandles.mHandles[h].handle, sgData.customShaderData[i]->getFloat());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LIGHTMGR->setLightInfo( this, mMaterial, sgData, state, pass, shaderConsts );
|
LIGHTMGR->setLightInfo( this, mMaterial, sgData, state, pass, shaderConsts );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,21 @@ public:
|
||||||
GFXShaderConstHandle* mNodeTransforms;
|
GFXShaderConstHandle* mNodeTransforms;
|
||||||
|
|
||||||
void init( GFXShader* shader, CustomMaterial* mat = NULL );
|
void init( GFXShader* shader, CustomMaterial* mat = NULL );
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class CustomFeatureShaderConstHandles
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct handleData
|
||||||
|
{
|
||||||
|
StringTableEntry handleName;
|
||||||
|
GFXShaderConstHandle* handle;
|
||||||
|
};
|
||||||
|
|
||||||
|
Vector<handleData> mHandles;
|
||||||
|
|
||||||
|
void init(GFXShader *shader, Vector<CustomShaderFeatureData*> customFeatureData);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ShaderRenderPassData : public RenderPassData
|
class ShaderRenderPassData : public RenderPassData
|
||||||
|
|
@ -109,6 +124,7 @@ public:
|
||||||
|
|
||||||
GFXShaderRef shader;
|
GFXShaderRef shader;
|
||||||
ShaderConstHandles shaderHandles;
|
ShaderConstHandles shaderHandles;
|
||||||
|
CustomFeatureShaderConstHandles customFeatureShaderHandles;
|
||||||
Vector<ShaderFeatureConstHandles*> featureShaderHandles;
|
Vector<ShaderFeatureConstHandles*> featureShaderHandles;
|
||||||
|
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@
|
||||||
|
|
||||||
class GFXTexHandle;
|
class GFXTexHandle;
|
||||||
class GFXCubemap;
|
class GFXCubemap;
|
||||||
|
class CustomShaderBindingData;
|
||||||
|
|
||||||
struct SceneData
|
struct SceneData
|
||||||
{
|
{
|
||||||
|
|
@ -92,6 +92,8 @@ struct SceneData
|
||||||
/// features.
|
/// features.
|
||||||
void *materialHint;
|
void *materialHint;
|
||||||
|
|
||||||
|
Vector<CustomShaderBindingData*> customShaderData;
|
||||||
|
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
SceneData()
|
SceneData()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,7 @@ void RenderBinManager::setupSGData( MeshRenderInst *ri, SceneData &data )
|
||||||
data.lightmap = ri->lightmap;
|
data.lightmap = ri->lightmap;
|
||||||
data.visibility = ri->visibility;
|
data.visibility = ri->visibility;
|
||||||
data.materialHint = ri->materialHint;
|
data.materialHint = ri->materialHint;
|
||||||
|
data.customShaderData = ri->mCustomShaderData;
|
||||||
}
|
}
|
||||||
|
|
||||||
DefineEngineMethod( RenderBinManager, getBinType, const char*, (),,
|
DefineEngineMethod( RenderBinManager, getBinType, const char*, (),,
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,8 @@ struct RenderInst;
|
||||||
class MatrixSet;
|
class MatrixSet;
|
||||||
class GFXPrimitiveBufferHandle;
|
class GFXPrimitiveBufferHandle;
|
||||||
|
|
||||||
|
class CustomShaderBindingData;
|
||||||
|
|
||||||
/// A RenderInstType hash value.
|
/// A RenderInstType hash value.
|
||||||
typedef U32 RenderInstTypeHash;
|
typedef U32 RenderInstTypeHash;
|
||||||
|
|
||||||
|
|
@ -382,6 +384,9 @@ struct MeshRenderInst : public RenderInst
|
||||||
const char *objectName;
|
const char *objectName;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//Custom Shader data
|
||||||
|
Vector<CustomShaderBindingData*> mCustomShaderData;
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,9 @@
|
||||||
#ifndef _GFXDEVICE_H_
|
#ifndef _GFXDEVICE_H_
|
||||||
#include "gfx/gfxDevice.h"
|
#include "gfx/gfxDevice.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef _TSRENDERDATA_H_
|
||||||
|
#include "ts/tsRenderState.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
class SceneManager;
|
class SceneManager;
|
||||||
class SceneRenderState;
|
class SceneRenderState;
|
||||||
|
|
|
||||||
|
|
@ -219,6 +219,8 @@ void CustomFeatureHLSL::addUniform(String name, String type, String defaultValue
|
||||||
newVarHolder.constSortPos = cspPrimitive;
|
newVarHolder.constSortPos = cspPrimitive;
|
||||||
|
|
||||||
mVars.push_back(newVarHolder);
|
mVars.push_back(newVarHolder);
|
||||||
|
|
||||||
|
mOwner->mAddedShaderConstants.push_back(StringTable->insert(name.c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -236,6 +238,8 @@ void CustomFeatureHLSL::addSampler(String name, String type, U32 arraySize)
|
||||||
newVarHolder.constNum = Var::getTexUnitNum(); // used as texture unit num here
|
newVarHolder.constNum = Var::getTexUnitNum(); // used as texture unit num here
|
||||||
|
|
||||||
mVars.push_back(newVarHolder);
|
mVars.push_back(newVarHolder);
|
||||||
|
|
||||||
|
mOwner->mAddedShaderConstants.push_back(StringTable->insert(name.c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -281,6 +285,8 @@ void CustomFeatureHLSL::addTexture(String name, String type, String samplerState
|
||||||
newVarHolder.constNum = constNum; // used as texture unit num here
|
newVarHolder.constNum = constNum; // used as texture unit num here
|
||||||
|
|
||||||
mVars.push_back(newVarHolder);
|
mVars.push_back(newVarHolder);
|
||||||
|
|
||||||
|
mOwner->mAddedShaderConstants.push_back(StringTable->insert(name.c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ class CustomShaderFeatureData : public SimObject
|
||||||
public:
|
public:
|
||||||
CustomFeatureHLSL* mFeatureHLSL;
|
CustomFeatureHLSL* mFeatureHLSL;
|
||||||
|
|
||||||
|
Vector<StringTableEntry> mAddedShaderConstants;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CustomShaderFeatureData();
|
CustomShaderFeatureData();
|
||||||
virtual ~CustomShaderFeatureData();
|
virtual ~CustomShaderFeatureData();
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,8 @@ void TSMesh::innerRender( TSMaterialList *materials, const TSRenderState &rdata,
|
||||||
|
|
||||||
coreRI->materialHint = rdata.getMaterialHint();
|
coreRI->materialHint = rdata.getMaterialHint();
|
||||||
|
|
||||||
|
coreRI->mCustomShaderData = rdata.getCustomShaderBinding();
|
||||||
|
|
||||||
coreRI->visibility = meshVisibility;
|
coreRI->visibility = meshVisibility;
|
||||||
coreRI->cubemap = rdata.getCubemap();
|
coreRI->cubemap = rdata.getCubemap();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ class TSShape;
|
||||||
|
|
||||||
struct CustomShaderBindingData
|
struct CustomShaderBindingData
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
enum UniformType
|
enum UniformType
|
||||||
{
|
{
|
||||||
Float = 0,
|
Float = 0,
|
||||||
|
|
@ -58,18 +59,59 @@ struct CustomShaderBindingData
|
||||||
Matrix4x3,
|
Matrix4x3,
|
||||||
Matrix4x4
|
Matrix4x4
|
||||||
};
|
};
|
||||||
|
private:
|
||||||
String targetedUniformName;
|
StringTableEntry targetedUniformName;
|
||||||
|
|
||||||
//ShaderConstHandles shaderConstHandle;
|
//ShaderConstHandles shaderConstHandle;
|
||||||
|
|
||||||
UniformType type;
|
UniformType type;
|
||||||
|
|
||||||
void* data; //for numeric data
|
F32 mFloat;
|
||||||
|
Point2F mFloat2;
|
||||||
|
Point3F mFloat3;
|
||||||
|
Point4F mFloat4;
|
||||||
|
|
||||||
//Image stuff
|
//Image stuff
|
||||||
GFXTexHandle texture;
|
GFXTexHandle texture;
|
||||||
GFXSamplerStateDesc samplerState;
|
GFXSamplerStateDesc samplerState;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void setFloat(StringTableEntry shaderConstName, F32 f)
|
||||||
|
{
|
||||||
|
targetedUniformName = shaderConstName;
|
||||||
|
mFloat = f;
|
||||||
|
type = Float;
|
||||||
|
}
|
||||||
|
F32 getFloat() { return mFloat; }
|
||||||
|
|
||||||
|
void setFloat2(StringTableEntry shaderConstName, Point2F f)
|
||||||
|
{
|
||||||
|
targetedUniformName = shaderConstName;
|
||||||
|
mFloat2 = f;
|
||||||
|
type = Float2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setFloat3(StringTableEntry shaderConstName, Point3F f)
|
||||||
|
{
|
||||||
|
targetedUniformName = shaderConstName;
|
||||||
|
mFloat3 = f;
|
||||||
|
type = Float3;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setFloat4(StringTableEntry shaderConstName, Point4F f)
|
||||||
|
{
|
||||||
|
targetedUniformName = shaderConstName;
|
||||||
|
mFloat4 = f;
|
||||||
|
type = Float4;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringTableEntry getHandleName() {
|
||||||
|
return targetedUniformName;
|
||||||
|
}
|
||||||
|
|
||||||
|
UniformType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A simple class for passing render state through the pre-render pipeline.
|
/// A simple class for passing render state through the pre-render pipeline.
|
||||||
|
|
@ -151,7 +193,7 @@ protected:
|
||||||
U32 mNodeTransformCount;
|
U32 mNodeTransformCount;
|
||||||
|
|
||||||
//Custom Shader data
|
//Custom Shader data
|
||||||
Vector<CustomShaderBindingData> mCustomShaderData;
|
Vector<CustomShaderBindingData*> mCustomShaderData;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TSRenderState();
|
TSRenderState();
|
||||||
|
|
@ -200,6 +242,15 @@ public:
|
||||||
void setAccuTex( GFXTextureObject* query ) { mAccuTex = query; }
|
void setAccuTex( GFXTextureObject* query ) { mAccuTex = query; }
|
||||||
GFXTextureObject* getAccuTex() const { return mAccuTex; }
|
GFXTextureObject* getAccuTex() const { return mAccuTex; }
|
||||||
|
|
||||||
|
void addCustomShaderBinding(CustomShaderBindingData* data)
|
||||||
|
{
|
||||||
|
mCustomShaderData.push_back(data);
|
||||||
|
}
|
||||||
|
Vector<CustomShaderBindingData*> getCustomShaderBinding() const
|
||||||
|
{
|
||||||
|
return mCustomShaderData;
|
||||||
|
}
|
||||||
|
|
||||||
///@ see mNodeTransforms, mNodeTransformCount
|
///@ see mNodeTransforms, mNodeTransformCount
|
||||||
void setNodeTransforms(MatrixF *list, U32 count) { mNodeTransforms = list; mNodeTransformCount = count; }
|
void setNodeTransforms(MatrixF *list, U32 count) { mNodeTransforms = list; mNodeTransformCount = count; }
|
||||||
void getNodeTransforms(MatrixF **list, U32 *count) const { *list = mNodeTransforms; *count = mNodeTransformCount; }
|
void getNodeTransforms(MatrixF **list, U32 *count) const { *list = mNodeTransforms; *count = mNodeTransformCount; }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue