记录ogre中gpu程序在compositor中使用问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mansir123/article/details/78549622

ogre中通过更改gpu程序中的参数,获取到自己想要的渲染效果。在使用到compositor中时,跟一般通过材质中fragmentprogram更改是不同的。需要在某个compositor的监听函数中,更改参数。
参考ogre的compositor例子,新建监听类并继承自Ogre::CompositorInstance::Listener,由于我需要的是在每一帧更改参数,所以重写了notifyMaterialRender函数。具体方法如下:

if (mat->getName().find("自己的材质名称")!=Ogre::String::npos)//之所以用find是因为材质到了compositor中会加前缀进去,跟compositor文件中的材质名有差别。具体原因是因为ogre在解析compositor时会新建材质
    {
        Ogre::GpuProgramParametersSharedPtr ptr=    mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();

        if (ptr->_findNamedConstantDefinition("br"))
        {
            ptr->setNamedConstant("br",(Ogre::Real)(mAssistCam->getPosition().z/10.0));
        }
    }

总结:失败的根本原因是compositor中材质,与材质管理器通过名称获取到的材质,并不是一个材质了。

猜你喜欢

转载自blog.csdn.net/mansir123/article/details/78549622