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 » Sat May 17, 2008 6:30 am

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!!
0 x

Princess_ConeCloon
Kobold
Posts: 39
Joined: Thu Sep 01, 2005 1:10 am

Post by Princess_ConeCloon » Sat May 17, 2008 7:15 am

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);
0 x

shaill
Greenskin
Posts: 103
Joined: Wed Mar 12, 2008 5:12 pm

Post by shaill » Sat May 17, 2008 9:24 am

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.
0 x

User avatar
betajaen
OGRE Moderator
OGRE Moderator
Posts: 3447
Joined: Mon Jul 18, 2005 4:15 pm
Location: Wales, UK
Contact:

Post by betajaen » Sat May 17, 2008 11:43 am

shaill wrote:Got it!! Thanks!!^^
If there is more detailed information, please tell me.
http://www.ogre3d.org/wiki/index.php/Fa ... ect_Shader
0 x

shaill
Greenskin
Posts: 103
Joined: Wed Mar 12, 2008 5:12 pm

Post by shaill » Sun May 18, 2008 7:23 am

Thanks for ur help. But this seems not about my topic :o
0 x

User avatar
HexiDave
OGRE Expert User
OGRE Expert User
Posts: 1538
Joined: Sat Jan 14, 2006 8:00 pm

Post by HexiDave » Sun May 18, 2008 7:41 am

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.
0 x

kro
Gnoblar
Posts: 24
Joined: Wed Aug 02, 2006 1:02 pm
Location: Copenhagen, Denmark

Post by kro » Sun May 18, 2008 9:34 am

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);
...
0 x

shaill
Greenskin
Posts: 103
Joined: Wed Mar 12, 2008 5:12 pm

Post by shaill » Sun May 18, 2008 10:25 am

Thanks kro and HexiDave.
I'll read it!! :)
0 x

Post Reply