My goal was to implement fire as particle system using built in particle system support in ogre instead of coding own by myself. I had some problems which I didn't solve very nicely, so any suggestions are welcome
Because texture is volume texture stored in DDS (3D texture) I needed to use custom shaders and animate particles inside shader. Current implementation of ParticleSystemRenderer for rendering particles as billboards doesn't support custom vertex format definitions and I think that also using BillboardSet is not very good forbillboards which are rendered via shaders. So I created my own ParticleSystemRender which allows defining own vertex format in particle system script. Second problem was how to bind custom data to particles and access these data in shader. Particle class support BRAND NAME but that's all. It is not possible to handle this data in current emitters implementations - It is only possible to create this data in current renderer but there is no way how to work with it in current classes.
I decided to solve this by writing my own emitter class (I copied BoxEmitter from FX plugin) and add support to emitter for setting custom data in emitted particles. So result is that renderer create vertex declaration based on informations in script and at the end of declaration it adds also one tex coord with float4 type which is filled from particles.
Source code:
http://www.mediafire.com/?8t6nstsk8qy6yp8
Updated for the Ogre 1.8.0 - I built the Ogre from source and updated my project settings to this, so for OgreSDK it will be maybe necessary little adjustment. I still use VS2005, so only the project files for this VS are provided (I am just starting with CMake so if it will be huge interest, I'll create the settings for it). Anyway also with the latest Ogre it is not working properly with OpenGL - it seems that volumetric textures are not fully supported in Ogre with OpenGL renderer. During porting from Ogre 1.6.x to 1.8.0 I didn't know how to adjust/fix the methods in ShaderParticleRenderer::getNumWorldTransforms and in ShaderParticleRenderer::getWorldTransforms (I left the original code commented there so if anybody will suggest proper migration, I'll change it (seems that some methods from Ogre::Node were removed). Also in release mode from unknown reason it is not possible to unzip OgreCore.zip - in debug there is no problem. So in release mode it is necessary to unzip the file to the same folder and just comment it (or remove) in resources.cfg, then it is also working in release without problem.
Particle script for this:
Code: Select all
particle_system nVidia/fire
{
quota 200
material animated_particle
particle_width 2
particle_height 2
cull_each false
renderer shader
sorted true
local_space false
iteration_interval 0.01
nonvisible_update_timeout 0
// renderer specific
diffuse_colour true
texture_coord true
particle_size true
time_frag_inv true
// emitter for fire particles
emitter BoxWithCustomParam
{
angle 0
colour 1 1 1 1
direction 0 1 0
emission_rate 5
position 0 0 0
velocity_min 0.5
velocity_max 1.0
time_to_live_min 1.5
time_to_live_max 1.8
duration 0
// box emitter specific
width 0.3
height 0.1
depth 0.3
custom_params 0.0 0 0 0
}
// emitter for smoke particles
emitter BoxWithCustomParam
{
angle 10
colour 1 1 1 1
direction 0 1 0
emission_rate 20
position 0 0 0
velocity_min 2.5
velocity_max 4.0
time_to_live_min 1.9
time_to_live_max 2.1
duration 0
// box emitter specific
width 0.3
height 0.1
depth 0.3
custom_params 0.5 0 0 0
}
}