2012-09-19 15:15:01 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// 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 _MATERIALS_PROCESSEDSHADERMATERIAL_H_
|
|
|
|
|
#define _MATERIALS_PROCESSEDSHADERMATERIAL_H_
|
|
|
|
|
|
|
|
|
|
#ifndef _MATERIALS_PROCESSEDMATERIAL_H_
|
|
|
|
|
#include "processedMaterial.h"
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef _GFXSHADER_H_
|
|
|
|
|
#include "gfx/gfxShader.h"
|
|
|
|
|
#endif
|
2017-10-26 22:06:27 +00:00
|
|
|
#ifndef CUSTOMSHADERBINDINGDATA_H
|
|
|
|
|
#include "materials/customShaderBindingData.h"
|
|
|
|
|
#endif
|
2012-09-19 15:15:01 +00:00
|
|
|
|
|
|
|
|
class GenericConstBufferLayout;
|
|
|
|
|
class ShaderData;
|
|
|
|
|
class LightInfo;
|
|
|
|
|
class ShaderMaterialParameterHandle;
|
|
|
|
|
class ShaderFeatureConstHandles;
|
|
|
|
|
class CustomMaterial;
|
|
|
|
|
|
|
|
|
|
class ShaderConstHandles
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
GFXShaderConstHandle* mDiffuseColorSC;
|
|
|
|
|
GFXShaderConstHandle* mToneMapTexSC;
|
|
|
|
|
GFXShaderConstHandle* mTexMatSC;
|
|
|
|
|
GFXShaderConstHandle* mSpecularColorSC;
|
2018-09-16 01:19:57 +00:00
|
|
|
GFXShaderConstHandle* mSmoothnessSC;
|
|
|
|
|
GFXShaderConstHandle* mMetalnessSC;
|
2012-09-19 15:15:01 +00:00
|
|
|
GFXShaderConstHandle* mParallaxInfoSC;
|
2014-12-21 20:07:42 +00:00
|
|
|
GFXShaderConstHandle* mAccuScaleSC;
|
|
|
|
|
GFXShaderConstHandle* mAccuDirectionSC;
|
|
|
|
|
GFXShaderConstHandle* mAccuStrengthSC;
|
|
|
|
|
GFXShaderConstHandle* mAccuCoverageSC;
|
|
|
|
|
GFXShaderConstHandle* mAccuSpecularSC;
|
2012-09-19 15:15:01 +00:00
|
|
|
GFXShaderConstHandle* mFogDataSC;
|
|
|
|
|
GFXShaderConstHandle* mFogColorSC;
|
|
|
|
|
GFXShaderConstHandle* mDetailScaleSC;
|
|
|
|
|
GFXShaderConstHandle* mVisiblitySC;
|
|
|
|
|
GFXShaderConstHandle* mColorMultiplySC;
|
|
|
|
|
GFXShaderConstHandle* mAlphaTestValueSC;
|
|
|
|
|
GFXShaderConstHandle* mModelViewProjSC;
|
|
|
|
|
GFXShaderConstHandle* mWorldViewOnlySC;
|
|
|
|
|
GFXShaderConstHandle* mWorldToCameraSC;
|
2018-10-28 10:42:26 +00:00
|
|
|
GFXShaderConstHandle* mCameraToWorldSC;
|
2012-09-19 15:15:01 +00:00
|
|
|
GFXShaderConstHandle* mWorldToObjSC;
|
|
|
|
|
GFXShaderConstHandle* mViewToObjSC;
|
|
|
|
|
GFXShaderConstHandle* mCubeTransSC;
|
2017-06-23 16:36:20 +00:00
|
|
|
GFXShaderConstHandle* mCubeMipsSC;
|
2012-09-19 15:15:01 +00:00
|
|
|
GFXShaderConstHandle* mObjTransSC;
|
|
|
|
|
GFXShaderConstHandle* mCubeEyePosSC;
|
|
|
|
|
GFXShaderConstHandle* mEyePosSC;
|
|
|
|
|
GFXShaderConstHandle* mEyePosWorldSC;
|
|
|
|
|
GFXShaderConstHandle* m_vEyeSC;
|
|
|
|
|
GFXShaderConstHandle* mEyeMatSC;
|
|
|
|
|
GFXShaderConstHandle* mOneOverFarplane;
|
|
|
|
|
GFXShaderConstHandle* mAccumTimeSC;
|
|
|
|
|
GFXShaderConstHandle* mMinnaertConstantSC;
|
|
|
|
|
GFXShaderConstHandle* mSubSurfaceParamsSC;
|
|
|
|
|
GFXShaderConstHandle* mDiffuseAtlasParamsSC;
|
|
|
|
|
GFXShaderConstHandle* mBumpAtlasParamsSC;
|
|
|
|
|
GFXShaderConstHandle* mDiffuseAtlasTileSC;
|
|
|
|
|
GFXShaderConstHandle* mBumpAtlasTileSC;
|
|
|
|
|
GFXShaderConstHandle *mRTSizeSC;
|
|
|
|
|
GFXShaderConstHandle *mOneOverRTSizeSC;
|
|
|
|
|
GFXShaderConstHandle* mDetailBumpStrength;
|
|
|
|
|
GFXShaderConstHandle* mViewProjSC;
|
|
|
|
|
|
|
|
|
|
GFXShaderConstHandle *mImposterUVs;
|
|
|
|
|
GFXShaderConstHandle *mImposterLimits;
|
|
|
|
|
|
The final step (barring any overlooked missing bits, requested refactors, and of course, rolling in dependencies already submitted as PRs) consists of:
renderPrePassMgr.cpp related:
A) shifting .addFeature( MFT_XYZ); calls from ProcessedShaderMaterial::_determineFeatures to ProcessedPrePassMaterial::_determineFeatures
B) mimicking the "// set the XXX if different" entries from RenderMeshMgr::render in RenderPrePassMgr::render
C) fleshing out ProcessedPrePassMaterial::getNumStages() so that it shares a 1:1 correlation with ProcessedShaderMaterial::getNumStages()
D) causing inline void Swizzle<T, mapLength>::ToBuffer( void *destination, const void *source, const dsize_t size ) to silently fail rather than fatally assert if a source or destination buffer is not yet ready to be filled. (support for #customTarget scripted render targets)
Reflections:
A) removing reflectRenderState.disableAdvancedLightingBins(true); entries. this would otherwise early out from prepass and provide no color data whatsoever.
B) removing the fd.features.addFeature( MFT_ForwardShading ); entry forcing all materials to be forward lit when reflected.
C) 2 things best described bluntly as working hacks:
C1) when reflected, a scattersky is rotated PI along it's z then x axis in order to draw properly.
C2) along similar lines, in terraincellmaterial, we shut off culling if it's a prepass material.
Skies: scattersky is given a pair of rotations for reflection purposes, all sky objects are given a z value for depth testing.
2016-02-16 08:50:49 +00:00
|
|
|
// Deferred Shading : Material Info Flags
|
|
|
|
|
GFXShaderConstHandle* mMatInfoFlagsSC;
|
|
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
GFXShaderConstHandle* mTexHandlesSC[Material::MAX_TEX_PER_PASS];
|
|
|
|
|
GFXShaderConstHandle* mRTParamsSC[TEXTURE_STAGE_COUNT];
|
|
|
|
|
|
2015-01-10 19:41:25 +00:00
|
|
|
GFXShaderConstHandle* mNodeTransforms;
|
|
|
|
|
|
2017-10-19 20:34:57 +00:00
|
|
|
struct customHandleData
|
|
|
|
|
{
|
|
|
|
|
StringTableEntry handleName;
|
|
|
|
|
GFXShaderConstHandle* handle;
|
|
|
|
|
};
|
|
|
|
|
Vector<customHandleData> mCustomHandles;
|
|
|
|
|
|
|
|
|
|
void init( GFXShader* shader, Vector<CustomShaderFeatureData*> customFeatureData, CustomMaterial* mat = NULL);
|
2017-10-10 20:54:54 +00:00
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ShaderRenderPassData : public RenderPassData
|
|
|
|
|
{
|
|
|
|
|
typedef RenderPassData Parent;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
virtual ~ShaderRenderPassData() { reset(); }
|
|
|
|
|
|
|
|
|
|
GFXShaderRef shader;
|
|
|
|
|
ShaderConstHandles shaderHandles;
|
|
|
|
|
Vector<ShaderFeatureConstHandles*> featureShaderHandles;
|
|
|
|
|
|
|
|
|
|
virtual void reset();
|
|
|
|
|
virtual String describeSelf() const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ProcessedShaderMaterial : public ProcessedMaterial
|
|
|
|
|
{
|
|
|
|
|
typedef ProcessedMaterial Parent;
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
ProcessedShaderMaterial();
|
|
|
|
|
ProcessedShaderMaterial(Material &mat);
|
|
|
|
|
~ProcessedShaderMaterial();
|
|
|
|
|
|
|
|
|
|
// ProcessedMaterial
|
|
|
|
|
virtual bool init( const FeatureSet &features,
|
|
|
|
|
const GFXVertexFormat *vertexFormat,
|
|
|
|
|
const MatFeaturesDelegate &featuresDelegate );
|
|
|
|
|
virtual bool setupPass(SceneRenderState *, const SceneData& sgData, U32 pass);
|
|
|
|
|
virtual void setTextureStages(SceneRenderState *, const SceneData &sgData, U32 pass );
|
|
|
|
|
virtual void setTransforms(const MatrixSet &matrixSet, SceneRenderState *state, const U32 pass);
|
2015-01-10 19:41:25 +00:00
|
|
|
virtual void setNodeTransforms(const MatrixF *address, const U32 numTransforms, const U32 pass);
|
2017-10-26 22:06:27 +00:00
|
|
|
virtual void setCustomShaderData(Vector<CustomShaderBindingData> &shaderData, const U32 pass);
|
2012-09-19 15:15:01 +00:00
|
|
|
virtual void setSceneInfo(SceneRenderState *, const SceneData& sgData, U32 pass);
|
|
|
|
|
virtual void setBuffers(GFXVertexBufferHandleBase* vertBuffer, GFXPrimitiveBufferHandle* primBuffer);
|
|
|
|
|
virtual bool stepInstance();
|
|
|
|
|
virtual void dumpMaterialInfo();
|
2019-05-13 05:28:23 +00:00
|
|
|
virtual void getMaterialInfo(GuiTreeViewCtrl* tree, U32 item);
|
2012-09-19 15:15:01 +00:00
|
|
|
virtual MaterialParameters* allocMaterialParameters();
|
|
|
|
|
virtual MaterialParameters* getDefaultMaterialParameters() { return mDefaultParameters; }
|
|
|
|
|
virtual MaterialParameterHandle* getMaterialParameterHandle(const String& name);
|
|
|
|
|
virtual U32 getNumStages();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
Vector<GFXShaderConstDesc> mShaderConstDesc;
|
|
|
|
|
MaterialParameters* mDefaultParameters;
|
|
|
|
|
Vector<ShaderMaterialParameterHandle*> mParameterHandles;
|
|
|
|
|
|
|
|
|
|
/// Hold the instancing state data for the material.
|
|
|
|
|
class InstancingState
|
|
|
|
|
{
|
|
|
|
|
const static U32 COUNT = 200;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
InstancingState()
|
|
|
|
|
: mInstFormat( NULL ),
|
|
|
|
|
mBuffer( NULL ),
|
|
|
|
|
mCount( -1 )
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~InstancingState()
|
|
|
|
|
{
|
|
|
|
|
delete [] mBuffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setFormat( const GFXVertexFormat *instFormat, const GFXVertexFormat *vertexFormat )
|
|
|
|
|
{
|
|
|
|
|
mInstFormat = instFormat;
|
|
|
|
|
mDeclFormat.copy( *vertexFormat );
|
|
|
|
|
mDeclFormat.append( *mInstFormat, 1 );
|
2016-03-20 11:52:11 +00:00
|
|
|
// Let the declaration know we have instancing.
|
|
|
|
|
mDeclFormat.enableInstancing();
|
2012-09-19 15:15:01 +00:00
|
|
|
mDeclFormat.getDecl();
|
|
|
|
|
|
|
|
|
|
delete [] mBuffer;
|
|
|
|
|
mBuffer = new U8[ mInstFormat->getSizeInBytes() * COUNT ];
|
|
|
|
|
mCount = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool step( U8 **outPtr )
|
|
|
|
|
{
|
|
|
|
|
// Are we starting a new draw call?
|
|
|
|
|
if ( mCount < 0 )
|
|
|
|
|
{
|
|
|
|
|
*outPtr = mBuffer;
|
|
|
|
|
mCount = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Increment to the next instance.
|
|
|
|
|
*outPtr += mInstFormat->getSizeInBytes();
|
|
|
|
|
mCount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return mCount < COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void resetStep() { mCount = -1; }
|
|
|
|
|
|
|
|
|
|
U8* getBuffer() const { return mBuffer; }
|
|
|
|
|
|
|
|
|
|
S32 getCount() const { return mCount; }
|
|
|
|
|
|
|
|
|
|
const GFXVertexFormat* getFormat() const { return mInstFormat; }
|
|
|
|
|
|
|
|
|
|
const GFXVertexFormat* getDeclFormat() const { return &mDeclFormat; }
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
GFXVertexFormat mDeclFormat;
|
|
|
|
|
const GFXVertexFormat *mInstFormat;
|
|
|
|
|
U8 *mBuffer;
|
|
|
|
|
S32 mCount;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// The instancing state if this material
|
|
|
|
|
/// supports instancing.
|
|
|
|
|
InstancingState *mInstancingState;
|
|
|
|
|
|
|
|
|
|
/// @name Internal functions
|
|
|
|
|
///
|
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
|
|
/// Adds a pass for the given stage.
|
|
|
|
|
virtual bool _addPass( ShaderRenderPassData &rpd,
|
|
|
|
|
U32 &texIndex,
|
|
|
|
|
MaterialFeatureData &fd,
|
|
|
|
|
U32 stageNum,
|
|
|
|
|
const FeatureSet &features);
|
|
|
|
|
|
|
|
|
|
/// Chooses a blend op for the given pass
|
|
|
|
|
virtual void _setPassBlendOp( ShaderFeature *sf,
|
|
|
|
|
ShaderRenderPassData &passData,
|
|
|
|
|
U32 &texIndex,
|
|
|
|
|
MaterialFeatureData &stageFeatures,
|
|
|
|
|
U32 stageNum,
|
|
|
|
|
const FeatureSet &features);
|
|
|
|
|
|
|
|
|
|
/// Creates passes for the given stage
|
|
|
|
|
virtual bool _createPasses( MaterialFeatureData &fd, U32 stageNum, const FeatureSet &features );
|
|
|
|
|
|
|
|
|
|
/// Fills in the MaterialFeatureData for the given stage
|
|
|
|
|
virtual void _determineFeatures( U32 stageNum,
|
|
|
|
|
MaterialFeatureData &fd,
|
|
|
|
|
const FeatureSet &features );
|
|
|
|
|
|
|
|
|
|
/// Do we have a cubemap on pass?
|
|
|
|
|
virtual bool _hasCubemap(U32 pass);
|
|
|
|
|
|
|
|
|
|
/// Used by setTextureTransforms
|
|
|
|
|
F32 _getWaveOffset( U32 stage );
|
|
|
|
|
|
|
|
|
|
/// Sets texture transformation matrices for texture animations such as scale and wave
|
|
|
|
|
virtual void _setTextureTransforms(const U32 pass);
|
|
|
|
|
|
|
|
|
|
/// Sets all of the necessary shader constants for the given pass
|
|
|
|
|
virtual void _setShaderConstants(SceneRenderState *, const SceneData &sgData, U32 pass);
|
|
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
|
|
void _setPrimaryLightConst(const LightInfo* light, const MatrixF& objTrans, const U32 stageNum);
|
|
|
|
|
|
|
|
|
|
/// This is here to deal with the differences between ProcessedCustomMaterials and ProcessedShaderMaterials.
|
2019-01-08 02:34:19 +00:00
|
|
|
public:
|
2012-09-19 15:15:01 +00:00
|
|
|
virtual GFXShaderConstBuffer* _getShaderConstBuffer(const U32 pass);
|
|
|
|
|
virtual ShaderConstHandles* _getShaderConstHandles(const U32 pass);
|
|
|
|
|
|
2019-01-08 02:34:19 +00:00
|
|
|
protected:
|
2012-09-19 15:15:01 +00:00
|
|
|
///
|
|
|
|
|
virtual void _initMaterialParameters();
|
|
|
|
|
|
|
|
|
|
ShaderRenderPassData* _getRPD(const U32 pass) { return static_cast<ShaderRenderPassData*>(mPasses[pass]); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // _MATERIALS_PROCESSEDSHADERMATERIAL_H_
|