daily pastebin goal
34%
SHARE
TWEET

per_shape_material_test.txt

a guest Apr 30th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Engine\source\materials\materialFeatureTypes.h (before the #endif)
  2.  
  3.    DeclareFeatureType( MFT_ConstantMult );  //test_material
  4.    
  5. Engine\source\materials\materialFeatureTypes.cpp (at the very end)
  6.    
  7.    ImplementFeatureType( MFT_ConstantMult , MFG_PostProcess, 998.0f, true );  //test_material
  8.  
  9. Engine\source\T3D\tsStatic.h (just after protected S32 mForceDetail; and still protected)
  10.  
  11.    ColorF mMultConstant;  //test_material
  12.  
  13. Engine\source\T3D\tsStatic.cpp (in TSStatic::TSStatic())
  14.  
  15.    mMultConstant.set(1.0f, 1.0f, 1.0f, 1.0f);  //test_material
  16.  
  17. Also in Engine\source\T3D\tsStatic.cpp (in void TSStatic::initPersistFields() before Parent::initPersistFields();)
  18.  
  19.    addField("multConstant", TypeColorF, Offset(mMultConstant, Material));  //test_material
  20.  
  21. Also in Engine\source\T3D\tsStatic.cpp (in U32 TSStatic::packUpdate( just after U32 retMask = Parent::packUpdate(con, mask, stream);)
  22.  
  23.    stream->write(mMultConstant);  //test_material
  24.  
  25. Also in Engine\source\T3D\tsStatic.cpp (in void TSStatic::unpackUpdate( just after Parent::unpackUpdate(con, stream);)
  26.  
  27.    stream->read(&mMultConstant);  //test_material
  28.  
  29. Also in Engine\source\T3D\tsStatic.cpp (in void TSStatic::prepRenderImage(after rdata.setOriginSort( mUseOriginSort );)
  30.  
  31.    rdata.setMultConstant( mMultConstant );  //test_material
  32.  
  33. Now, for that last line to work we need to change
  34. Engine\source\ts\tsRenderState.h
  35.  
  36. class TSRenderState
  37. {
  38. protected:
  39.    ColorF mMultConstant;  //test_material
  40. public:
  41.    const ColorF &getMultConstant() const { return mMultConstant; }  //test_material
  42.    void setMultConstant(const ColorF &val) { mMultConstant = val; }  //test_material
  43.  
  44.  
  45. Engine\source\renderInstance\renderPassManager.h (inside struct MeshRenderInst : public RenderInst{ )
  46.  
  47.    ColorF multConstant;  //test_material
  48.  
  49. Engine\source\ts\tsMesh.cpp (in void TSMesh::innerRender( TSMaterialList *materials, const TSRenderState &rdata, TSVertexBufferHandle &vb, GFXPrimitiveBufferHandle &pb ) after coreRI->type = RenderPassManager::RIT_Mesh;)
  50.  
  51.    coreRI->multConstant = rdata.getMultConstant();  //test_material
  52.    
  53. Engine\source\materials\sceneData.h (in struct SceneData{ after F32 visibility;)
  54.  
  55.    ColorF* multConstant;  //test_material
  56.  
  57. Engine\source\renderInstance\renderBinManager.cpp in (void RenderBinManager::setupSGData( )
  58.  
  59.    data.multConstant = &ri->multConstant;  //test_material
  60.  
  61. Create source\constantMult.cpp
  62. --------------------------------------------------------------------------------------------------------------
  63.  
  64. #include "shaderGen/shaderFeature.h"
  65. #include "shaderGen/shaderOp.h"
  66. #include "shaderGen/featureMgr.h"
  67. #include "materials/materialFeatureTypes.h"
  68. #include "materials/sceneData.h"
  69. #include "gfx/gfxDevice.h"
  70.  
  71. class ConstantMultFeature : public ShaderFeature
  72. {
  73. public:
  74.    virtual void processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
  75.    {
  76.       // Find the constant value
  77.       Var *multConst = (Var *)( LangElement::find("multConst") );
  78.       if( multConst == NULL )
  79.       {
  80.          multConst = new Var;
  81.          multConst->setType( GFX->getAdapterType() == OpenGL ? "vec4" : "float4" );
  82.          multConst->setName( "multConst" );
  83.          multConst->constSortPos = cspPotentialPrimitive;
  84.          multConst->uniform = true;
  85.       }
  86.  
  87.       // Find output fragment
  88.       Var *color = (Var*) LangElement::find( getOutputTargetVarName(DefaultTarget) );
  89.       if ( !color )
  90.       {
  91.          color = new Var;
  92.          color->setType( GFX->getAdapterType() == OpenGL ? "vec4" : "fragout" );
  93.          color->setName( getOutputTargetVarName(DefaultTarget) );
  94.  
  95.          if(GFX->getAdapterType() != OpenGL)
  96.             color->setStructName( "OUT" );
  97.  
  98.          output = new GenOp( "@ = @", color, multConst );
  99.       }
  100.       output = new GenOp( "   @ *= @;\r\n", color, multConst );
  101.    }
  102.  
  103.    virtual String getName() { return "ConstantMultFeature"; }
  104.    
  105.    
  106.    class ConstMultFeatureHdls : public ShaderFeatureConstHandles
  107.    {
  108.       GFXShaderConstHandle* mMultConstSC;
  109.      
  110.       public:
  111.      
  112.       ConstMultFeatureHdls( GFXShader *shader )
  113.       {
  114.          mMultConstSC = shader->getShaderConstHandle("$multConst");
  115.       }
  116.      
  117.       void init( GFXShader *shader )
  118.       {
  119.          mMultConstSC = shader->getShaderConstHandle("$multConst");
  120.       }
  121.      
  122.       virtual void setConsts( SceneRenderState *state, const SceneData &sgData, GFXShaderConstBuffer *buffer )
  123.       {
  124.          if( mMultConstSC->isValid() && sgData.multConstant )
  125.          {
  126.             buffer->set( mMultConstSC, *sgData.multConstant );
  127.          }
  128.       }
  129.    };
  130.      
  131.    virtual ShaderFeatureConstHandles* createConstHandles( GFXShader *shader )
  132.    {
  133.       // This memory is cleaned up via a delete call which takes place
  134.       // in ShaderRenderPassData::reset()
  135.      
  136.       ConstMultFeatureHdls *handles = new ConstMultFeatureHdls(shader);
  137.       //handles->init( shader );      
  138.  
  139.       return handles;
  140.      
  141.       //return new ConstMultFeatureHdls( shader );
  142.    }
  143.    
  144.  
  145.    // These methods aren't used
  146.    virtual Var* getVertTexCoord( const String &name ) { return NULL; }
  147.    virtual LangElement *setupTexSpaceMat(  Vector<ShaderComponent*> &componentList, Var **texSpaceMat ) { return NULL; }
  148.    virtual LangElement *expandNormalMap( LangElement *sampleNormalOp, LangElement *normalDecl, LangElement *normalVar, const MaterialFeatureData &fd ) { return NULL; }
  149.    virtual LangElement *assignColor( LangElement *elem, Material::BlendOp blend, LangElement *lerpElem = NULL, ShaderFeature::OutputTarget outputTarget = ShaderFeature::DefaultTarget ) { return NULL; }
  150. };
  151.  
  152.  
  153. class ConstMultFeatureReg
  154. {
  155.    bool _handleGFXEvent(GFXDevice::GFXDeviceEventType evt)
  156.    {
  157.       if( evt == GFXDevice::deInit )
  158.       {
  159.          FEATUREMGR->registerFeature( MFT_ConstantMult, new ConstantMultFeature );
  160.       }
  161.       else if( evt == GFXDevice::deDestroy )
  162.       {
  163.          //this is not needed as it's unregistered in FeatureMgr::~FeatureMgr()
  164.          //FEATUREMGR->unregisterFeature( MFT_ConstantMult );
  165.       }
  166.       return true;
  167.    }
  168.  
  169. public:
  170.    ConstMultFeatureReg()
  171.    {
  172.       GFXDevice::getDeviceEventSignal().notify(this, &ConstMultFeatureReg::_handleGFXEvent, 998.0f);
  173.    }
  174. };
  175.  
  176. static ConstMultFeatureReg sConstMultFeatureReg;
  177. //</ShaderComponent*></ShaderComponent*>
  178.  
  179. --------------------------------------------------------------------------------------------------------------
  180.  
  181.  
  182. Engine/source/materials/processedShaderMaterial.cpp (in void ProcessedShaderMaterial::_determineFeatures( before //Allow features to add themselves.)
  183.  
  184.    if ( mMaterial->mMultConstant )  //test_material
  185.       fd.features.addFeature( MFT_ConstantMult );  //test_material
  186.  
  187.  
  188. Engine/source/materials/materialDefinition.h (after String mMapTo; )
  189.  
  190.    bool mMultConstant;  //test_material
  191.  
  192. Engine\source\materials\materialDefinition.cpp (in Material::Material() at the end)
  193.  
  194.    mMultConstant = false;  //test_material
  195.  
  196. Also Engine\source\materials\materialDefinition.cpp (in void Material::initPersistFields() before Parent::initPersistFields();)
  197.  
  198.    addField("multConstant", TypeBool, Offset(mMultConstant, Material));  //test_material
RAW Paste Data
Top