shader-纹理处理-mipmap

什么是mipmap

三维计算图形的贴图渲染中常用的技术,为了加快渲染速度和减少图像锯齿,图像被处理成由一列被预先计算和优化过的图片组成的文件,但是同时会占用较多的空间,空间换时间。(unity中大概多占33%的内存)。每一个层级的小图都是主图按一定比列缩小细节的复制图。当图片被缩小或远离摄像机时,会切换早适合的mipmap层级。mipmap图片是经过缩小后的图片,读取的像素值远小于原图片,同时已经经过抗锯齿处理,所以可以提高渲染速度和减少实时渲染的计算。

多级渐远纹理技术原理:提前用滤波处理来得到很多更小的图像,形成一个图像金字塔,每一层都是对上一层降采样的结果。这样在实际运行时,就能快速得到结果像素。当物体原理摄像机时,可以直接使用较小的纹理(纹理质量稍差,模糊感较强),当物体靠近时适当替换较大纹理(纹理质量好,模糊感较少),以便给玩家呈现更精致的画面。
测试

使用前

       

 

使用后

        

https://my.oschina.net/sweetdark/blog/177812

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用 osgEarth 3.2 绘制云层的示例代码: ```cpp #include <osgEarth/Registry> #include <osgEarth/ImageUtils> #include <osgEarth/ShaderUtils> #include <osgEarth/Sky> #include <osgEarthUtil/Sky> #include <osgEarthUtil/Clouds> osg::Node* createCloudLayer() { // 创建一个 CloudLayer 对象 osgEarth::Util::CloudLayerOptions options; options.altitude() = 20000.0f; options.thickness() = 2000.0f; options.color() = osg::Vec3(1.0f, 1.0f, 1.0f); options.brightness() = 1.0f; options.speed() = 0.0001f; osg::ref_ptr<osgEarth::Util::CloudLayer> cloudLayer = new osgEarth::Util::CloudLayer(options); // 加载云层纹理 osg::ref_ptr<osg::Image> cloudImage = osgDB::readImageFile("path_to_cloud_texture"); osg::ref_ptr<osg::Texture2D> cloudTexture = new osg::Texture2D(cloudImage); cloudTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); cloudTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT); cloudTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR); cloudTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); cloudLayer->setTexture(cloudTexture); // 设置云层渲染 shader osg::ref_ptr<osg::Program> cloudShader = new osg::Program; cloudShader->addShader(osgEarth::ShaderUtils::loadShaderFile("path_to_cloud_shader.vert", osg::Shader::VERTEX)); cloudShader->addShader(osgEarth::ShaderUtils::loadShaderFile("path_to_cloud_shader.frag", osg::Shader::FRAGMENT)); osg::ref_ptr<osgEarth::StateSetCache> stateSetCache = osgEarth::Registry::instance()->getStateSetCache(); osg::StateSet* stateSet = stateSetCache->getOrCreateStateSet(cloudShader.get()); stateSet->addUniform(new osg::Uniform("oe_Sky_CloudsAltitude", options.altitude().get())); stateSet->addUniform(new osg::Uniform("oe_Sky_CloudsThickness", options.thickness().get())); stateSet->addUniform(new osg::Uniform("oe_Sky_CloudsColor", options.color().get())); stateSet->addUniform(new osg::Uniform("oe_Sky_CloudsBrightness", options.brightness().get())); stateSet->addUniform(new osg::Uniform("oe_Sky_CloudsSpeed", options.speed().get())); stateSet->addUniform(new osg::Uniform("oe_Sky_Time", 0.0f)); // 创建云层节点 osg::ref_ptr<osg::Group> cloudNode = new osg::Group; cloudNode->addChild(cloudLayer->getOrCreateStateSetGroup()); cloudNode->addChild(cloudLayer->getOrCreateGeometry()); return cloudNode.release(); } ``` 这段代码使用 `osgEarth::Util::CloudLayer` 类来创建一个云层节点,并设置云层纹理和渲染 shader。其中,`path_to_cloud_texture` 和 `path_to_cloud_shader.vert`/`path_to_cloud_shader.frag` 分别表示云层纹理和 shader 的路径。你可以根据实际情况进行修改。 最后,将云层节点添加到场景图中即可。例如: ```cpp osgViewer::Viewer viewer; viewer.setSceneData(createCloudLayer()); viewer.run(); ``` 这将创建一个带有云层的场景,并且使用时钟来不断更新 shader 中的 `oe_Sky_Time` 变量,以实现云层的运动效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值