十三,打印辐照度图

上节HDR环境贴图进行卷积后,得到的就是辐照度图,表示的是周围环境间接漫反射光的积分。

现在也进行下打印,和前面打印HDR环境贴图一样,只是由于辐照度图做了平均,失去了大量高频部分,因此,可以用较低分辨率32x32存储。

运行结果如下:
在这里插入图片描述
代码如下:
#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 <osgGA/TrackballManipulator>
#include <osgDB/WriteFile>

static const char * vertexShader =
{
“in vec3 aPos;\n”
“varying vec3 WorldPos;”
“void main(void)\n”
“{\n”
“WorldPos = aPos;\n”
" gl_Position = ftransform();\n"
“}\n”
};

static const char *psShader =
{
"varying vec3 WorldPos; "
"uniform samplerCube environmentMap; "
"const float PI = 3.14159265359; "
"void main() "
"{ "
" vec3 N = normalize(WorldPos); "
" vec3 irradiance = vec3(0.0); "
" vec3 up = vec3(0.0, 1.0, 0.0); "
" vec3 right = normalize(cross(up, N)); "
" up = normalize(cross(N, right)); "
" float sampleDelta = 0.025; "
" float nrSamples = 0.0; "
" for (float phi = 0.0; phi < 2.0 * PI; phi += sampleDelta) "
" { "
" for (float theta = 0.0; theta < 0.5 * PI; theta += sampleDelta) "
" { "
" vec3 tangentSample = vec3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta)); "
" vec3 sampleVec = tangentSample.x * right + tangentSample.y * up + tangentSample.z * N; "
" irradiance += texture(environmentMap, sampleVec).rgb * cos(theta) * sin(theta); "
" nrSamples++; "
" } "
" } "
" irradiance = PI * irradiance * (1.0 / float(nrSamples)); "
" gl_FragColor = vec4(irradiance, 1.0); "
“}”
};
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 = 32;
int textureHeight = 32;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()
{
osg::ref_ptrosg::TextureCubeMap tcm = new osg::TextureCubeMap;
tcm->setTextureSize(512, 512);
tcm->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
tcm->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
tcm->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
tcm->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
tcm->setWrap(osg::Texture::WRAP_R, osg::Texture::CLAMP_TO_EDGE);

std::string strImagePosX = "D:/delete/Right face camera.bmp";
osg::ref_ptr<osg::Image> imagePosX = osgDB::readImageFile(strImagePosX);
tcm->setImage(osg::TextureCubeMap::POSITIVE_X, imagePosX);
std::string strImageNegX = "D:/delete/Left face camera.bmp";
osg::ref_ptr<osg::Image> imageNegX = osgDB::readImageFile(strImageNegX);
tcm->setImage(osg::TextureCubeMap::NEGATIVE_X, imageNegX);std::string strImagePosY = "D:/delete/Front face camera.bmp";;
osg::ref_ptr<osg::Image> imagePosY = osgDB::readImageFile(strImagePosY);
tcm->setImage(osg::TextureCubeMap::POSITIVE_Y, imagePosY);
std::string strImageNegY = "D:/delete/Back face camera.bmp";;
osg::ref_ptr<osg::Image> imageNegY = osgDB::readImageFile(strImageNegY);
tcm->setImage(osg::TextureCubeMap::NEGATIVE_Y, imageNegY);std::string strImagePosZ = "D:/delete/Top face camera.bmp";
osg::ref_ptr<osg::Image> imagePosZ = osgDB::readImageFile(strImagePosZ);
tcm->setImage(osg::TextureCubeMap::POSITIVE_Z, imagePosZ);
std::string strImageNegZ = "D:/delete/Bottom face camera.bmp";
osg::ref_ptr<osg::Image> imageNegZ = osgDB::readImageFile(strImageNegZ);
tcm->setImage(osg::TextureCubeMap::NEGATIVE_Z, imageNegZ);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, tcm, 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("environmentMap", 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:/irradiance/" + theImage->getFileName() + ".bmp";osgDB::writeImageFile(*theImage, strPrintName);}}
}
return 0;

}

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

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

相关文章

2.(vue3.x+vite)组件注册并调用

前端技术社区总目录(订阅之前请先查看该博客) 关联博客 1.(vue3.x+vite)封装组件 一:umd调用方式 1:引入umd.js <script src="./public/myvue5.umd.js"></script>2:编写代码调用 (1)umd方式,根据“5

unity 限制 相机移动 区域(无需碰撞检测)

限制功能原著地址&#xff1a;unity限制相机可移动区域&#xff08;box collider&#xff09;_unity限制相机移动区域_manson-liao的博客-CSDN博客 一、创建限制区域 创建一个Cube&#xff0c;Scale大小1&#xff0c;添加组件&#xff1a;BoxCollder&#xff0c;调整BoxColld…

阿里云产品试用系列-云桌面电脑

无影云电脑&#xff08;WUYING Workspace&#xff09;&#xff0c;是一种易用、安全、高效的云上桌面服务。它支持快速便捷的桌面环境创建、部署、统一管控与运维。无需前期传统硬件投资&#xff0c;帮您快速构建安全、高性能、低成本的企业桌面办公体系。可广泛应用于具有高数…

网工内推 | 网络工程师,软考证书优先,六险一金,包吃

01 科力信息 招聘岗位&#xff1a;网络工程师 职责描述&#xff1a; 1、负责蚌埠项目的设备安装及调试&#xff1b; 2、对边界网络运行中的监控、故障排除、问题处理。 任职要求&#xff1a; 1、2年及以上网络相关工作经验&#xff0c;有交通管理网络运维经验优先&#xff1b…

Xilinx FPGA 程序固化重新上电程序不运行的问题

问题描述 FPGA直接下载bit文件,功能正常。 FPGA擦除FLASH,烧写FLASH,正常。 电源断电,重新上电,FALSH里面的程序没有启动,FPGA程序没有跑起来。–FLASH启动不正常。 解决办法 在XDC约束文件里边增加约束: ## Configuration options, can be used for all designs se…

js中的类型转换

原文地址 JavaScript 中有两种类型转换&#xff1a;隐式类型转换&#xff08;强制类型转换&#xff09;和显式类型转换。类型转换是将一个数据类型的值转换为另一个数据类型的值的过程。 隐式类型转换&#xff08;强制类型转换&#xff09;&#xff1a; 隐式类型转换是 Java…

unittest单元测试框架使用

什么是unittest 这里我们将要用的unittest是python的单元测试框架&#xff0c;它的官网是 25.3. unittest — Unit testing framework — Python 2.7.18 documentation&#xff0c;在这里我们可以得到全面的信息。 当我们写的用例越来越多时&#xff0c;我们就需要考虑用例编写…

Linux配置命令

一&#xff1a;HCSA-VM-Linux安装虚拟机后的基础命令 1.代码命令 1.查看本机IP地址&#xff1a; ip addr 或者 ip a [foxbogon ~]$ ip addre [foxbogon ~]$ ip a 1&#xff1a;<Loopback,U,LOWER-UP> 为环回2网卡 2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP&g…

Android滑动片段

本文所有的代码均存于 https://github.com/MADMAX110/BitsandPizzas 回到BitsandPizzas应用&#xff0c;之前已经创建过创建订单和发出反馈等功能。 修改披萨应用&#xff0c;让它使用标签页导航。在工具条下显示一组标签页&#xff0c;每个选项对应一个不同的标签页。用户单击…

实验室安全教育与考试

目录 我的错题&#xff08;2个&#xff09;新知识题目&#xff08;10个&#xff09;刚开始不太理解的题目&#xff08;10个&#xff09;写在最后&#xff08;免责声明&#xff09; 我的错题&#xff08;2个&#xff09; 18.发生电气火灾时可以使用的灭火设备包括&#xff1a;&…

秋招在线人才测评考什么内容?

又是一年招聘季&#xff0c;各大高校都会组织校园招聘&#xff0c;这次我们就来了解一下秋季校园招聘究竟考什么。近些年来校园秋招已经广泛采用在线测评&#xff0c;尤其各行业龙头大厂们&#xff0c;网申、在线测评、小组无领导讨论&#xff0c;一面二面......各类纷杂的面试…

RobotFrameWork自动化测试框架如何搭建环境?

前言 Robot Framework是一款python编写的功能自动化测试框架。具备良好的可扩展性&#xff0c;支持关键字驱动&#xff0c;可以同时测试多种类型的客户端或者接口&#xff0c;可以进行分布式测试执行。主要用于轮次很多的验收测试和验收测试驱动开发&#xff08;ATDD&#xff0…

服务好的CMDB运维管理平台的服务优势

随着公司信息化程度的不断提高&#xff0c;IT基础设施也越来越复杂。为了方便这些基础设施的管理和维护&#xff0c;CMDB&#xff08;配置管理数据库&#xff09;运维管理平台应运而生。本文将介绍一个服务好、价格实惠的CMDB运维管理平台&#xff0c;帮助读者更好地了解和使用…

手机能搜到某个wifi,电脑搜不到解决方法(也许有用)

方法一&#xff1a;更新驱动 下载驱动大师、驱动精灵等等驱动软件&#xff0c;更新网卡驱动 方法二 按 win 键&#xff0c;打开菜单 搜索 查看网络连接&#xff08;win11版本是搜这个名字&#xff09; 点击打开是这样式的 然后对 WLAN右击->属性->配置->高级 这…

Java比较器之equals、comparable、comparator

文章目录 前言一、基本类型比较1.2.equals3.和equals的区别 二、对象的比较1.覆写基类的equals2.基于Comparable接口类的比较3.基于Comparator比较器比较4.三种方式对比 前言 在Java中&#xff0c;基本类型的对象可以直接比较&#xff0c;而自定义类型&#xff0c;默认是用equ…

如何正确监测蓄电池健康?狠狠学到!

蓄电池在现代生活和工业中发挥着关键作用&#xff0c;它们为无数设备和系统提供了必要的电力支持。然而&#xff0c;蓄电池的性能和可靠性对许多应用至关重要。监控蓄电池状态和性能变得越来越重要&#xff0c;以确保它们在需要时始终可用。 为此&#xff0c;蓄电池监控系统应运…

将切分的图片筛选出有缺陷的

将切分的图片筛选出有缺陷的 需求代码 需求 由于之前切分的图像有一些存在没有缺陷&#xff0c;需要再次筛选 将可视化的图像更改后缀 更改为xml的 可视化代码 可视化后只有7000多个图像 原本的图像有1W多张 代码 # 按照xml文件删除对应的图片 # coding: utf-8 from P…

【Linux】【网络】传输层协议:UDP

文章目录 UDP 协议1. 面向数据报2. UDP 协议端格式3. UDP 的封装和解包4. UDP 的缓冲区 UDP 协议 UDP传输的过程类似于寄信。 无连接&#xff1a;知道对端的IP和端口号就直接进行传输&#xff0c;不需要建立连接。不可靠&#xff1a;没有确认机制&#xff0c;没有重传机制&am…

一分钟用手机搞定视频提取伴奏

上台表演需要去掉人声&#xff0c;提取伴奏&#xff0c;这个操作可以直接使用【音分轨】软件中的【视频提取伴奏】功能&#xff0c;接下来教大家具体的操作流程&#xff01; 第一步&#xff1a;在首页点击【人声分离】&#xff0c;上传需要分离的视频&#xff0c;有三种方式可以…