http://blog.csdn.net/ldpxxx/article/details/7855165
首先通过通路获得gpu程序和gpu程序参数:
Ogre::GpuProgramPtr mActiveVertexProgram = mActivePass->getVertexProgram();
Ogre::GpuProgramParameterPtr mActiveVertexParameters = mActivePass->getVertexProgramParameters();
通过通路可以直接得到或设置某些内置unform的值:
pass->getAmbient(),pass->setAmbient().
pass->getDiffuse(); pass->setDiffuse().
pass->getSpecular(); pass->setSpecular();
通过程序代码设置shader中uniform参数值
下面是得到uniform参数:
Ogre::GpuConstantDefinition& def = mActiveVertexParameters->getConstantDefinition(ParamName);
float* pFloat = activeParameters->getFloatPointer(def.physicalIndex);
通过pFloat[elementIndex],就能得到uniform的值了。
设置uniform参数的值:
物理索引可以通过def.physicalIndex得到,这个ElementIndex是事先知道的,如果是vec2,就有两个值,elementindex分别是0,1。
activeParameters->_writeRawConstant(PhysicalIndex + ElementIndex, val);
也可以这样设置:
pass->getFragmentProgramParameters()->setNamedConstant("pssmSplitPoints", splitPoints);
setNamedConstant函数有很多重载的版本
在.material文件中设置shader中uniform参数的值
先定义:
vertex_program GLSL/Ocean2VS glsl
{
source Ocean2GLSL.vert
}
然后在.material中的pass中:
vertex_program_ref GLSL/Ocean2VS
{
param_named_auto eyePosition camera_position_object_space
param_named_auto time time_0_x 100.0
param_named BumpScale float 0.2
param_named textureScale float2 25 26
param_named bumpSpeed float2 0.015 0.005
param_named waveFreq float 0.028
param_named waveAmp float 1.8
}