投影贴花

投影纹理映射(Projective Texture Mapping)详解 投影纹理映射(Projective Texture Mapping)目的是映射一张纹理到物体上,就像将幻灯片投影到墙上一样。该方法不需要在应用程序中指定顶点纹理坐标,实际上,投影纹理映射中使用的纹理坐标是在顶点着色程序中通过视点矩阵和投影矩阵计算得到的,通常也被称作投影纹理坐标(coordinates in projective space)。而我们常用的纹理坐标是在建模软件中通过手工调整纹理和3 阅读详情

Draws a decal on your terrain that can be arbitrarily positioned. Suitable for following the mouse and indicating brush size for editing.

How to Use:


Create the following files and include them in your project
Create transparent (no content, just blank/transparent) 2px by 2px png and name it decalBase.png - If you want to name it something else, edit the string literal in DecalCursor::init
Create an instance of DecalCursor in your project.
Call DecalCursor::show() to make it appear and hide to hide it.
Call DecalCurstor::setPosition(Vector3) to move the decal around (for example, in your mouseMoved handler.)
======================================================================

 

#ifndef SANGUIS_DECALCURSOR_H
#define SANGUIS_DECALCURSOR_H

#include "OgreMaterial.h"
#include "OgreVector3.h"
#include "OgreVector2.h"

// forward declaration
namespace Ogre
{
   class SceneManager;
   class SceneNode;
   class Frustum;
   class TextureUnitState;
   class Pass;
}


class DecalCursor
{
   public:
      DecalCursor(Ogre::SceneManager* man,
               Ogre::MaterialPtr terrainMat,
               const Ogre::Vector2& size,
               const std::string& tex);
      ~DecalCursor();

      inline bool isVisible() const {   return m_bVisible;   }

      Ogre::Vector3 getPosition() const;

      void show();
      void hide();

      void setPosition(const Ogre::Vector3& pos);
      void setSize(const Ogre::Vector2& size);

   private:
      void init(const Ogre::Vector2& size, const std::string& tex);
      void showTerrainDecal();
      void hideTerrainDecal();

      Ogre::Vector2 m_size;            /**< @brief size of decal */
     Ogre::Vector3 m_pos;

      std::string m_sTexName;            /**< @brief texture to apply */

      Ogre::SceneNode* m_nodeProj;         /**< @brief the projection node */
      Ogre::Frustum* m_frustProj;         /**< @brief the projection frustum */
      Ogre::TextureUnitState* m_texState;   /**< @brief pointer to the texture unit state in the pass */
      Ogre::Pass* m_pass;               /**< @brief pointer to the decal pass */
      Ogre::MaterialPtr m_terrainMat;      /**< @brief sharedptr to the terrain material */

      Ogre::SceneManager* m_sceneMgr;      /**< @brief Pointer to the application's Ogre::SceneManager */

      bool m_bVisible;                  /**< @brief true if the decal visible, otherwise false */
};

#endif

==========================================================================

 

#include "OgreSceneManager.h"
#include "OgreTextureManager.h"
#include "OgreSceneNode.h"
#include "OgreFrustum.h"
#include "OgreTextureUnitState.h"
#include "OgrePass.h"

#include "DecalCursor.h"


static const float METER_SCALE = 1.0f;

DecalCursor::DecalCursor(Ogre::SceneManager* man, Ogre::MaterialPtr terrainMat, const Ogre::Vector2& size,
                   const std::string& tex)

: m_bVisible ( false ), m_nodeProj(0), m_pass(0), m_frustProj(0), m_texState(0), m_sceneMgr(man),
m_terrainMat( terrainMat ), m_pos ( Ogre::Vector3::ZERO ), m_size ( Ogre::Vector2::ZERO )
{
   init(size, tex);
}

DecalCursor::~DecalCursor()
{
   hide();

   // remove the decal pass
   if ( m_pass )
   {
      m_terrainMat->getTechnique(0)->removePass( m_pass->getIndex() );
      m_pass = 0;
   }

      // delete frustum
   m_nodeProj->detachAllObjects();
   delete m_frustProj;

      // destroy node
   m_nodeProj->getParentSceneNode()->removeAndDestroyChild(m_nodeProj->getName());
}

void DecalCursor::init(const Ogre::Vector2& size, const std::string& tex )
{
      // create a new pass in the material to render the decal
   m_pass = m_terrainMat->getTechnique(0)->getPass("Decal");
   if (!m_pass)
   {
      Ogre::Technique* techPref = m_terrainMat->getTechnique(0);
      m_pass = techPref->createPass();
      m_pass->setName("Decal");
      m_pass->setLightingEnabled(false);
      m_pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
      m_pass->setDepthBias(2.5, 2.5);
      m_pass->setFog(true);
      m_pass->createTextureUnitState("decalBase.png");
   }

      // init projective decal
      // set up the main decal projection frustum
   m_frustProj = new Ogre::Frustum();
   m_nodeProj = m_sceneMgr->getRootSceneNode()->createChildSceneNode();
   m_nodeProj->attachObject(m_frustProj);
   m_frustProj->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
   m_nodeProj->setOrientation(Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3::UNIT_X));
   
      /* Commented out for general use. If you are using mouse picking in your scene, set this to an unselectable flag otherwise you may find the frustum in your ray queries. */
   //m_frustProj->setQueryFlags(Sanguis::UNSELECTABLE);

      // set given values
   setSize(size);
   m_sTexName = tex;      // texture to apply

      // load the images for the decal and the filter
   Ogre::TextureManager::getSingleton().load(m_sTexName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 1);

   m_bVisible = false;
}

Ogre::Vector3 DecalCursor::getPosition() const
{
   return m_pos;
}

void DecalCursor::show()
{
   if(!m_bVisible)
   {
      m_bVisible = true;
      showTerrainDecal();
      setPosition(m_pos);
   }
}

void DecalCursor::hide()
{
   if (m_bVisible)
   {
      m_bVisible = false;
      hideTerrainDecal();
   }
}

void DecalCursor::setPosition(const Ogre::Vector3& pos)
{
   m_pos = pos;

   // Set the projection coming from some distance above the current position.
   m_nodeProj->setPosition(pos.x, pos.y + (10.0 * METER_SCALE), pos.z);
}

void DecalCursor::setSize(const Ogre::Vector2& size)
{
   if (m_size != size)
   {
      m_size = size;

         // update aspect ratio
    #if OGRE_VERSION_MAJOR == 1 && OGRE_VERSION_MINOR <= 4
      m_frustProj->setAspectRatio(m_size.x / m_size.y);
   #else
      m_frustProj->setOrthoWindow ( m_size.x, m_size.y );
   #endif

         // set fovy so that tan = 1, so 45 degrees
      m_frustProj->setFOVy(Ogre::Degree(45));

         // set near clip plane according to fovy:
      m_frustProj->setNearClipDistance(m_size.y);
   }
}

// Protected

void DecalCursor::showTerrainDecal()
{
   if (!m_texState)
   {
         // set up the decal's texture unit
      m_texState = m_pass->createTextureUnitState(m_sTexName);
      m_texState->setProjectiveTexturing(true, m_frustProj);
      m_texState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
      m_texState->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_LINEAR, Ogre::FO_NONE);
      m_texState->setAlphaOperation(Ogre::LBX_ADD);
   }
}

void DecalCursor::hideTerrainDecal()
{
   if (m_texState)
   {
      m_pass->removeTextureUnitState(m_pass->getTextureUnitStateIndex(m_texState));
      m_texState = 0;
   }
}
 

使用投影纹理进行模型贴花(Mesh Decals) Decals Using Projective Texture Mapping 讲投影纹理的好文章网上是很多的,在此给大家一个参考链接,我就不再呈述了。 此文章的描述很易懂。 投影纹理映射(Projective Texture Mapping) http://wwwnno00.irrlicht3d.cn:8011/redirect.php?tid=54109&goto=lastpost   阅读详情

相关推荐

简易投影贴花制作

unity3d插件,用于 地表贴花,模型贴花,投影 效果不错..

投影纹理映射(Projective Texture Mapping)

摘抄“GPU Programming And Cg Language Primer 1rd Edition” 中文名“GPU编程与CG语言之阳春白雪下里巴人”    投影纹理映射(Projective Texture Mapping)最初由Segal在文章“Fast shadows and lighting effects using texture

liu_lin_xm的专栏 1万+

projective_texture_mapping

投影矩阵的教程 Introduction Projective texture mapping is a method of texture mapping described by Segal [3] that allows the texture image to be projected onto the scene as if by a slide projector. Figure 1 shows some example screen shots from the projspot demo, available in the NVIDIA OpenGL SDK. Projective texture mapping is useful in a variety of lighting techniques, including shadow mapping [4]. This document provides some background and describes the steps involved in projective texture mapping in OpenGL. Projective texture mapping refers both to the way texture coordinates are assigned to vertices, and the way they are computed during rasterization of primitives. We usually think of texture mapping as “the application of a texture image to a primitive,” and while it certainly is that – there is more math going on than most folks think. If you have ever written your own rasterizer with support for mipmap filtered, perspective-correct, projective texture mapping, you no doubt became aware of the many subtle issues involved. We will begin by discussing the way that texture coordinates are computed during rasterization, and then we will discuss methods for assigning the texture coordinates to the vertices. We do not discuss filtering here, but there is a paper on Anisotropic Filtering at the NVIDIA developer web site that provides a good introduction to that topic. Figure 1.

OpenGL 4.0 GLSL 实现 投影纹理映射(Projective Texture Mapping)

投影纹理映射 (projective texture mapping):就是把纹理投射到场景的物体上,就像一个投影机把幻灯片投影到其他物体上一样。 如下图:用左边的纹理图像投影到一个茶壶上 投影纹理的实现方法: 其实最重要的一点就是确定纹理坐标,纹理坐标的确定依赖于物体表面点的相对位置和投影机的位置。在OpenGL中我们可以定义一个camera,我们定义一个中心在投影机位置的

UnrealEngine4 、Delta3D、OSG 1万+

Unity3D——贴花.part1

一共有两份,这是第一份。 Unity3D——贴花.part1 Unity3D——贴花.part1

OpenGL中decal贴图代码

decal贴图可以模拟射击、爆炸痕迹效果,本程序利用decal技术实现了贴图

openGL Projective texture mapping

原文链接:https://sites.google.com/site/gsucomputergraphics/educational/advanced-texture-mapping/projective-texture-mapping Example   此示例演示了投影纹理贴图,这是阴影贴图,光照贴图和纹理贴图的基础。 在常规纹理贴图中,每个顶点的纹理坐标都是静态的,通常是在建模软件(例如Maya,3DS Max或Blender)中计算的。在投影纹理贴图中,每个顶点的纹理坐标不是静

whl0071的专栏 554

GLSL之多重纹理演示

GLSL之多重纹理演示 http://www.cnblogs.com/zengqh/

【unity组件介绍】URP Decal Projector贴花投影器,将特定材质(贴花)投影到场景中的其他对象上。

Unity URP贴花投影器使用指南 Unity URP贴花投影器(Decal Projector)是Unity 2021版本引入的功能,用于在不修改原始网格的情况下向场景投射贴花效果。本文介绍了贴花投影器的创建步骤、参数配置和使用技巧。 核心功能: 非破坏性添加表面细节(血迹、弹孔等) 支持材质混合和法线强度调节 可通过渲染层控制投射对象 使用流程: 创建URP贴花投影器 添加贴花渲染器功能 创建Decal材质并配置贴图 调整投影参数(大小、深度、渲染层等) 优化建议: 合理设置投影深度和大小 使用GPU

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 2996

蓝桥杯STM32G431RBT6学习——GPIO

蓝桥杯STM32G431RBT6学习——GPIO

weixin_44098974的博客 2234

交换机救命命令手册:华为 & 思科平台最全运维指令速查表

很多时候,真正拉你一把的不是“高深理论”,而是你手里有没有一份靠得住的命令速查表。这篇文章,希望能成为你“进可调试,退可排障”的一份救命卡片。

HuaweiLab_Peach的博客 1515

【unity实战】使用URP Decal Projector贴花投影器实现高级的弹孔效果

本文介绍了使用URP Decal Projector实现高级弹孔效果的方法。首先准备弹孔素材,可在线生成法线贴图增强效果。然后创建URP贴花投影器,添加贴花渲染器功能,并配置弹孔材质。通过脚本在鼠标点击位置生成弹孔预制体,使其朝向碰撞面法线方向并随机旋转增加真实感,最后设置自动销毁。文末还推荐了Unity相关的学习专栏,包含游戏开发、特效制作、优化等多方面内容。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 1750

DeepLearningTool-深度学习分类-和HALCON的详细过程

损失函数:衡量预测误差,用于模型优化。混淆矩阵:评估分类模型性能,提供详细预测结果分析。两者结合使用,可以全面评估和优化模型。过拟合:模型过于复杂,捕捉了噪声,表现为训练集误差低,测试集误差高。欠拟合:模型过于简单,无法捕捉数据模式,表现为训练集和测试集误差都高。调整参数过拟合:简化模型、增加数据、使用正则化、早停、Dropout。欠拟合:增加模型复杂度、特征工程、增加训练时间、调整学习率、使用集成方法。通过合理调整参数和方法,可以有效避免过拟合和欠拟合,提升模型性能。

weixin_36672036的博客 6184

告别“贴纸感”:Painter“投影+锚点”的工业级Decal(贴花)工作流

我将深入介绍一套基于 Adobe Substance 3D Painter 的、工业级的“Decal(贴花)”解决方案。通过本指南,你将学会如何利用Painter强大的“投影(Projection)”工具,将你在 Photoshop(或用Firefly AI)中制作的贴花素材,“无损”地、“精准”地,“投射”到模型的任意复杂表面上,并联动“锚点(Anchor Points)”,实现贴花与底层材质(如墙皮剥落、锈迹)的“智能”融合,彻底告别“贴纸感”。

海外设计界工作十余年的设计师 1602

数字IC后端新手必看:Innovus从安装到跑通第一个设计的完整流程(附常用命令清单)

本文为数字IC后端设计新手提供了Cadence Innovus工具的完整实战指南。详细介绍了从环境搭建、软件安装与许可证配置,到加载网表、库文件和约束,并逐步完成布局规划、单元布局、时钟树综合、布线及物理验证的核心使用流程。文章最后附有常用Tcl命令清单,帮助初学者快速上手并跑通第一个设计。

vscode5coder的博客 1238

matlab特征提取和分类_SAST Weekly|MATLAB机器学习初探——做个心音分类器

SAST weekly 是由电子工程系学生科协推出的科技系列推送,内容涵盖信息领域技术科普、研究前沿热点介绍、科技新闻跟进探索等多个方面,帮助同学们增长姿势,开拓眼界,每周更新,欢迎关注!欢迎愿意分享知识的同学投稿至 eesast@mail.tsinghua.edu.cn , 期待你的作品!本期的SAST weekly,想跟大家分享一下如何用MATLAB进行初步的机器学习,构建一个正常/...

weixin_36453829的博客 5579

Ogre视投影纹理贴花

投影纹理映射(Projective Texture Mapping) 投影纹理映射( Projective Texture Mapping )最初由 Segal 在文章 “Fast shadows and lighting effects using texture maaping” 中提出,用于映射一个纹理到物体上,就像将幻灯片投影到墙上一样。该方法不需要在应用程序中指定顶点纹...

dgvfx80822的专栏 227

Visual Studio Installer下载失败的5种修复方法(含DNS修改/补丁安装)

本文针对Visual Studio Installer下载安装文件失败的问题,提供了从网络层到系统层的深度排查与修复指南。详细介绍了DNS修改、代理配置、防火墙设置、系统服务检查等5种核心修复方法,并包含离线安装与手动补丁等替代方案,帮助开发者彻底解决安装难题。

sprite的博客 1617
上一篇: 模型贴花
下一篇: md5
Redefine
博客等级 码龄19年 4粉丝 13原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值