osgfbo(六)从pass的角度考虑,改写fbo(二)

2023-11-11

什么是pass,这个问题,看似简单,也让我头疼。看了osgdefered,pass定义为osg::Camera。杨石兴的osg视频教程定义为osg::Group。

我认为一个passRoot可以定义为一个Group,包含三部分:到目前pass为止的所有摄像机,geode,texture。只要通过viewer->setSceneData(passRoot)就可以看到该pass的内容。
1,摄像机。
摄像机分为采样摄像机,中间处理摄像机,以及最后呈现的摄像机。
摄像机之间如何传递,众说纷纭。osg自带例子上只有采样摄像机和最后呈现的摄像机,并没有中间摄像机,忽略了这步。
实际上,应该按采样顺序和处理顺序依次加载摄像机。

2,geode
geode只是一个空板,被camera->addchild()用来呈现物体。在以前的例子里,是将shader写到geode->getorcreateStateset(),是不科学的,实际上,应该写到camera->getOrCreateStateset()
视频教程上,camera->addchild(上个passRoot)这个方法不科学,因为会导致屏幕死掉,还要额外加上eventhandler
3,texture
这个是承上启下的过程。渲染到纹理,最主要的是传递纹理,而不是传递上个passroot

摄像机通过attach()输出纹理,setTextureAttributeAndModes()处理输入纹理。

先简单改写下
osgfbo(二)中的内容,改写不多,但是思路完全不同。

//final
osg::ref_ptr<osg::Camera> finalCamera = new osg::Camera;
{
	osg::ref_ptr<osg::StateSet> ss = finalCamera->getOrCreateStateSet();
	ss->setTextureAttributeAndModes(0, tex);
	ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF); //设置不受光照影响,不然太暗了就看不清楚
	osg::ref_ptr<osg::Geode> panelGeode = createTexturePanelGeode();
	finalCamera->addChild(panelGeode);
	finalCamera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
}

passRoot->addChild(sampleCamera); //将摄像机加入场景
passRoot->addChild(finalCamera);
viewer->setSceneData(passRoot);

所有代码如下:

#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/AnimationPathManipulator>
#include <osgGA/TerrainManipulator>
#include <osgGA/SphericalManipulator>

#include <osgGA/Device>
#include <osg/Shader>

osg::ref_ptrosg::Texture2D createFloatRectangleTexture(int width, int height)
{
osg::ref_ptrosg::Texture2D tex2D = new osg::Texture2D;
tex2D->setTextureSize(width, height);
tex2D->setInternalFormat(GL_RGBA16F_ARB);
tex2D->setSourceFormat(GL_RGBA);
tex2D->setSourceType(GL_FLOAT);
return tex2D.release();
}
osg::ref_ptrosg::Geode createTexturePanelGeode()
{
osg::ref_ptrosg::Vec3Array vertices = new osg::Vec3Array;
vertices->push_back(osg::Vec3(-1.0f, -1.0f, 0.0f));
vertices->push_back(osg::Vec3(1.0f, -1.0f, 0.0f));
vertices->push_back(osg::Vec3(1.0f, 1.0f, 0.0f));
vertices->push_back(osg::Vec3(-1.0f, 1.0f, 0.0f));

osg::ref_ptr<osg::Vec2Array> texCoord = new osg::Vec2Array;
texCoord->push_back(osg::Vec2(0.0, 0.0));
texCoord->push_back(osg::Vec2(1.0, 0.0));
texCoord->push_back(osg::Vec2(1.0, 1.0));
texCoord->push_back(osg::Vec2(0.0, 1.0));

osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
geom->setVertexArray(vertices);
geom->setTexCoordArray(0, texCoord);
geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4));

osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable(geom);
return geode;

}

int main()
{
osg::ref_ptrosgViewer::Viewer viewer = new osgViewer::Viewer;
std::string strFileName = “D:/OpenSceneGraph-master/OpenSceneGraph-Data-master/cow.osg”;
//各个pass的根
osg::ref_ptrosg::Group passRoot = new osg::Group();
//场景根
osg::ref_ptrosg::Group sceneRoot = new osg::Group();
osg::ref_ptrosg::Node node = osgDB::readNodeFile(strFileName);
sceneRoot->addChild(node);

//获取系统分辨率
unsigned int screenWidth, screenHeight;
osg::GraphicsContext::WindowingSystemInterface * wsInterface = osg::GraphicsContext::getWindowingSystemInterface();
if (!wsInterface)
{
	return -1;
}
wsInterface->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), screenWidth, screenHeight);
int texWidth = screenWidth;
int texHeight = screenHeight;
osg::ref_ptr<osg::Texture2D> tex = createFloatRectangleTexture(texWidth, texHeight);
//绑定pass1采样摄像机
osg::ref_ptr<osg::Camera> sampleCamera = new osg::Camera;
{
	sampleCamera->addChild(sceneRoot);
	sampleCamera->setClearColor(osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
	sampleCamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); //这句话使内容不渲染到屏幕上
	sampleCamera->attach(osg::Camera::COLOR_BUFFER0, tex); //关联采样贴图
	sampleCamera->setViewport(0, 0, screenWidth, screenHeight);//摄像机关联视口

}

//final
osg::ref_ptr<osg::Camera> finalCamera = new osg::Camera;
{
	osg::ref_ptr<osg::StateSet> ss = finalCamera->getOrCreateStateSet();
	ss->setTextureAttributeAndModes(0, tex);
	ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF); //设置不受光照影响,不然太暗了就看不清楚
	osg::ref_ptr<osg::Geode> panelGeode = createTexturePanelGeode();
	finalCamera->addChild(panelGeode);
	finalCamera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
}

passRoot->addChild(sampleCamera); //将摄像机加入场景
passRoot->addChild(finalCamera);
viewer->setSceneData(passRoot);
viewer->run();
return 0;

}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

osgfbo(六)从pass的角度考虑,改写fbo(二) 的相关文章

随机推荐

  • 计算机毕业设计-基于协同过滤算法的农特产商城微信小程序-springboot商城小程序

    注意 该项目只展示部分功能 如需了解 评论区咨询即可 本文目录 1 开发环境 2 系统的设计背景 3 各角色功能模块 3 1 用户 3 2 管理员 4 系统页面展示 4 1 小程序端功能模块展示 4 2 后台管理端功能模块展示 5 更多推荐
  • 什么是MES生产制造执行系统?实施MES生产管理系统有哪些目标?

    一 什么是MES生产制造执行管理系统 MES系统通过控制包括物料 设备 人员 流程指令和设施在内的所有工厂资源 优化从定单到产品完成的整个生产活动 以最少的投入生产出最优的产品 实现连续均衡生产 MES系统通过与ERP DCS系统的全面集成
  • React 实现一个水球图

    代码来源于https github com ant design ant design pro blob all blocks src pages dashboard monitor index tsx 个人 代码实现 实际代码看上面cod
  • 项目中QNX的USB驱动开发的反思

    锋影 e mail 174176320 qq com 接触驱动层的东西 心里还有点小激动 总感觉自己比没搞之前提高了那么一点点 也不知是真的假的 拉出来遛遛 1 整体思路 驱动层 先从驱动层说起 他将USB设备通过Resource Mana
  • 南邮CTF平台writeup:Web(一)

    签到题 查看网页源代码即可 md5 collision md51 md5 QNKCDZO a GET a md52 md5 a if isset a if a QNKCDZO md51 md52 echo nctf else echo fa
  • 做你自己

    2017 03 06 2017 03 10将彼得 巴菲特的书籍 做你自己 个股神巴菲特送给儿子的人生礼物 读完了 感受颇深 沃伦 巴菲特的名言 出生时嘴里含着的金汤匙 最后可能会变成扎在背上的金匕首 考虑不周的赠与会浇灭一个人的雄心并枯竭他
  • Android update api

    修改公共api后 需要 make update api 比较framework base api 下的current xml跟原始x xml 比如2 2为8 xml 2 3 3为10 xml 同时修改x xml 然后make
  • Windows 0x80190001错误解决

    Windows 0x80190001错误 笔者使用的系统版本为win10 2004 若同学们正在使用的系统为Windows 11 请移步这篇文章 Windows11 0x80190001错误解决 windows出现这样的错误 初步判断为wi
  • numpy的两个属性的详解 →→→→arange()和reshape()

    arange 简单的说就是创建了一个数组 print 默认是一维为数组 np arange 5 参数表示从0到5截至 不包括5 print 自定义起点一维数组 np arange 1 5 参数表示从1到5截至 不包括5 print 自定义起
  • mongodb 关于 整数类型 和 字符串类型 索引的比较

    想看看到底是 整数类型的索引快呢 还是字符串类型的索引快 到底快多少呢 内存分别占多少呢 今天就来测试一下 配置 华硕飞行堡垒6 500G 的 SSD 准备数据 a 是 for 循环的变量 id a name abcdefg a 2千万的数
  • python英寸和厘米互换_将厘米转换为英寸的Python程序

    python英寸和厘米互换 There are many problems where we have to calculate the distance in inches at the end but initially the mea
  • Impala链接报错

    impala集成Kerberos链接报错 操作命令 impala shell i 10 250 122 40 19005 k s e3base Error connecting TTransportException Could not s
  • Windows 编程概述(使用 C++)

    Windows 编程概述 使用 C 1 命令行 控制台 应用程序 2 本机桌面客户端应用程序 3 COM 组件 4 通用 Windows 平台应用程序 5 桌面桥 6 游戏 7 SQL Server 数据库客户端 8 Windows设备驱动
  • Qt:QProcess实现cmd命令,带参数.exe程序

    首先引入都文件 include
  • C#系列-set,

    using System public class cls private int book 定义一个域 也可以叫变量 只是面向对像里都这么叫 使用起来也更加方便 public int Book get Console WriteLine
  • DateTimeFormatter、LocalDateTime 的使用

    由于SimpleDateFormat是线程不安全的 所以在多线程中可以使用线程安全的DateTimeFormatter 代替 SimpleDateFormat 阿里巴巴java开发手册推荐 如果是 JDK8 的应用 可以使用 Instant
  • printk,printf 打印调试

    includelinux kernel h define KERN EMERG lt 0 gt 紧急事件消息 系统崩溃之前提示 表示系统不可用 define KERN ALERT lt 1 gt 报告消息 表示必须立即采取措施 define
  • Docker----DockerSwarm集群环境弹性服务动态扩缩容

    详细内容见 DevOps技术社区文章 Docker DockerSwarm集群环境弹性服务动态扩缩容
  • 新词发现

    新词发现是 NLP 的基础任务之一 通过对已有语料进行挖掘 从中识别出新词 新词发现也可称为未登录词识别 严格来讲 新词是指随时代发展而新出现或旧词新用的词语 同时 我认为特定领域的专有名词也可归属于新词的范畴 何出此言呢 通常我们会很容易
  • osgfbo(六)从pass的角度考虑,改写fbo(二)

    什么是pass 这个问题 看似简单 也让我头疼 看了osgdefered pass定义为osg Camera 杨石兴的osg视频教程定义为osg Group 我认为一个passRoot可以定义为一个Group 包含三部分 到目前pass为止