2D effects
by bentgarney · in Torque Game Builder · 03/06/2005 (3:41 pm) · 5 replies
#2
Where %factor is how transparent the object is, from 0.0 to 1.0.
2) Mostly depends on the sort of thrilling effects you want to achieve. :) I would recommend checking some OpenGL documentation on the command glBlendFunc(). (Not setBlendFunc as the tech docs state!) In short how it works is that it species how OpenGL scales the incoming color of your texture (the first option in glBlendFunc) and how it scales the value already in the frame buffer (the second option in glBlendFunc), when it adds them together.
So, the standard src_alpha and one_minus_src_alpha boils down to this formula: (where bA = blend alpha, sR = source red, sA = source alpha, dR = destination red, and so on.)
frame buffer R component = min(bR, sR * (sA / bA) + dR * (1 - (dA / bA)) ;
(repeat for the rest of the components, including alpha.)
If you work out that by hand, you'll see that it takes the incoming source values, modulates them by the source scaling factors (src_alpha), then adds it to the destination value in the frame buffer, which is also scaled by the dest factor. So, if your source alpha is 1.0 and your blending alpha is 1.0, you can simply reduce that to just: frame buffer R component = min (bR, sR). Otherwise, sR is blended together with the destination color, modulated by the source's alpha (assuming blend color is 1.0)...
BTW, I took that formula straight from the OpenGL reference manual, the so-called "Blue Book". I recommend that, and the implementation guide, the "Red Book". :)
Hmm..That's a terrible explanation, I suppose. I'm sure someone else could do better.
03/06/2005 (4:03 pm)
1) Really? You should be able to vary the alpha by doing:%obj.setblending (true) ;
%obj.setblendcolour ("255 255 255" SPC 255 * %factor) ;Where %factor is how transparent the object is, from 0.0 to 1.0.
2) Mostly depends on the sort of thrilling effects you want to achieve. :) I would recommend checking some OpenGL documentation on the command glBlendFunc(). (Not setBlendFunc as the tech docs state!) In short how it works is that it species how OpenGL scales the incoming color of your texture (the first option in glBlendFunc) and how it scales the value already in the frame buffer (the second option in glBlendFunc), when it adds them together.
So, the standard src_alpha and one_minus_src_alpha boils down to this formula: (where bA = blend alpha, sR = source red, sA = source alpha, dR = destination red, and so on.)
frame buffer R component = min(bR, sR * (sA / bA) + dR * (1 - (dA / bA)) ;
(repeat for the rest of the components, including alpha.)
If you work out that by hand, you'll see that it takes the incoming source values, modulates them by the source scaling factors (src_alpha), then adds it to the destination value in the frame buffer, which is also scaled by the dest factor. So, if your source alpha is 1.0 and your blending alpha is 1.0, you can simply reduce that to just: frame buffer R component = min (bR, sR). Otherwise, sR is blended together with the destination color, modulated by the source's alpha (assuming blend color is 1.0)...
BTW, I took that formula straight from the OpenGL reference manual, the so-called "Blue Book". I recommend that, and the implementation guide, the "Red Book". :)
Hmm..That's a terrible explanation, I suppose. I'm sure someone else could do better.
#3
03/06/2005 (4:14 pm)
A simple utility function setAlpha(0-100) on fxSceneObject would be quite nice.
#4
With regards to your other question; T2D will be about writing primitive actions, the things you're asking for are really compound actions. You're talking about lots of seperate actions there and yes, for the moment, they would need to be handled by you. We really can't start writing a "%obj.MoveToScaleAndKill()" function. I think what you're asking for though is animation and as we move forward, we've already got plans for animatable properties, much like the particle system.
Have you considered using a particle effect. It has all the animations you want although it doesn't allow collisions but that's not a problem, just mount it directly onto a fxSceneObject2D that does. The particle emitters have the concept of a single particle so that you can have just a single ball and this then allows you to have all sorts of timed animations as well. :)
@Seth: I messed-up when I let the "setBlendColour" function through. I had it on my list to normalise the parameters for that call and it just got missed. I think we'll be changing it either in the next update or the following one. The "setAlpha" is a good idea though.
@David: Oops, got a little get/set crazy with T2D there. Changed the doco, thanks.
One thing to note is that you can turn off the blending which will speed-up your rendering. There's quite a bit of tuning work for T2D still to happen. We're into the core stability phase so expect much more speed over the next few months as well as some really crazy cool stuff. *zips mouth shut*
- Melv.
03/07/2005 (1:30 am)
@Robert: Not wanting to gripe but have you looked at the reference doc? You could use search for "blend" on it. It's just that so many posts could be solved by searching them. Seeing lots of questions at the moment that would take seconds to answer with a quick search, that's all. Don't take this the wrong way mate.With regards to your other question; T2D will be about writing primitive actions, the things you're asking for are really compound actions. You're talking about lots of seperate actions there and yes, for the moment, they would need to be handled by you. We really can't start writing a "%obj.MoveToScaleAndKill()" function. I think what you're asking for though is animation and as we move forward, we've already got plans for animatable properties, much like the particle system.
Have you considered using a particle effect. It has all the animations you want although it doesn't allow collisions but that's not a problem, just mount it directly onto a fxSceneObject2D that does. The particle emitters have the concept of a single particle so that you can have just a single ball and this then allows you to have all sorts of timed animations as well. :)
@Seth: I messed-up when I let the "setBlendColour" function through. I had it on my list to normalise the parameters for that call and it just got missed. I think we'll be changing it either in the next update or the following one. The "setAlpha" is a good idea though.
@David: Oops, got a little get/set crazy with T2D there. Changed the doco, thanks.
One thing to note is that you can turn off the blending which will speed-up your rendering. There's quite a bit of tuning work for T2D still to happen. We're into the core stability phase so expect much more speed over the next few months as well as some really crazy cool stuff. *zips mouth shut*
- Melv.
#5
Particles are quite a nice way of doing it. :)
- Melv.
03/07/2005 (3:18 am)
@Rob: Okay, sorry. It's just that you didn't even mention the call in your post so I assumed you hadn't looked. My bad.Particles are quite a nice way of doing it. :)
- Melv.
Torque Owner Seth Willits