osg fbo(四),将颜色缓冲区图片中的牛通过shader变绿

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值