Setting constant for shader for shapebase
by Anthony Rosenbaum · in Torque 3D Professional · 06/27/2012 (10:38 am) · 7 replies
I am trying to set the color of a shapebase object via custom material. I have it rigged to take a color from the data block and allow it to be updated via a method on the object, all of that works fine, debugger has reported correct values
My problem is that I don't know where to put the setShaderConstBuffer call for shape base, the documentation said to put it in the renderObject but shapebase does note have one. I have tried prepBatchRender() but that does not seem to work.
Where do I put this?
My problem is that I don't know where to put the setShaderConstBuffer call for shape base, the documentation said to put it in the renderObject but shapebase does note have one. I have tried prepBatchRender() but that does not seem to work.
Where do I put this?
GFX->setShader( mShader ); mShaderConsts->setSafe( mPaintColorHandle, mPaintColor ); GFX->setShaderConstBuffer( mShaderConsts ); GFX->setStateBlock( mStateblock );
About the author
#2
If I replace
with
The Handle is valid.
If I add a variable paintColor into that shader (cloudLayerP.hlsl) and retry it doesn't think it exist and the handle is invalid
WHY!!?!?!?!?!?
Does something need to be purged? PLEASE I NEED help from the GFX guru!!!
AR
06/28/2012 (6:08 pm)
This just plain oddIf I replace
mShader = Sim::findObject( "racingMoverShader", shaderData ) ?
shaderData->getShader() : NULL;
. . . .
mPaintColorHandle = mShader->getShaderConstHandle( "$paintColor" );with
mShader = Sim::findObject( "CloudLayerShader", shaderData ) ?
shaderData->getShader() : NULL;
. . . .
mPaintColorHandle = mShader->getShaderConstHandle( "$cloudBaseColor" );The Handle is valid.
If I add a variable paintColor into that shader (cloudLayerP.hlsl) and retry it doesn't think it exist and the handle is invalid
WHY!!?!?!?!?!?
Does something need to be purged? PLEASE I NEED help from the GFX guru!!!
AR
#3
I think that it was written when T3D was still beta, so may not be relevant any more, but it might give you some ideas.
06/29/2012 (2:05 am)
Have you read this article?.I think that it was written when T3D was still beta, so may not be relevant any more, but it might give you some ideas.
#4
but now I am getting a crash, that the shader constant is unassigned.
Which leads me to my initial question where do I put the
render code for shapebase
06/29/2012 (10:57 am)
Ok the handle was invalid because the new variable paintColor has to be declared AND used in the shaderbut now I am getting a crash, that the shader constant is unassigned.
Which leads me to my initial question where do I put the
render code for shapebase
GFX->setShader( mShader ); mShaderConsts->setSafe( mPaintColorHandle, mPaintColor ); GFX->setShaderConstBuffer( mShaderConsts ); GFX->setStateBlock( mStateblock );
#5
06/29/2012 (12:55 pm)
Take a look at BasicClouds::prepRenderImage and BasicClouds::renderObject. You'll find that renderObject is a delegate that is bound to the ObjectRenderingInst.ObjectRenderInst *ri = state->getRenderPass()->allocInst< ObjectRenderInst >(); ri->renderDelegate.bind( this, &BasicClouds::renderObject ); ri->type = RenderPassManager::RIT_Sky; ri->defaultKey = 0; ri->defaultKey2 = 0; state->getRenderPass()->addInst( ri );
#6
www.garagegames.com/community/resources/view/19161/1
It did not like the opaque approach I had to be more verbose and add a new material feature.
AR
06/29/2012 (12:59 pm)
Well it took three attempts but I got it by merging Pat's article with this resourcewww.garagegames.com/community/resources/view/19161/1
It did not like the opaque approach I had to be more verbose and add a new material feature.
AR
#7
So glad that works not it should be quick to get the other consts in
07/02/2012 (2:03 pm)
Ok I got the Opaque way to work, my problem was not adding the const to the customShader I thought it would be initialized via the class instance.So glad that works not it should be quick to get the other consts in
Associate Anthony Rosenbaum
here is a code snippet .
// Find ShaderData ShaderData *shaderData; mShader = Sim::findObject( "racingMoverShader", shaderData ) ? shaderData->getShader() : NULL; if ( !mShader ) { Con::errorf( "ShapeBase::onAdd - could not find racingMoverShader" ); return false; } mShaderConsts = mShader->allocConstBuffer(); mPaintColorHandle = mShader->getShaderConstHandle( "$paintColor" ); // Create StateBlocks GFXStateBlockDesc desc; desc.setCullMode( GFXCullNone ); desc.setBlend( true ); desc.setZReadWrite( false, false ); desc.samplersDefined = true; desc.samplers[0].addressModeU = GFXAddressWrap; desc.samplers[0].addressModeV = GFXAddressWrap; desc.samplers[0].addressModeW = GFXAddressWrap; desc.samplers[0].magFilter = GFXTextureFilterLinear; desc.samplers[0].minFilter = GFXTextureFilterLinear; desc.samplers[0].mipFilter = GFXTextureFilterLinear; desc.samplers[0].textureColorOp = GFXTOPModulate; mStateblock = GFX->createStateBlock( desc );Any thoughts?