T3d 1.1 - Passing a custom value to a shader?
by Jack Stone · in Torque 3D Professional · 06/07/2012 (2:51 pm) · 3 replies
Hello,
I have been working on shaders in T3D for some time now, and I seem to have gotten stuck with what I thought would be a fairly simple task.
What I want to do is pass a value (an XYZ position, so, a Point3F?) from script to a shader, and be able to update this value dynamically. So, for example: myShader.customPosition = "X Y Z".
I understand that to do this I need to create a custom shader constant, which I believe I have done. I have used these three resources:
http://www.garagegames.com/community/resources/view/19161/1
http://www.garagegames.com/community/forums/viewthread/117615
http://www.garagegames.com/community/blogs/view/15211
They all seemed to make sense, and compiled perfectly. However, I don't know how to access my custom value in the shader itself.
It seems that in older versions of the engine, this code was used:
However, in T3D 1.1, that code changes to:
Thanks for any advice!
I have been working on shaders in T3D for some time now, and I seem to have gotten stuck with what I thought would be a fairly simple task.
What I want to do is pass a value (an XYZ position, so, a Point3F?) from script to a shader, and be able to update this value dynamically. So, for example: myShader.customPosition = "X Y Z".
I understand that to do this I need to create a custom shader constant, which I believe I have done. I have used these three resources:
http://www.garagegames.com/community/resources/view/19161/1
http://www.garagegames.com/community/forums/viewthread/117615
http://www.garagegames.com/community/blogs/view/15211
They all seemed to make sense, and compiled perfectly. However, I don't know how to access my custom value in the shader itself.
It seems that in older versions of the engine, this code was used:
//Script Controlled Variables
GFX->setPixelShaderConstF( PC_USERDEF1, (float*)&mMaterial->collisionPos[stageNum], 1 );Which uses the PC_USERDEF1 register. This makes sense, since I can then use:uniform float3 collisionPos : register(PC_USERDEF1)in my shader to access the value.
However, in T3D 1.1, that code changes to:
if ( handles->mCollisionPos->isValid() ){
shaderConsts->setSafe( handles->mCollisionPos, mMaterial->collisionPos[stageNum]);
}This doesn't seem to use a register? So I am confused as to how to access this value from the shader, and use it? I must be missing something obvious here, surely passing a custom value to a shader is a fairly common thing to want to do? Thanks for any advice!
Torque 3D Owner Jack Stone
I have created an addField in MaterialDefinition, everything seems ok, but in processedShaderMaterial.cpp, this line:
Never received the proper value from script. mMaterial->mcollisionPos is always set to the value specified in the constructor, so it seems the addField isn't working.
Any idea why this might be?