第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果

这篇具有很好参考价值的文章主要介绍了第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

本节主要学习如何使用Ogre2.3加载粒子效果。为了学习方便,直接将官方粒子模块Sample_ParticleFX单独拿出来编译,学习如何实现粒子效果。

一. 前提须知

  1. 如果参考官方示例建议用最新版的Ogre 2.3.1。否则找不到有粒子效果的示例。不要用官网Ogre2.3 script脚本编译源码!
  2. Ogre 1.x中关于实现粒子效果的官方示例材质太老,不支持固管,要写shader,不建议在Ogre 2.3中使用。要使用新的材质!
    Ogre 1.x中的材质:
material Examples/Flare
{
	technique
	{
		pass
		{
			lighting off
			scene_blend add
			depth_write off
			diffuse vertexcolour

			texture_unit
			{
				texture flare.png
			}
		}
	}
}

Ogre 2.3中的材质:

hlms Examples/Flare2 unlit
{
	depth_write		off
	cull_hardware	none

	scene_blend		add

	diffuse_map flaretrail.png
}

二. 新建项目工程的头文件和库文件配置如下:

注意:你需要把Media文件夹bin/Debug文件夹下的资源拷贝过来,具体拷贝到哪里大家应该很了解。
这里说下头文件和库文件的设置。
头文件:
第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果库目录:
第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果注意:这里改成窗口
第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果

三. 粒子效果总结

先展示下官网给的12个粒子效果,具体代码放到最后。

  1. 烟花效果,粒子Examples/Fireworks,材质官方没有给出,自己尝试模仿写了一个,添加到Particles.material文件中。
 Particles.material:
hlms Examples/Flare unlit
{
	depth_write		off
	cull_hardware	none

	scene_blend		add

	diffuse_map flare.png
}

第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果
2. 向上漂浮的绿色颗粒,粒子Examples/GreenyNimbus。材质自己为自己添加。

Particles.material:
hlms Examples/FlarePointSprite unlit
{
	depth_write		off
	cull_hardware	none

	scene_blend		add

	diffuse_map flare.png
}

第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果
3. 闪闪发光的紫色喷泉。粒子Examples/PurpleFountain。材质为官方自带。
第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果
4. 雨,粒子Examples/Rain。材质自己实现。

材质Particles.material:
hlms Examples/Droplet unlit
{
	depth_write		off
	cull_hardware	none

	scene_blend		add

	diffuse_map basic_droplet.png
}

第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果
5. 飞机喷气尾焰,粒子Examples/JetEngine1。粒子和材质代码详见官方示例。
第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果
6. 飞机喷气尾焰2,粒子Examples/JetEngine2。粒子和材质代码详见官方示例。
第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果
7. 向上漂浮的光环,类似龙卷风。粒子 Examples/Aureola。粒子和材质代码详见官方示例。
第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果
8. 四处游动的类似火花。粒子Examples/Swarm。粒子和材质代码详见官方示例。
第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果
9.漫天雪花,粒子Examples/Snow。粒子和材质代码详见官方示例。
第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果
10. 类似烟花。粒子Examples/Animated/Test1。粒子和材质代码详见官方示例。
第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果
11. 大雨滴,粒子Examples/Water/Rain。粒子和材质代码详见官方示例。
第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果
12. 烟雾。粒子Examples/Smoke。粒子代码见官方示例。材质代码自己写。如下:

材质Particles.material:
hlms Examples/Smoke unlit
{
	depth_write		off
	cull_hardware	none

	scene_blend		add

	diffuse_map Smoke15Frames.png
}

第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果

四. 代码

具体代码参考官方模块Sample_ParticleFX,这里为了单独测试不同粒子效果,把少数代码注释了。
ParticleFXGameState.cpp文章来源地址https://www.toymoban.com/news/detail-492590.html


#include "ParticleFXGameState.h"

#include "CameraController.h"
#include "GraphicsSystem.h"
#include "OgreCamera.h"
#include "OgreHlmsManager.h"
#include "OgreHlmsPbs.h"
#include "OgreHlmsPbsDatablock.h"
#include "OgreHlmsSamplerblock.h"
#include "OgreItem.h"
#include "OgreMesh2.h"
#include "OgreMeshManager.h"
#include "OgreMeshManager2.h"
#include "OgreRoot.h"
#include "OgreSceneManager.h"
#include "OgreTextureFilters.h"
#include "OgreTextureGpuManager.h"
#include "OgreWindow.h"

#include "OgreParticleSystem.h"
//
#include <iostream>

using namespace Demo;

namespace Demo
{
    ParticleFXGameState::ParticleFXGameState(const Ogre::String& helpDescription) :
        TutorialGameState(helpDescription),
        mTime(0.0f)
    {
    }
    //-----------------------------------------------------------------------------------
    void ParticleFXGameState::createScene01()
    {
        Ogre::SceneManager* sceneManager = mGraphicsSystem->getSceneManager();

        Ogre::v1::MeshPtr planeMeshV1 = Ogre::v1::MeshManager::getSingleton().createPlane(
            "Plane v1", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
            Ogre::Plane(Ogre::Vector3::UNIT_Y, 1.0f), 50.0f, 50.0f, 1, 1, true, 1, 4.0f, 4.0f,
            Ogre::Vector3::UNIT_Z, Ogre::v1::HardwareBuffer::HBU_STATIC,
            Ogre::v1::HardwareBuffer::HBU_STATIC);

        Ogre::MeshPtr planeMesh = Ogre::MeshManager::getSingleton().createByImportingV1(
            "Plane", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, planeMeshV1.get(), true,
            true, true);

        {
            Ogre::Item* item = sceneManager->createItem(planeMesh, Ogre::SCENE_DYNAMIC);
            item->setDatablock("Marble");
            Ogre::SceneNode* sceneNode = sceneManager->getRootSceneNode(Ogre::SCENE_DYNAMIC)
                ->createChildSceneNode(Ogre::SCENE_DYNAMIC);
            sceneNode->setPosition(0, -1, 0);
            sceneNode->attachObject(item);

            // Change the addressing mode of the roughness map to wrap via code.
            // Detail maps default to wrap, but the rest to clamp.
            assert(dynamic_cast<Ogre::HlmsPbsDatablock*>(item->getSubItem(0)->getDatablock()));
            Ogre::HlmsPbsDatablock* datablock =
                static_cast<Ogre::HlmsPbsDatablock*>(item->getSubItem(0)->getDatablock());
            // Make a hard copy of the sampler block
            Ogre::HlmsSamplerblock samplerblock(*datablock->getSamplerblock(Ogre::PBSM_ROUGHNESS));
            samplerblock.mU = Ogre::TAM_WRAP;
            samplerblock.mV = Ogre::TAM_WRAP;
            samplerblock.mW = Ogre::TAM_WRAP;
            // Set the new samplerblock. The Hlms system will
            // automatically create the API block if necessary
            datablock->setSamplerblock(Ogre::PBSM_ROUGHNESS, samplerblock);
        }

        Ogre::SceneNode* rootNode = sceneManager->getRootSceneNode();

        Ogre::Light* light = sceneManager->createLight();
        Ogre::SceneNode* lightNode = rootNode->createChildSceneNode();
        lightNode->attachObject(light);
        light->setPowerScale(Ogre::Math::PI);
        light->setType(Ogre::Light::LT_DIRECTIONAL);
        light->setDirection(Ogre::Vector3(-1, -1, -1).normalisedCopy());

        sceneManager->setAmbientLight(Ogre::ColourValue(0.3f, 0.5f, 0.7f) * 0.1f * 0.75f,
            Ogre::ColourValue(0.6f, 0.45f, 0.3f) * 0.065f * 0.75f,
            -light->getDirection() + Ogre::Vector3::UNIT_Y * 0.2f);

      /*  Ogre::ParticleSystem* pSystem0 = sceneManager->createParticleSystem("Examples/PurpleFountain");
        Ogre::ParticleSystem* pSystem1 = sceneManager->createParticleSystem("Examples/Aureola");
        Ogre::ParticleSystem* pSystem2 = sceneManager->createParticleSystem("Examples/Animated/Test1");

        Ogre::SceneNode* sceneNode = rootNode->createChildSceneNode();
        sceneNode->attachObject(pSystem0);
        sceneNode = rootNode->createChildSceneNode();
        sceneNode->attachObject(pSystem1);
        sceneNode = rootNode->createChildSceneNode();
        sceneNode->setPosition(Ogre::Vector3(10, 0, 0));
        sceneNode->attachObject(pSystem2);*/

        Ogre::ParticleSystem* pSystem0 = sceneManager->createParticleSystem("Examples/Smoke");
        Ogre::SceneNode* sceneNode = rootNode->createChildSceneNode();
        sceneNode->attachObject(pSystem0);

        //参数获取
        unsigned short numAffectors = pSystem0->getNumAffectors();
        Ogre::ParticleAffector* particleAffector = pSystem0->getAffector(0);
       /* for (int i = 0; i < list.size(); i++) {
            Ogre::ParameterDef parameterDef = list[i];
            std::cout << parameterDef.description() << std::endl;

        }*/
        /*size_t s  = pSystem0->getParticleQuota();
        Ogre::ParticleAffector * particleAffector = pSystem0->getAffector(0);
        bool cull = pSystem0->getCullIndividually();
        bool castShadows = pSystem0->getCastShadows();
        Ogre::Real height = pSystem0->getDefaultHeight();
        pSystem0->getDefaultLightMask();
        Ogre::Real nonVisibleUpdateTimeout = pSystem0->getDefaultNonVisibleUpdateTimeout();
        pSystem0->getDefaultVisibilityFlags();*/
       /* Ogre::Item* particleSystem3_item = sceneManager->createItem(planeMesh, Ogre::SCENE_DYNAMIC);
        particleSystem3_item->setDatablock("Marble");
        mParticleSystem3_RootSceneNode = rootNode->createChildSceneNode();
        sceneNode = mParticleSystem3_RootSceneNode->createChildSceneNode();
        sceneNode->setScale(Ogre::Vector3(0.2f));
        sceneNode->attachObject(particleSystem3_item);

        Ogre::ParticleSystem* pSystem3 = sceneManager->createParticleSystem("Examples/Animated/Test1");
        mParticleSystem3_RootSceneNode->attachObject(pSystem3);
        mParticleSystem3_EmmitterSceneNode = mParticleSystem3_RootSceneNode->createChildSceneNode();
        pSystem3->setParticleEmitterRootNode(mParticleSystem3_EmmitterSceneNode);
        Ogre::Item* particleSystem3_emmiter_item =
            sceneManager->createItem(planeMesh, Ogre::SCENE_DYNAMIC);
        particleSystem3_emmiter_item->setDatablock("Marble");
        mParticleSystem3_EmmitterSceneNode->setScale(Ogre::Vector3(0.01f));
        mParticleSystem3_EmmitterSceneNode->attachObject(particleSystem3_emmiter_item);*/

        mGraphicsSystem->getCamera()->setPosition(Ogre::Vector3(0.0f, 40.0f, 120.0f));

        mCameraController = new CameraController(mGraphicsSystem, false);

        TutorialGameState::createScene01();
    }

    void ParticleFXGameState::update(float timeSinceLast)
    {
        mTime += timeSinceLast;

        if (mTime > 10.0f)
            mTime = 0.0f;

       /* mParticleSystem3_RootSceneNode->setPosition(
            Ogre::Vector3(-50.0f * mTime / 10.0f + 25.0f, 2, -50));
        mParticleSystem3_EmmitterSceneNode->setPosition(
            Ogre::Vector3(20.0f * mTime / 10.0f - 10.f, 0.5, 20.0f * mTime / 10.0f - 10));*/

        TutorialGameState::update(timeSinceLast);
    }
}  // namespace Demo

到了这里,关于第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【数据结构初阶】第五节.栈的详讲

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言 一、栈的基本认识 二、栈模拟实现:  三、栈的实战演练 3.1 有效的括号 3.2 逆波兰表达式 3.3 栈的压入、弹出序列 总结 上一节内容我们学习了链表的有关内容,今天我们将进行栈的学习

    2023年04月23日
    浏览(38)
  • 【Git 入门教程】第五节、Git远程仓库

    Git是一种分布式版本控制系统,它允许开发者在不同计算机之间协作并共享代码。在本文中,我们将介绍如何以Git为基础进行远程协作。其中包括克隆仓库、推送代码、拉取代码等操作。 要协作开发一个Git项目,需要从服务器上获取该项目的副本。 运行以下命令来克隆Git仓

    2024年02月01日
    浏览(42)
  • Python利用pygame实现飞机大战游戏

    文章目录: 一:运行效果 1.演示 2.思路和功能 二:代码 文件架构 Demo 必备知识:python图形化编程pygame游戏模块 效果图 ◕‿◕✌✌✌ Python利用pygame实现飞机大战游戏运行演示 参考:【Python游戏】1小时开发飞机大战游戏-Pygame版本(1小时40分钟) 博主提取资源: 提取

    2024年04月09日
    浏览(50)
  • 【测试开发】第五节.测试——自动化测试(Selenium工具)

    作者简介:大家好,我是未央; 博客首页:未央.303 系列专栏:Java测试开发 每日一句: 人的一生,可以有所作为的时机只有一次,那就是现在!!! 前言 一、自动化测试的概念以及分类 二、Selenium—web自动化测试工具 2.1 自动化测试的一些前置工作 2.2 第一个自动化实例

    2024年02月04日
    浏览(51)
  • 第五节 zookeeper集群与分布式锁_2

    1)要介绍分布式锁,首先要提到与分布式锁相对应的是线程锁。 线程锁 :主要用来给方法、代码块加锁。当某个方法或代码使用锁,在同一时刻仅有一个线程执行该方法或该代码段。 线程锁只在同一JVM中有效果,因为线程锁的实现在根本上是依靠线程之间共享内存实现的,

    2024年02月19日
    浏览(33)
  • Vue2项目练手——通用后台管理项目第五节

    面包屑 使用组件 使用vuex存储面包屑数据 src/store/tab.js src/components/CommonAside.vue src/components/CommonHeader.vue tag 使用组件 文件目录 CommonTag.vue Main.vue 全部代码: tabs.js 全部代码: 使用的组件 对话框 表单 页面布局与校验 Users.vue

    2024年02月10日
    浏览(29)
  • 【Python零基础学习入门篇⑤】——第五节:Python中的函数

    ⬇️⬇️⬇️⬇️⬇️⬇️ ⭐⭐⭐Hello,大家好呀我是陈童学哦,一个普通大一在校生,请大家多多关照呀嘿嘿😁😊😘 🌟🌟🌟 技术这条路固然很艰辛,但既已选择,该当坚毅地走下去,加油! 🌤️PUA: ” 你所看到的惊艳都曾平庸历练 **“**🚀🚀🚀 🍉🍉🍉 最后让我

    2024年02月04日
    浏览(35)
  • 第三章:R语言编程 第五节:值传递&对象不变性

    在R语言中,一切皆为对象,同时在调用函数的时候也采用值传递的方式,即作为参数的对象会被复制,然后将副本传递给函数 例如: 这里将数据框作为参数传递给函数的时候,函数内部的修改将不会影响原对象。这是因为调用f()函数时采用的时值传递的方法;df2中保持的不

    2024年03月11日
    浏览(37)
  • 书生·浦语大模型实战营第五节课笔记及作业

    1.1 模型部署及大模型特点 1.2 大模型部署挑战及方案 2.1 核心功能-量化 2.2 核心功能-推理引擎TurboMind 2.1 核心功能-推理服务api server 按照文档LMDeploy 的量化和部署中的步骤在InternStudio中的 A100(1/4) 机器上一步步操作即可! 3.1 基础作业 使用 LMDeploy 以本地对话、网页Gradio、API服

    2024年01月19日
    浏览(30)
  • AI实战营第二期 第五节 《目标检测与MMDetection》——笔记6

    MMDetection 是一个基于 PyTorch 的目标检测开源工具箱。它是 OpenMMLab 项目的一部分。是目前应用最广的算法库 主分支代码目前支持 PyTorch 1.6 以上的版本。代码链接:https://gitee.com/open-mmlab/mmdetection。 模块化设计。MMDetection 将检测框架解耦成不同的模块组件,通过组合不同的模块

    2024年02月08日
    浏览(25)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包