osg fbo(三)中,把整个屏幕变绿了,因为是把shader添加到了颜色缓冲区图片上了。如果只想把牛变绿,就需要把shader添加到原始场景根中。
即
osg::ref_ptr<osg::StateSet> statset_SceneRoot = sceneRoot->getOrCreateStateSet();
statset_SceneRoot->setAttribute(program1, osg::StateAttribute::ON);
运行结果如下:
代码如下:
#include <osgDB/ReadFile>
#include <osgUtil/Optimizer>
#include <osg/CoordinateSystemNode>
#include <osg/Switch>
#include <osg/Types>
#include <osgText/Text>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osgGA/StateSetManipulator>
#include <osgGA/AnimationPa

该代码示例展示了如何在OpenSceneGraph(osg)中通过Shader将屏幕整体变绿,以及如何只对场景中的特定对象(如牛)应用着色。首先,创建并添加顶点和片段着色器到场景根节点的状态集中,然后设置渲染到纹理的Camera,最后将纹理应用到一个几何体面板上显示。通过这种方式,可以实现对特定物体的颜色控制。
最低0.47元/天 解锁文章
900

被折叠的 条评论
为什么被折叠?



