Game Development Community

Animated particle textures

by Howard Dortch · in Torque Game Engine · 06/26/2004 (7:45 am) · 18 replies

I noticed in the ParticleEngine.cc file there is a provision for having multiple textures for a particle and page flip between them at some rate. I havent seen much discussion on this in the forums and wondered if anyone could show me how to implement it.

I want a nice flickering flame for a fire rather than the single boiling texture I have seen in the demos.

#1
06/26/2004 (7:55 am)
Of course, you'll have to do some tweaking, but this should get you started. This was actually modified from one of my weapon particle scripts, which does have a nice effect. I never could get a fire or smoke effect which was any better than just using a single particle texture, though.

datablock ParticleData(AnimatedFireParticle)
{
   dragCoeffiecient     = 0.5;
   gravityCoefficient   = -0.5;
   inheritedVelFactor   = 0.0;

   lifetimeMS           = 3350;
   lifetimeVarianceMS   = 0;

   textureName          = "fps/data/shapes/particles/animated/Fire1"; // this is used if the card doesn't allow animated textures

   useInvAlpha = false;
   spinRandomMin = 0;
   spinRandomMax = 0;

//begin animated particle specifics 
//
   animateTexture = true;   
   framesPerSec = 8;

   animTexName[0]       = "fps/data/shapes/particles/animated/Fire0";
   animTexName[1]       = "fps/data/shapes/particles/animated/Fire1";
   animTexName[2]       = "fps/data/shapes/particles/animated/Fire2";
   animTexName[3]       = "fps/data/shapes/particles/animated/Fire3";
   animTexName[4]       = "fps/data/shapes/particles/animated/Fire4";
   animTexName[5]       = "fps/data/shapes/particles/animated/Fire5";
   animTexName[6]       = "fps/data/shapes/particles/animated/Fire6";
   animTexName[7]       = "fps/data/shapes/particles/animated/Fire7";
   // animTexName[8]       = "fps/data/shapes/particles/animated/Fire8";

//end specifics

   colors[0]     = "1.0 1 01 0.75";
   colors[1]     = "1.0 1 1 0.5";
   colors[2]     = "0 0 0 0.0";
   sizes[0]      = 1.5;
   sizes[1]      = 2.0;
   sizes[2]      = 1.0;
   times[0]      = 0.0;
   times[1]      = 0.2;
   times[2]      = 1.0;
};

datablock ParticleEmitterData(AnimatedFireParticleEmitter)
{
   ejectionPeriodMS = 20;
   periodVarianceMS = 1;

   ejectionVelocity = 0.0;
   velocityVariance = 0.0;

   thetaMin         = 0.0;
   thetaMax         = 0.0;

   particles = "AnimatedFireParticle";
};
#2
06/26/2004 (10:38 am)
My fire looks like a bunch of squares, dont suppose I need alpha channel in there?
#3
06/26/2004 (10:56 am)
Alpha or normal transparancy should work. It'll have to be in a format that supports it, like PNG or TIF(?). You may also have to play with the colors and invalpha setting to perfect it.
#4
06/26/2004 (11:07 am)
Tried alpha channel but still get squares
#5
06/26/2004 (11:13 am)
Make sure your texture is a power of two.

Beyond that, you're just going to have to play with it until you figure it out.
#6
06/26/2004 (1:02 pm)
It doesn't like the frames per second any idea here?

>>> Advanced script error report. Line 49.
>>> Some error context, with ## on sides of error halt:
animateTexture = true;

// numFrames = 8;

framesPerSec 8;##
##
#7
06/26/2004 (1:55 pm)
FramesPerSec = 8; ??
#8
06/26/2004 (2:09 pm)
:) typo?
#9
06/26/2004 (3:56 pm)
Not a typo seems to be a bug.
I commented out the numFrames, framesPerSec and it seems to work now at least. I tried lots of values there but still get that error. What number to you suggest?
#10
06/26/2004 (7:24 pm)
Where in the world are you getting "numFrames" from? It's not in the code I posted earlier.

I think you're either using old Tribes2 forcefield datablock code or confusing some leftover code from said forcefields. This is the only place that I know of that uses "numFrames".
#11
06/26/2004 (11:18 pm)
@Eric from the engine code, if it's not used can someone remove it from the code so as not to confuse?

ParticleData : public SimBlockData

bool useInvAlpha;

bool animateTexture;
U32 numFrames; <<<<<<<<<<<<<<<<<<<<<<< ERIC
U32 framesPerSec;

ColorF colors[ParticleEngine::PC_COLOR_KEYS];
F32 sizes[ParticleEngine::PC_SIZE_KEYS];
F32 times[4];
#12
06/27/2004 (7:48 am)
Where did the "numFrames = 8;" come from then?
#13
06/27/2004 (8:02 am)
I just set it to 8 in the cs file, as I said before I tried lots of values there the 8 just happened to be there when I copied the error from the log file.
numFrames seemed to be just a number for the code to know how many sprites to allocate rather than reading textures and doing a count.

What is the problem with the number 8?

framesPerSec was the error not a commented out numFrames value
#14
06/27/2004 (8:08 am)
I gave you code that should work. There's no "numFrames" in that code--perhaps it's autogenerated from the number of textures. I don't know. However, I'd recommend reverting back to what I gave you and starting over.

BTW, make sure the texture directory is listed correctly in AnimTexName. You might change them to "~/data/shapes/particles/animated/Fire0"; instead.
#15
06/27/2004 (10:08 am)
Howard, I think RedCore and Westy was pointing out the fact that there's no equal sign in the quoted error message; is that the problem?
#16
06/27/2004 (10:24 am)
Bingo Luke thanks
#17
05/07/2008 (12:35 pm)
Hey I know that this thread is pretty old but because it's the first thing that comes up when you search for animated particles I thought I'd just post my findings for TGEA:

I wasn't able to get the animTexName[x] array to work in TGEA 1.7.0 as those previously managed to get working in older builds of the engine. The only way I was able to successfully get animating textures was to use animating texture coordinates. How to do this can be found here.

tdn.garagegames.com/wiki/TSE/Particles
#18
05/07/2008 (12:43 pm)
The only way to animate particles in TGEA is using animated texture coords. I don't believe TGEA has ever supported the old way of doing it. Not since TGEA 1.0 at any rate.