十一,从摄像机打印HDR环境贴图

越来越接近真相了。我们很自然地想到,如果把漫游器放在中心打印,是不是就可以打印整个等距柱状投影图了呢?是的,但是,只是要注意的是,立方体贴图的内部和外部尽管一样,但是还是稍微有点模糊,也可以在外部设置漫游器位置六次,打印六次,就像上节那样。但是,这里不考虑这些细节。
也就是把漫游器位置设置为
osg::Vec3d newEye(0, 0, 0);

运行结果不出所料。
在这里插入图片描述

当然,也可以把osg::Image和osg::TextureCubeMap关联起来。使用osg::TextureCubeMap打印。即

int textureWidth = 512;
int textureHeight = 512;osg::ref_ptr<osg::TextureCubeMap> texture = new osg::TextureCubeMap;texture->setTextureSize(textureWidth, textureHeight);
texture->setInternalFormat(GL_RGB);
texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
texture->setWrap(osg::Texture::WRAP_R, osg::Texture::CLAMP_TO_EDGE);

各个面关联,比如
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Y);

	osg::ref_ptr<osg::Image> printImage = new osg::Image;printImage->setFileName(camera->getName());printImage->allocateImage(textureWidth, textureHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);texture->setImage(0, printImage);camera->attach(osg::Camera::COLOR_BUFFER, printImage);

打印时

		int imageNumber = textureCubeMap->getNumImages(); for (int i = 0; i < imageNumber; i++){osg::ref_ptr<osg::Image> theImage = textureCubeMap->getImage(i); std::string strPrintName = "e:/" + theImage->getFileName() + ".bmp";osgDB::writeImageFile(* theImage, strPrintName);}

完整代码如下:
#include <osg/TextureCubeMap>
#include <osg/TexGen>
#include <osg/TexEnvCombine>
#include <osgUtil/ReflectionMapGenerator>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/NodeVisitor>
#include <osg/ShapeDrawable>
#include <osg/Texture2D>
#include <osgGA/TrackballManipulator>
#include <osgDB/WriteFile>
static const char * vertexShader =
{
“in vec3 aPos;\n”
“varying vec3 outPos;”
“void main(void)\n”
“{\n”
“outPos = aPos;\n”
" gl_Position = ftransform();\n"
“}\n”
};

static const char *psShader =
{
“varying vec3 outPos;”
“uniform sampler2D tex0;”
"const vec2 invAtan = vec2(0.1591, 0.3183); "
"vec2 SampleSphericalMap(vec3 v) "
"{ "
" vec2 uv = vec2(atan(v.z, v.x), asin(v.y)); "
" uv *= invAtan; "
" uv += 0.5; "
" return uv; "
"} "

"void main()"
"{"
"vec2 uv = SampleSphericalMap(normalize(outPos)); "
"vec3 color = texture(tex0, uv).rgb;"
"gl_FragColor = vec4(color,1.0);\n"
"}\n"

};
class MyNodeVisitor : public osg::NodeVisitor
{
public:
MyNodeVisitor() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
{

}
void apply(osg::Geode& geode)
{int count = geode.getNumDrawables();for (int i = 0; i < count; i++){osg::ref_ptr<osg::Geometry> geometry = geode.getDrawable(i)->asGeometry();if (!geometry.valid()){continue;}osg::Array* vertexArray = geometry->getVertexArray();geometry->setVertexAttribArray(1, vertexArray);}traverse(geode);
}

};

osg::ref_ptrosg::TextureCubeMap getTextureCubeMap(osgViewer::Viewer& viewer)
{
unsigned int screenWidth, screenHeight;
osg::GraphicsContext::WindowingSystemInterface * wsInterface = osg::GraphicsContext::getWindowingSystemInterface();
wsInterface->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), screenWidth, screenHeight);

osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = 0;
traits->y = 0;
traits->width = screenWidth;
traits->height = screenHeight;
traits->windowDecoration = false;
traits->doubleBuffer = true;
traits->sharedContext = 0;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (!gc)
{osg::notify(osg::NOTICE) << "GraphicsWindow has not been created successfully." << std::endl;return NULL;
}int textureWidth = 512;
int textureHeight = 512;osg::ref_ptr<osg::TextureCubeMap> texture = new osg::TextureCubeMap;texture->setTextureSize(textureWidth, textureHeight);
texture->setInternalFormat(GL_RGB);
texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
texture->setWrap(osg::Texture::WRAP_R, osg::Texture::CLAMP_TO_EDGE);osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT;
// front face
{osg::ref_ptr<osg::Camera> camera = new osg::Camera;camera->setName("Front face camera");camera->setGraphicsContext(gc.get());camera->setViewport(new osg::Viewport(0, 0, textureWidth, textureHeight));camera->setAllowEventFocus(false);camera->setRenderTargetImplementation(renderTargetImplementation);camera->setRenderOrder(osg::Camera::PRE_RENDER);//关联采样贴图camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Y);osg::ref_ptr<osg::Image> printImage = new osg::Image;printImage->setFileName(camera->getName());printImage->allocateImage(textureWidth, textureHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);texture->setImage(0, printImage);camera->attach(osg::Camera::COLOR_BUFFER, printImage);viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd());
}// top face
{osg::ref_ptr<osg::Camera> camera = new osg::Camera;camera->setName("Top face camera");camera->setGraphicsContext(gc.get());camera->setViewport(new osg::Viewport(0, 0, textureWidth, textureHeight));camera->setAllowEventFocus(false);camera->setRenderTargetImplementation(renderTargetImplementation);camera->setRenderOrder(osg::Camera::PRE_RENDER);//关联采样贴图camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Z);osg::ref_ptr<osg::Image> printImage = new osg::Image;printImage->setFileName(camera->getName());printImage->allocateImage(textureWidth, textureHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);texture->setImage(1, printImage);camera->attach(osg::Camera::COLOR_BUFFER, printImage);viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 1.0, 0.0, 0.0));
}// left face
{osg::ref_ptr<osg::Camera> camera = new osg::Camera;camera->setName("Left face camera");camera->setGraphicsContext(gc.get());camera->setViewport(new osg::Viewport(0, 0, textureWidth, textureHeight));camera->setAllowEventFocus(false);camera->setRenderTargetImplementation(renderTargetImplementation);camera->setRenderOrder(osg::Camera::PRE_RENDER); //关联采样贴图camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_X);osg::ref_ptr<osg::Image> printImage = new osg::Image;printImage->setFileName(camera->getName());printImage->allocateImage(textureWidth, textureHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);texture->setImage(2, printImage);camera->attach(osg::Camera::COLOR_BUFFER, printImage);viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0, 1.0, 0.0) * osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0, 0.0, 1.0));
}// right face
{osg::ref_ptr<osg::Camera> camera = new osg::Camera;camera->setName("Right face camera");camera->setGraphicsContext(gc.get());camera->setViewport(new osg::Viewport(0, 0, textureWidth, textureHeight));camera->setAllowEventFocus(false);camera->setRenderTargetImplementation(renderTargetImplementation);camera->setRenderOrder(osg::Camera::PRE_RENDER);//关联采样贴图camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_X);osg::ref_ptr<osg::Image> printImage = new osg::Image;printImage->setFileName(camera->getName());printImage->allocateImage(textureWidth, textureHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);texture->setImage(3, printImage);camera->attach(osg::Camera::COLOR_BUFFER, printImage);viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0, 1.0, 0.0) * osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0, 0.0, 1.0));}// bottom face
{osg::ref_ptr<osg::Camera> camera = new osg::Camera;camera->setGraphicsContext(gc.get());camera->setName("Bottom face camera");camera->setViewport(new osg::Viewport(0, 0, textureWidth, textureHeight));camera->setAllowEventFocus(false);camera->setRenderTargetImplementation(renderTargetImplementation);camera->setRenderOrder(osg::Camera::PRE_RENDER);//关联采样贴图camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Z);osg::ref_ptr<osg::Image> printImage = new osg::Image;printImage->setFileName(camera->getName());printImage->allocateImage(textureWidth, textureHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);texture->setImage(4, printImage);camera->attach(osg::Camera::COLOR_BUFFER, printImage);viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 1.0, 0.0, 0.0) * osg::Matrixd::rotate(osg::inDegrees(180.0f), 0.0, 0.0, 1.0));}// back face
{osg::ref_ptr<osg::Camera> camera = new osg::Camera;camera->setName("Back face camera");camera->setGraphicsContext(gc.get());camera->setViewport(new osg::Viewport(0, 0, textureWidth, textureHeight));camera->setAllowEventFocus(false);camera->setRenderTargetImplementation(renderTargetImplementation);camera->setRenderOrder(osg::Camera::PRE_RENDER);//关联采样贴图camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Y);osg::ref_ptr<osg::Image> printImage = new osg::Image;printImage->setFileName(camera->getName());printImage->allocateImage(textureWidth, textureHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);texture->setImage(5, printImage);camera->attach(osg::Camera::COLOR_BUFFER, printImage);viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(180.0f), 1.0, 0.0, 0.0));}viewer.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 0.1, 10);//viewer.getCamera()->setNearFarRatio(0.0001f);
return texture;

}

int main()
{
std::string strHDRImageName = “D:/tutorial/LearnOpenGL-master/LearnOpenGL-master/resources/textures/hdr/newport_loft.hdr”;
osg::ref_ptrosg::Image image = osgDB::readImageFile(strHDRImageName);

int imageWidth = image->s();
int imageHeight = image->t();
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
texture->setImage(image.get());
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_FLOAT, data);
//
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//texture->osg::ref_ptr<osg::Box> box = new osg::Box(osg::Vec3(0, 0, 0), 1);
osg::ref_ptr<osg::ShapeDrawable> drawable = new osg::ShapeDrawable(box);
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable(drawable);
MyNodeVisitor nv;
geode->accept(nv);
osg::ref_ptr<osg::StateSet> stateset = geode->getOrCreateStateSet();
stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);//shaderosg::ref_ptr<osg::Shader> vs1 = new osg::Shader(osg::Shader::VERTEX, vertexShader);
osg::ref_ptr<osg::Shader> ps1 = new osg::Shader(osg::Shader::FRAGMENT, psShader);
osg::ref_ptr<osg::Program> program1 = new osg::Program;
program1->addShader(vs1);
program1->addShader(ps1);
program1->addBindAttribLocation("aPos", 1);osg::ref_ptr<osg::Uniform> tex0Uniform = new osg::Uniform("tex0", 0);
stateset->addUniform(tex0Uniform);
stateset->setAttribute(program1, osg::StateAttribute::ON);osgViewer::Viewer viewer;
osg::ref_ptr<osgGA::TrackballManipulator> manipulator = new osgGA::TrackballManipulator();
viewer.setCameraManipulator(manipulator);
osg::Vec3d newEye(0, 0, 0);
osg::Vec3 newCenter(0, 0, 0);
osg::Vec3 newUp(0, 1, 0);
manipulator->setHomePosition(newEye, newCenter, newUp);
osg::ref_ptr<osg::TextureCubeMap> textureCubeMap = getTextureCubeMap(viewer);
viewer.setSceneData(geode.get());bool bPrinted = false;
while (!viewer.done())
{viewer.frame();if (!bPrinted){bPrinted = true;int imageNumber = textureCubeMap->getNumImages(); for (int i = 0; i < imageNumber; i++){osg::ref_ptr<osg::Image> theImage = textureCubeMap->getImage(i); std::string strPrintName = "e:/" + theImage->getFileName() + ".bmp";osgDB::writeImageFile(* theImage, strPrintName);}}
}
return 0;

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/91091.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

spring6-IOC容器

IOC容器 1、IoC容器1.1、控制反转&#xff08;IoC&#xff09;1.2、依赖注入1.3、IoC容器在Spring的实现 2、基于XML管理Bean2.1、搭建子模块spring6-ioc-xml2.2、实验一&#xff1a;获取bean①方式一&#xff1a;根据id获取②方式二&#xff1a;根据类型获取③方式三&#xff…

安卓机型不需要解锁bl 不需要root 即可安装模块 框架 VirtualXposed使用步骤分析

​​​​​​安卓玩机教程---全机型安卓4----安卓12 框架xp edx lsp安装方法【一】 安卓系列机型 框架LSP 安装步骤 支持多机型 LSP框架通用安装步骤 通过以上两个博文基本可以了解手机正常安装框架的步骤。但很多机型局限于不能解锁bl和root&#xff0c;那么这些机型能不能使…

vue前端项目中添加独立的静态资源

如果想要在vue项目中放一些独立的静态资源&#xff0c;比如html文件或者用于下载的业务模板或其他文件等&#xff0c;需要在vue打包的时候指定一下静态资源的位置和打包后的目标位置。 使用的是 copy-webpack-plugin 插件&#xff0c;如果没有安装则需要先安装一下&#xff0c;…

Armv9 Cortex-A720的L1 memory system 和 L1 Cache

思考: L1 System memory和L1 Cache是什么关系?L1指令cache禁用时,指令cache就真的不会缓存了吗?此时还会出现缓存不一致的情况吗?L1 data cache禁用时,L1 data cache就真的不会缓存了吗?此时还会出现缓存不一致的情况吗?在下电的时候,cache有什么自动的行为?有没有in…

大数据Flink(九十):Lookup Join(维表 Join)

文章目录 Lookup Join(维表 Join) Lookup Join(维表 Join) Lookup Join 定义(支持 Batch\Streaming):Lookup Join 其实就是维表 Join,比如拿离线数仓来说,常常会有用户画像,设备画像等数据,而对应到实时数仓场景中,这种实时获取外部缓存的 Join 就叫做维表 Join。…

Nginx之upstream被动式重试机制解读z

目录 基本介绍 默认错误 选择定义错误 指令配置 proxy_next_upstream proxy_next_upstream_timeout proxy_next_upstream_tries 重试限制方式 基本介绍 我们使用Nginx通过反向代理做负载均衡时&#xff0c;如果被代理的其中一个服务发生错误或者超时的时候&#xff0…

python抓取网页视频

1. 喜马拉雅音频 1-1 喜马拉雅 import requests import json import time import random import hashliburl https://www.ximalaya.com/revision/play/v1/audio?id46103875&ptype1headers { user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.3…

HUAWEI悦盒ec6108v9c 如何刷成海纳思系统(家用低功耗服务器,使用Home Assistant服务)

环境&#xff1a; 1.HW悦盒ec6108v9c一套 2.16G U盘 3.格式化软件USB_format.exe 4.固件 mv100-mdmo1g-usb-flash.zip&#xff08;底层是Ubuntu 20.04系统&#xff09; 5.十字螺丝刀 6.翘片/薄铲子 7.有线网络环境 8.镊子/回形针 问题描述&#xff1a; 最近玩智能家居…

CH347读写SPI Flash

CH347读写SPI Flash 前面耽搁了几天&#xff0c;今天终于把CH347 SPI接口调试好了。 CH347动态库中SPI接口函数如下&#xff1a; typedef struct _SPI_CONFIG{UCHAR iMode; // 0-3:SPI Mode0/1/2/3UCHAR iClock; // 060…

【数据库】形式化关系查询语言(一):关系代数Relational Algebra

目录 一、关系代数Relational Algebra 1. 基本运算 a. 选择运算&#xff08;Select Operation&#xff09; b. 投影运算&#xff08;Project Operation&#xff09; 组合 c. 并运算&#xff08;Union Operation&#xff09; d. 集合差运算&#xff08;Set Difference Op…

python: 用百度API读取增值税发票信息

# encoding: utf-8 # 版权所有 2023 涂聚文有限公司 # 许可信息查看&#xff1a; # 描述&#xff1a; # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 311 # Datetime : 2023/9/30 6:56 # User : geovindu # Product : PyCharm # Proj…

机器学习笔记 - 基于强化学习的贪吃蛇玩游戏

一、关于深度强化学习 如果不了解深度强化学习的一般流程的可以考虑看一下下面的链接。因为这里的示例因为在PyTorch 之上实现深度强化学习算法。 机器学习笔记 - Deep Q-Learning算法概览深度Q学习是一种强化学习算法,它使用深度神经网络来逼近Q函数,用于确定在给定状态下采…

架构设计第七讲:数据巡检系统之daily线上表结构自动化比对

架构设计第七讲&#xff1a;数据巡检系统之daily&线上表结构自动化比对 本文是架构设计第七讲&#xff0c;数据巡检系统之daily&线上表结构自动化比对&#xff0c;避免正式环境与测试环境数据库/表、列结构不一致带来问题。 文章目录 架构设计第七讲&#xff1a;数据巡…

193419-86-2,用于蛋白电泳检测的Fluorescein o-acrylate

产品简介&#xff1a;Fluorescein o-acrylate 中FITC具有荧光素衍生物的普遍特性&#xff0c;FITC也经常被用于蛋白电泳检测和荧光能量激发转移测试。 荧光染料及其荧光标记技术一直是生物领域常用的产品和技术&#xff0c;荧光物质是指具有共轭双键体系化学结构的化合物&…

LabVIEW开发实时自动化多物镜云计算全玻片成像装置

LabVIEW开发实时自动化多物镜云计算全玻片成像装置 数字病理学领域正在迅速发展&#xff0c;这主要是由于计算机处理能力、数据传输速度、软件创新和云存储解决方案方面的技术进步。因此&#xff0c;病理科室不仅将数字成像用于图像存档等简单任务&#xff0c;还用于远程病理学…

monkeyrunner录制脚本和回放

Monkeyrunner关于使用录制、生成脚本、编译脚本及执行脚本。 首先在计算机上下载和安装SDK、python 2.将recorder.py文件放置SDK文件夹里tools文件夹下 3.USB连接手机&#xff0c;手机端&#xff0c;开启USB调试&#xff0c;并在计算机DOS中输入adb devices命令&#xff0c;查看…

K8S-CNI

CNI的设计思想即为:Kubernetes在启动Pod的pause容器之后&#xff0c;直接调用CNI网络插件&#xff0c;从而实现为Pod内部应用容器月在的Network Namespace配置符合预期的网络信息。 这里面需要特别关注两个方面:Container必须有自己的网络命名空间的环境&#xff0c;也就是end…

go mod tidy 报错:x509: certificate signed by unknown authority 最佳实践

最近在docker中运行了一个ubuntu20的系统&#xff0c;在上面运行golang程序&#xff0c;使用go mod tidy后报错&#xff1a; tls: failed to verify certificate: x509: certificate signed by unknown authority 如&#xff1a; go: finding module for package google.gol…

Java:使用 Graphics2D 类来绘制图像

目录 过程介绍创建一个 BufferedImage 对象创建一个 Graphics2D 对象绘制字符和干扰线将生成的图像保存到文件 示例代码 过程介绍 创建一个 BufferedImage 对象 首先创建一个 BufferedImage 对象来表示图像 创建一个 Graphics2D 对象 然后使用 createGraphics() 方法创建一…

XXE 漏洞及案例实战

文章目录 XXE 漏洞1. 基础概念1.1 XML基础概念1.2 XML与HTML的主要差异1.3 xml示例 2. 演示案例2.1 pikachu靶场XML2.1.1 文件读取2.1.2 内网探针或者攻击内网应用&#xff08;触发漏洞地址&#xff09;2.1.4 RCE2.1.5 引入外部实体DTD2.1.6 无回显读取文件 3. XXE 绕过3.1 dat…