How to pass variables to shader code through main program?

Problems building or running the engine, queries about how to use features etc.
Post Reply
shaill
Greenskin
Posts: 103
Joined: Wed Mar 12, 2008 5:12 pm

How to pass variables to shader code through main program?

Post by shaill »

As title,
In my main.cpp, how can I pass the variables(ex. texture, float4, matrix..) to shader code?

Is there any tutorial to teach these things?

Thanks a lot!!
Princess_ConeCloon
Kobold
Posts: 39
Joined: Thu Sep 01, 2005 1:10 am

Post by Princess_ConeCloon »

I've never used it, and I'm not sure if this is what you're looking for:

http://www.ogre3d.org/docs/api/html/cla ... eters.html

Code: Select all

GpuProgramParametersSharedPtr mParams;
mParams = material->getTechnique()->getPass()->getVertexProgram();
mParams = material->getTechnique()->getPass()->getFragmentProgram();
mParams->setNamedConstant("name", value);
shaill
Greenskin
Posts: 103
Joined: Wed Mar 12, 2008 5:12 pm

Post by shaill »

Princess_ConeCloon wrote:I've never used it, and I'm not sure if this is what you're looking for:

http://www.ogre3d.org/docs/api/html/cla ... eters.html

Code: Select all

GpuProgramParametersSharedPtr mParams;
mParams = material->getTechnique()->getPass()->getVertexProgram();
mParams = material->getTechnique()->getPass()->getFragmentProgram();
mParams->setNamedConstant("name", value);
Got it!! Thanks!!^^
If there is more detailed information, please tell me.
User avatar
betajaen
OGRE Moderator
OGRE Moderator
Posts: 3447
Joined: Mon Jul 18, 2005 4:15 pm
Location: Wales, UK
x 58
Contact:

Post by betajaen »

shaill wrote:Got it!! Thanks!!^^
If there is more detailed information, please tell me.
http://www.ogre3d.org/wiki/index.php/Fa ... ect_Shader
shaill
Greenskin
Posts: 103
Joined: Wed Mar 12, 2008 5:12 pm

Post by shaill »

Thanks for ur help. But this seems not about my topic :o
User avatar
HexiDave
OGRE Expert User
OGRE Expert User
Posts: 1538
Joined: Sat Jan 14, 2006 8:00 pm
x 1

Post by HexiDave »

shaill wrote:
Thanks for ur help. But this seems not about my topic :o
Yes, it is - read the page. It talks about setting custom parameters through each renderable item. If you're just talking about materials, that's covered there a bit too.
kro
Gnoblar
Posts: 24
Joined: Wed Aug 02, 2006 1:02 pm
Location: Copenhagen, Denmark

Post by kro »

shaill wrote:
Princess_ConeCloon wrote:I've never used it, and I'm not sure if this is what you're looking for:

http://www.ogre3d.org/docs/api/html/cla ... eters.html

Code: Select all

GpuProgramParametersSharedPtr mParams;
mParams = material->getTechnique()->getPass()->getVertexProgram();
mParams = material->getTechnique()->getPass()->getFragmentProgram();
mParams->setNamedConstant("name", value);
Got it!! Thanks!!^^
If there is more detailed information, please tell me.
I love this feature in OGRE... I setup some named parameters in a program definition:

Code: Select all

...
default_params
{
        // These are overwritten from within code when FFF changes
        param_named fFFOptions float4 0.0 0.0 0.0 0.0
        param_named fFFForceFactor float 0.0
        param_named fFFNearFarClipDistances float4 0.0 1000.0 0 1
        param_named fFFViewMatrix matrix4x4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
...
and in code I set these when needed changed:

Code: Select all

MaterialPtr mat = (MaterialPtr)MaterialManager::getSingleton().getByName("MyMaterial");
Pass* pass = mat->getTechnique("Default")->getPass(0);
GpuProgramParametersSharedPtr parameters = pass->getVertexProgramParameters();
parameters->setNamedConstant("fFFOptions", mData->fFFToggleOptions);
parameters->setNamedConstant("fFFForceFactor", mData->forceFieldCameraForceFactor);
parameters->setNamedConstant("fFFNearFarClipDistances", mData->fFFNearFarClipDistance);
parameters->setNamedConstant("fFFViewMatrix", mData->fFFCameraViewMatrix);
...
shaill
Greenskin
Posts: 103
Joined: Wed Mar 12, 2008 5:12 pm

Post by shaill »

Thanks kro and HexiDave.
I'll read it!! :)
Post Reply