[2.1] Create and use particle effect in Ogre 2.1 Topic is solved

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
123iamking
Gremlin
Posts: 152
Joined: Sat Aug 12, 2017 4:16 pm
x 4

[2.1] Create and use particle effect in Ogre 2.1

Post by 123iamking »

I tried to recreate the sample Sample_ParticleFX from Ogre 1.10 to Ogre 2.1 (I just want to trigger the Fireworks effect only), but I when I copy the particle file emitted_emitter.particle (I see this file has Examples/Fireworks)
I got the exception

Code: Select all

OGRE EXCEPTION(2:InvalidParametersException): Cannot find requested emitter type. in ParticleSystemManager::_createEmitter at E:\Source\ogre\OgreMain\src\OgreParticleSystemManager.cpp (line 278)
So I try this example but still get the exception.

I see that in Ogre 1.10, the function createParticleSystem has 2 parameters: const String& name, const String& templateName
but in Ogre 2.1, there is only 1 parameter: const String& templateName. Anyway, according to Names are now optional, I think I'll just ignore name then.
123iamking
Gremlin
Posts: 152
Joined: Sat Aug 12, 2017 4:16 pm
x 4

Re: [2.1] Create and use particle effect in Ogre 2.1

Post by 123iamking »

123iamking wrote: Mon Oct 30, 2017 12:28 pm I tried to recreate the sample Sample_ParticleFX from Ogre 1.10 to Ogre 2.1 (I just want to trigger the Fireworks effect only), but I when I copy the particle file emitted_emitter.particle (I see this file has Examples/Fireworks)
I got the exception

Code: Select all

OGRE EXCEPTION(2:InvalidParametersException): Cannot find requested emitter type. in ParticleSystemManager::_createEmitter at E:\Source\ogre\OgreMain\src\OgreParticleSystemManager.cpp (line 278)
So I try this example but still get the exception.
About this, According to this article, just add the ParticleFX plugin to your project, about How to: just similar to add RenderSystem_Direct3D11 & RenderSystem_GL3Plus (Edit the file plugins_d.cfg, put the file Plugin_ParticleFX_d.dll into the Debug\Plugins)
So one thing left to do is try to bring some particle effect on screen, hope it won't be too much tricky :mrgreen:
123iamking
Gremlin
Posts: 152
Joined: Sat Aug 12, 2017 4:16 pm
x 4

Re: [2.1] Create and use particle effect in Ogre 2.1

Post by 123iamking »

Ok, so I try to follow the Explosion example
First, I got all the file of this example
  1. explode.dds
  2. explode.hlsl
  3. explode_fp.glsl
  4. explode_vp.glsl
  5. explosion.material
  6. explosion.particle
put in the folder Data/Particle (load this folder with file resources2.cfg)
And in create scene function, I call setup setupParticles()

Code: Select all

/*--------Effect--------------*/
	void EmptyProjectGameState::setupParticles()
	{
		/*Get scene manager*/
		Ogre::SceneManager* pSceneMana;
		pSceneMana = mGraphicsSystem->getSceneManager();

		/*Create particle*/
		Ogre::ParticleSystem* particleSystem = pSceneMana->createParticleSystem("explosionTemplate");
		particleSystem->setName("explosions");

		// fast forward 1 second  to the point where the particle has been emitted
		particleSystem->fastForward(1.0);

		// attach the particle system to a scene node
		pSceneMana->getRootSceneNode()->attachObject(particleSystem);
	}
But I got an Exception break when render the first frame :cry:
Visual Studio wrote:Exception thrown: read access violation.

std::_Vector_alloc<std::_Vec_base_types<Ogre::Pass * __ptr64,Ogre::STLAllocator<Ogre::Pass * __ptr64,Ogre::CategorisedAllocPolicy<0> > > >::_Myfirst(...) returned 0x10.

If there is a handler for this exception, the program may be safely continued.
And the full callstack is:

Code: Select all

>	OgreMain_d.dll!std::vector<Ogre::Pass * __ptr64,Ogre::STLAllocator<Ogre::Pass * __ptr64,Ogre::CategorisedAllocPolicy<0> > >::size() Line 1180	C++
 	OgreMain_d.dll!Ogre::Technique::getPass(unsigned short index) Line 382	C++
 	OgreMain_d.dll!Ogre::HlmsLowLevel::calculateHashFor(Ogre::Renderable * renderable, unsigned int & outHash, unsigned int & outCasterHash) Line 166	C++
 	OgreMain_d.dll!Ogre::Renderable::setDatablock(Ogre::HlmsDatablock * datablock) Line 100	C++
 	OgreMain_d.dll!Ogre::v1::BillboardSet::setDatablock(Ogre::HlmsDatablock * datablock) Line 918	C++
 	OgreMain_d.dll!Ogre::Renderable::setMaterial(const Ogre::SharedPtr<Ogre::Material> & material) Line 188	C++
 	OgreMain_d.dll!Ogre::v1::BillboardSet::setMaterial(const Ogre::SharedPtr<Ogre::Material> & material) Line 895	C++
 	OgreMain_d.dll!Ogre::Renderable::setMaterialName(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & name, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & groupName) Line 178	C++
 	OgreMain_d.dll!Ogre::v1::BillboardSet::_createBuffers() Line 867	C++
 	OgreMain_d.dll!Ogre::v1::BillboardSet::beginBillboards(unsigned __int64 numBillboards) Line 381	C++
 	OgreMain_d.dll!Ogre::v1::BillboardParticleRenderer::_updateRenderQueue(Ogre::RenderQueue * queue, Ogre::Camera * camera, const Ogre::Camera * lodCamera, std::list<Ogre::Particle *,Ogre::STLAllocator<Ogre::Particle *,Ogre::CategorisedAllocPolicy<0> > > & currentParticles, bool cullIndividually, Ogre::FastArray<Ogre::Renderable *> & outRenderables) Line 142	C++
 	OgreMain_d.dll!Ogre::ParticleSystem::_updateRenderQueue(Ogre::RenderQueue * queue, Ogre::Camera * camera, const Ogre::Camera * lodCamera) Line 732	C++
 	OgreMain_d.dll!Ogre::SceneManager::_renderPhase02(Ogre::Camera * camera, const Ogre::Camera * lodCamera, Ogre::Viewport * vp, unsigned char firstRq, unsigned char lastRq, bool includeOverlays) Line 1158	C++
 	OgreMain_d.dll!Ogre::Camera::_renderScenePhase02(const Ogre::Camera * lodCamera, Ogre::Viewport * vp, unsigned char firstRq, unsigned char lastRq, bool includeOverlays) Line 406	C++
 	OgreMain_d.dll!Ogre::Viewport::_updateRenderPhase02(Ogre::Camera * camera, const Ogre::Camera * lodCamera, unsigned char firstRq, unsigned char lastRq) Line 230	C++
 	OgreMain_d.dll!Ogre::RenderTarget::_updateViewportRenderPhase02(Ogre::Viewport * viewport, Ogre::Camera * camera, const Ogre::Camera * lodCamera, unsigned char firstRq, unsigned char lastRq, bool updateStatistics) Line 242	C++
 	OgreMain_d.dll!Ogre::CompositorPassScene::execute(const Ogre::Camera * lodCamera) Line 217	C++
 	OgreMain_d.dll!Ogre::CompositorNode::_update(const Ogre::Camera * lodCamera, Ogre::SceneManager * sceneManager) Line 1020	C++
 	OgreMain_d.dll!Ogre::CompositorWorkspace::_update() Line 752	C++
 	OgreMain_d.dll!Ogre::CompositorManager2::_updateImplementation(Ogre::SceneManagerEnumerator & sceneManagers, Ogre::HlmsManager * hlmsManager) Line 709	C++
 	OgreMain_d.dll!Ogre::RenderSystem::updateCompositorManager(Ogre::CompositorManager2 * compositorManager, Ogre::SceneManagerEnumerator & sceneManagers, Ogre::HlmsManager * hlmsManager) Line 1029	C++
 	OgreMain_d.dll!Ogre::CompositorManager2::_update(Ogre::SceneManagerEnumerator & sceneManagers, Ogre::HlmsManager * hlmsManager) Line 637	C++
 	OgreMain_d.dll!Ogre::Root::_updateAllRenderTargets() Line 1558	C++
 	OgreMain_d.dll!Ogre::Root::renderOneFrame() Line 1079	C++
 	PointAndClick.exe!Demo::GraphicsSystem::update(float timeSinceLast) Line 320	C++
 	PointAndClick.exe!Demo::MainEntryPoints::mainAppSingleThreaded(HINSTANCE__ * hInst, HINSTANCE__ * hPrevInstance, char * strCmdLine, int nCmdShow) Line 118	C++
 	PointAndClick.exe!WinMainApp(HINSTANCE__ * hInst, HINSTANCE__ * hPrevInstance, char * strCmdLine, int nCmdShow) Line 35	C++
 	PointAndClick.exe!WinMain(HINSTANCE__ * hInst, HINSTANCE__ * hInst2, char * strCmdLine, int intParam) Line 32	C++
 	[External Code]	
Did I do something wrong :)
I see that the error cause by mSupportedTechniques.empty() == true
File \ogre\OgreMain\src\OgreMaterial.cpp

Code: Select all

    Technique* Material::getBestTechnique(unsigned short lodIndex, const Renderable* rend)
    {
        if (mSupportedTechniques.empty())
        {
            return NULL;
        }
        else
        {
so the technique pointer is null, but the function getPass get called on this Null pointer, thus cause the error :)
File \ogre\OgreMain\src\OgreHlmsLowLevel.cpp

Code: Select all

        Technique *technique = mat->getBestTechnique( renderable->getCurrentMaterialLod(), renderable );
        Pass *pass = technique->getPass( 0 );
And in Output window did print this
Output window wrote: WARNING: material explosionMaterial has no supportable Techniques and will be blank. Explanation:
Pass 0: Vertex program explodeVertexProgram cannot be used - not supported.
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: [2.1] Create and use particle effect in Ogre 2.1

Post by al2950 »

I have not read all your posts, however I noticed you appear to be using a V1 material, or what is known as a 'Low Level Material'. I would highly suggest recreating the material using an 'Unlit HLMS' Material.
123iamking
Gremlin
Posts: 152
Joined: Sat Aug 12, 2017 4:16 pm
x 4

Re: [2.1] Create and use particle effect in Ogre 2.1

Post by 123iamking »

123iamking wrote: Tue Oct 31, 2017 8:12 am Ok, so I try to follow the Explosion example
...
But I got an Exception break when render the first frame :cry:
Visual Studio wrote:Exception thrown: read access violation.

std::_Vector_alloc<std::_Vec_base_types<Ogre::Pass * __ptr64,Ogre::STLAllocator<Ogre::Pass * __ptr64,Ogre::CategorisedAllocPolicy<0> > > >::_Myfirst(...) returned 0x10.

If there is a handler for this exception, the program may be safely continued.
...
So I decide to switch to another example - the firework example in Ogre 1x. With this example, I don't have the error above anymore.
First, use the particle file "E:\Source\ogre1x\Samples\Media\particle\emitted_emitter.particle" (Ogre 1.10 branch) for the project.
And some other files as I try to apply the texture for the firework:
  • "E:\Source\ogre1x\Samples\Media\materials\scripts\Examples.material"
  • "E:\Source\ogre1x\Samples\Media\materials\textures\flare.png"
  • "E:\Source\ogre1x\Samples\Media\materials\textures\flare.png"
Then call this code at create scene

Code: Select all

		/*Get scene manager*/
		Ogre::SceneManager* pSceneMana;
		pSceneMana = mGraphicsSystem->getSceneManager();

		/*Create particle*/
		Ogre::ParticleSystem* particleSystem = pSceneMana->createParticleSystem("Examples/Fireworks");
		particleSystem->setName("Fireworks");

		// attach the particle system to a scene node
		pSceneMana->getRootSceneNode()->attachObject(particleSystem);
Even though the firework look like it doesn't have color or shape (just blue block), but hey, at lest it works :)
Anyway, the reason that cause no color or shape is: according to the output window
Output window wrote:OGRE EXCEPTION(3:RenderingAPIException): Fixed Function pipeline is no longer allowed nor supported. The material Examples/Flare must use shaders in HlmsLowLevel::calculateHashFor at E:\Source\ogre\OgreMain\src\OgreHlmsLowLevel.cpp (line 157)
And that just leads to this article.
So..., the problem is because of the file Examples.material. According to this post, the file Examples.material need to be cleared and fill the following code

Code: Select all

hlms Examples/Flare unlit
{
     scene_blend add
     depth_write off
     diffuse_map flare.png
}
The material name is Examples/Flare because the following code of the file emitted_emitter.particle

Code: Select all

// Example emitted emitters
particle_system Examples/Fireworks
{
    material Examples/Flare
    point_rendering            false
    ...
123iamking
Gremlin
Posts: 152
Joined: Sat Aug 12, 2017 4:16 pm
x 4

Re: [2.1] Create and use particle effect in Ogre 2.1

Post by 123iamking »

To sum the whole thing up in one post.
Assume you use Ogre Empty project.
  1. Create folder Particle ([YourProject]\bin\Data\Particle) and
    declare this folder in the file resources2.cfg:

    Code: Select all

    FileSystem=../Data/Particle
  2. Put the following file into folde Particle
    Particle file: emitted_emitter.particle
    Material file: Examples.material

    Code: Select all

    hlms Examples/Flare unlit
    {
         scene_blend add
         depth_write off
         diffuse_map flare.png
    }
    And finally, the image: flare.png
  3. Add the Plugin_ParticleFX plug in for your project.
    1. put the file Plugin_ParticleFX_d.dll into the Debug's plugin folder ([YourProject]\bin\Debug\Plugins)
    2. Declare this plug-in in the file plugins_d.cfg

    Code: Select all

    Plugin=Plugin_ParticleFX_d
    3. Step 1&2 above is for Debug, you can do similar for release.
  4. Add the particle into your scene
    In the method: EmptyProjectGameState::createScene01(void)
    Use this code to add the particle effect into your scene

    Code: Select all

    		/*Get scene manager*/
    		Ogre::SceneManager* pSceneMana;
    		pSceneMana = mGraphicsSystem->getSceneManager();
    
    		/*Create particle*/
    		Ogre::ParticleSystem* particleSystem = pSceneMana->createParticleSystem("Examples/Fireworks");
    		particleSystem->setName("explosion");
    
    		// attach the particle system to a scene node
    		pSceneMana->getRootSceneNode()->attachObject(particleSystem);
  5. Run the project and use the camera to look for the firework- Enjoy :)
Post Reply