Author Topic: Splash Sprites  (Read 8360 times)

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Splash Sprites
« on: 22 September 2009, 01:17:55 »
I had an idea. I noticed how god aweful our splashes are for customization. Why can't we have sprites? I don't really know how most games work, but this does seem like the best option, and I have used them before in some testing, such as with the Iriltch (sp) 3D engine. They would work FANTASTIC to put it simply. It could display a series of images, such as in order, from frame 1, to frame x, and would 'tilt' towards the camera so that we always see the image. Not sure how other engines do it, but I can imagine that it would be great for splashes.

Sprites are simply still images, usually done in large numbers, such as 20 sprites (can also be called frames). They work like an animated GIF, displaying each image after the other to appear to make a moving image. It would be great for explosions.

Here's an example:


Of course, we would have to split into individual images, most likely, and alpha would be needed for a background. PNG would be the best format.

What do you think?
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

silnarm

  • Local Moderator
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Splash Sprites
« Reply #1 on: 22 September 2009, 06:35:21 »
That's pretty old school :)

Still has been used to good effect even in recent times mind you.  But none the less, I think I'd prefer fancier particle systems than sprites.

I've had the renderer under the microscope recently, and its booked in for a service soon, aimed at improving performance.  But if any of us turn out to have a knack for this OpenGL business, maybe some new fancy effects will follow.

Glest Advanced Engine - Code Monkey

Timeline | Downloads

wciow

  • Behemoth
  • *******
  • Posts: 968
    • View Profile
Re: Splash Sprites
« Reply #2 on: 23 September 2009, 16:52:49 »
Good idea Omega but I think there are a few things ahead of this on the todo list.

Would like to see it implemeted as an option some day tho  :)

Check out my new Goblin faction - https://forum.megaglest.org/index.php?topic=9658.0

ElimiNator

  • Airship
  • ********
  • Posts: 3,391
  • The MegaGlest Moder.
    • View Profile
Re: Splash Sprites
« Reply #3 on: 23 September 2009, 20:52:58 »
Yes thats a really good idea, think of the possibilities with that.
I wouldn't think it would be to hard ether I might be wrong though.
Get the Vbros': Packs 1, 2, 3, 4, and 5!

daniel.santos

  • Guest
Re: Splash Sprites
« Reply #4 on: 24 September 2009, 06:57:47 »
I don't mind this type of sprite implemented into the particle system.  I can assure that we will need to have particles with custom images on them like this (the type that always face the camera, or at least on 2 axis, I forget what these types of particles are called).  But using pre-cooked sprites to make an effect is very old school and the technology to do it better is has more than abundantly saturated the low-level consumer market, so there's no excuse, beyond lack of time (or expertise), to implement it right (in 3D).  I'm not saying that the particle systems aren't lacking, indeed I ran into this when implementing the visual effects for healing (priests) and mana transfer (acolytes) in FPM.  To this day, the acolyte's mana transfer looks too much like an attack, and that's just because the code that was originally designed just for that, so was hard to adapt for a special effect that's supposed to look like energy moving from one unit to another in a beneficial fashion.  I think all of that stuff is in what is now the "0.3_deprecated" branch (of which, the goodies will eventually be pulled out into a new branch, probably after networking re-write is finished, so it can be merged with all of the 0.2.12a and network changes).

The only things I have added to the particle systems is to the attack particle system and is documented here: https://docs.megaglest.org/GAE/Projectile_Particle_XML.  Sadly, still lacking from all particle systems is (to my knowledge):
  • The ability to have black colors.  For some reason, each color's luminance determines it's alpha level, and I'm not sure why.  This makes it impossible to have dark colored effects (maybe there's a better term for this, but essentially, you can't lower the light level if I understand correctly).
  • The ability to have an imagage for particles.  Currently, you control the color (which should remain), but the image is only use for alpha values.
  • Need lots more algorithms to spell out how particles behave (I think I listed this out in a thread a year ago or so).
  • As discussed in the old threads about weather, I would like a weather system that has wind and each particle system says how much each particle is affected by wind.  Contrast this to the fire particle systems which are always blowing in a single direction.

But to get back to omega's original issue, this is a pretty explosion.  We should be able to do this in real-time, 3D with dynamic interaction with the environment, i.e., (back to the weather thing) explosions should create extremely high pressure systems, which the weather engine performs calculations against every client (or weather) frame, thus transferring the pressure to adjacent cells, creating wind.  If two explosions occur simultaneously and adjacently, the pressure in the middle should keep them from overlapping (in essence) and you should see a greater push on either side due to this.  In addition, if a fire is burning nearby, the particles should be blown by this.  This type of system isn't *that* hard (and I say that part carefully :) ) to implement and it makes for some amazingly realistic-appearing scene.

This fits with the scheme of how trees and "blowable" objects were supposed to work (trees, shrubs, etc.).  If one wanted to go the step beyond this, you would define models with "blowable" (or maybe a better word is in order, one that doesn't conjure so many other connotations :) ) aspects, like hair, robes, etc., although I think we would need to have full weighted-skeleton animation and a nice physics engine in place before this becomes easy to implement cleanly (i.e., without a lot of hacks).

EDIT: Oh, I also forgot to mention that the particle system also needs to be able to have full 3d particles (i.e., small objects that are rendered instead of the "always facing camera" polygons) in order to create some of the cooler affects.
« Last Edit: 18 June 2016, 17:28:47 by filux »

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,239
    • View Profile
    • http://www.titusgames.de
Re: Splash Sprites
« Reply #5 on: 24 September 2009, 12:25:09 »
I also think we don't need sprites. As daniel says, a better particle system would be much much better and will give us much more eyecandy.
I know black color is not possible, but why?
Is this an opengl restriction? It looks like spring has dark particles!
« Last Edit: 24 September 2009, 12:51:55 by titi »
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

Hectate

  • Guest
Re: Splash Sprites
« Reply #6 on: 24 September 2009, 13:24:17 »
What he's saying is happening is that the alpha channel is being pulled from the brightness of the color itself. As you get closer to black as your color the actual engine is just rendering it more transparent (until black is 100% alpha channel).

It definitely makes it difficult, because there are a lot of cool effects that could be done with dark color particles. Some nice black and deep blood red colored magical attacks would be perfect for some of the Dark Magic units, for instance.

Back in my HL modding days this was an issue whenever a newbie selected "Additive" mode for something - you could never use it to make something darker. Perhaps the code is using additive mode and needs to be changed? Either to a different mode (which would probably significantly change many existing particles) or to add a negative (or several similar) mode available via an XML line. Would that work?

daniel.santos

  • Guest
Re: Splash Sprites
« Reply #7 on: 24 September 2009, 20:14:52 »
I'll have to look at the code again, but there's already an "alpha" value for all of these, so it shouldn't have to use this "additive" mode as far as I understand.  It could have just been an early coding oversight on Martiño's behalf, but then again, I'm still green in 3d graphics stuff.

daniel.santos

  • Guest
Re: Splash Sprites
« Reply #8 on: 24 September 2009, 20:36:39 »
First off, just for reference, this issue has had a bug opened against it for some time now: https://bugs.codemonger.org/show_bug.cgi?id=60

So here's the code that sets the blend mode:

Code: [Select]
void ParticleRendererGl::setBlendMode(Particle::BlendMode blendMode){
    switch (blendMode) {

    case Particle::bmOne:
        glBlendFunc(GL_SRC_ALPHA, GL_ONE);
        break;

    case Particle::bmOneMinusAlpha:
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        break;

    default:
        assert(false);
    }
}

And it does appear to get called prior to rendering quads (polygons with particles) and lines, although it's overriding a previous glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) call in ParticleRendererGl::renderManager().  Either way, glBlendFunc() supports a lot more options that can be easily made available in the particle system's .XML.  I'll try this out and see what I can come up with.  If I can't solve it quickly, I'll have to move on (back to networking stuff) but it's bugged me for a while too. :)  Also

daniel.santos

  • Guest
Re: Splash Sprites
« Reply #9 on: 24 September 2009, 21:21:55 »
Ahh! The problem appears to be that there's no mechanism to set the blend mode in the particle system's .XML.  Additionally, the buffer that particle rendering is drawn to is still subject to whatever blending is being done with the actual frame buffer, so I have to look at that as well (I don't think it draws directly to the frame buffer).  Even still, reading the docs for glBlendFunc, what's hard-coded shouldn't make dark colors translucent, so there's probably something else :(

Hectate

  • Guest
Re: Splash Sprites
« Reply #10 on: 24 September 2009, 21:26:18 »
We could always make some test particles, yes? Specifically designed to be solid black. Or maybe a square with a diagonal separation where one half is 100% black, no alpha - and the other 100% alpha. They'd be of no use in the actual game other than for testing.

daniel.santos

  • Guest
Re: Splash Sprites
« Reply #11 on: 24 September 2009, 23:30:43 »
Yea, that's what I just did and agonized for a long time over it.  But alas, I found the f**king problem!!!  The blend function is getting set more than once, and this was causing confusion.  But, in essence, using glBlendFunc(GL_SRC_ALPHA, GL_ONE); causes this behavior and using glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); solves it.  I'm going to add a <blend-func sfactor="value" dfactor="value"/>  that maps directly to this function call to solve the problem and allow for the greatest flexibility.  I'm putting this in the (freshly created) 0.2.13 branch.  I'll have to get with silnarm and hailstone to decide what all we want to do in the next minor release.

Hectate

  • Guest
Re: Splash Sprites
« Reply #12 on: 25 September 2009, 01:30:10 »
Well about 2/3rds of it was a foreign language (j/k) but good that's awesome news! Does this mean that we'll be able to select from a few different blend functions when creating particle systems?

silnarm

  • Local Moderator
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Splash Sprites
« Reply #13 on: 25 September 2009, 03:35:39 »
This is great news indeed!

However... I'm not so sure <belnd-func> is a good idea, with those 'attributes' anyway. Hectate might have been joking about the 2/3, but I suspect not about the GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA stuff ;)

I just had a look at table 6-1 in the red book, simply mapping the parameters of glBlendFunc() to XML attributes is not going to be very modder friendly.  I think we are going to need to figure out what combinations achieve desirable effects, and expose them with friendly names.

Although, I guess the flexibility would be nice, so how about something like,
Code: [Select]
<blend-func type="glest" /> <!-- The 'normal' Glest type -->
<!-- Or ... -->
<blend-func type="dark" /> <!-- New 'dark' particles -->
<!-- Or ... -->
<!-- Other 'named' types -->
<!-- Or ... -->
<blend-func type="custom" sfactor="value" dfactor="value" />
Glest Advanced Engine - Code Monkey

Timeline | Downloads

Hectate

  • Guest
Re: Splash Sprites
« Reply #14 on: 25 September 2009, 04:00:09 »
I can't speak for anyone else, but Standard (alpha channel used), Additive, Subtractive, Multiply, and Divide all are common to me from use in Gimp and elsewhere. I don't know how well they correspond with the parameters of OpenGL's blend function, but those would allow some nice effects including both "dark" and "negative" particles.

Just some thoughts...
I wish I had the coding experience. Thanks again for looking at this. 

daniel.santos

  • Guest
Re: Splash Sprites
« Reply #15 on: 25 September 2009, 17:13:10 »
Look guys, I don't understand this sh*t, I just managed to figure out the part I needed is all, LMAO! :) So here's what I suggest:  If you find a nice sub-set of these settings, more power to your happy arse!  We'll add an alternate definition so it accepts either

<blend-mode src="P(δφ)N(δθ)A(φ,θ,ψ)" dest=""/>

or it accepts the more friendly version (to which we internally map the src & dest values):

<blend-mode type="dark/>

In the mean time, it's documented here: https://docs.megaglest.org/Splash_Particle_XML and it tells you the values you can for the classic behavior and the one that will allow dark particles, which is, respectively:

<blend-mode src="src_alpha" dest="one"/>
and
<blend-mode src="src_alpha" dest="one_minus_src_alpha"/>

I wish I understood the rest of the color functions, but, in short, it sounds like you can do a lot of stuff (negative particles could look cool!).  Also, no need for a "type=custom", we'll just make sure that one or the other is present (a type or src/dest pair), and we can call it sfactor and dfactor too, if that would make anybody happy :)
« Last Edit: 18 June 2016, 14:22:59 by filux »

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: Splash Sprites
« Reply #16 on: 25 September 2009, 22:06:53 »
Sprites WOULDN'T be needed if we had the proper spectrum of colors at our displosal. Alpha isn't really a color. It is the transparency applied to the color. Options include having colors work how ever they do in web design.

For example, we only have three colors, RGB, which we can use either HEX (#FF0000 is red), in percentages (rgb(100%,0,0) is red), in absolute values of 0-255 (rgb(255,0,0) is red). Glest only offers these three colors too, yet look:

255,255,255 = white
0,0,0 = black
255,0,0 = red
0,255,0 = green
0,0,255 = blue
120,120,120 = grey
50,0,0 = brown

etc, etc, etc;

Of course, they can also be done in percentages (which fit well with glest's format of 0-1), though I'm more comfortable with hex (though I showed you it in 255 method, since it is the W3C recommendations and is easier for others to understand.
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

daniel.santos

  • Guest
Re: Splash Sprites
« Reply #17 on: 25 September 2009, 22:41:48 »
Hex away!  I'm not 100% certain which version this was introduced in (maybe 0.2.11?), but you can specify colors in XML in either format:
Code: [Select]
<some-color-tag red="0.5" green="0.1" blue="0.0" />
<some-color-tag rgb="801b00" />
<!-- or with alpha -->
<some-color-tag rgba="801b00ff" />

EDIT: Oh, the other thing is that I believe we need better support for multiple particle colors within a single particle system.  Alternately, the 0.3 (depreciated) compound particle system can be used.  Either way.

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: Splash Sprites
« Reply #18 on: 25 September 2009, 22:57:38 »
Really? My bad. Never realized.

Does it allow for the same colors as say a webpage would? ie: would rgb=000000 become black?
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

daniel.santos

  • Guest
Re: Splash Sprites
« Reply #19 on: 25 September 2009, 23:01:10 »
well, yea, because it follows the exact same format: each byte specifies a color value between zero and 255 (0xff).  The only thing is that if it's a 4 value color (RGBA) then you have to have the extra two hex digits.  For 3-value colors, you use rga="123456" and for 4 value colors, you use rgba="12345678".

Hectate

  • Guest
Re: Splash Sprites
« Reply #20 on: 25 September 2009, 23:40:18 »
A quick Google reveals some information concerning glBlendFunc and it's source/destination modes... very interesting read - thank you daniel.santos for the links.

Unfortunately a little knowledge can be a dangerous thing. Shouldn't we really want to implement access to the glBlendEquation as well? That seems to be strongly linked into the end result...

Also, I found this a very interesting set of examples. In particular I liked the invert example (that's what I meant by negative particles)
http://resumbrae.com/ub/dms424_s03/08/p06.html
Code: [Select]
/* Invert all the colors */

glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
glColor4f(1.0, 1.0, 1.0, 1.0);
I'm not sure if it has any main page, but it starts with p01.html and many pages have examples in .c files apparently.

Ah, if you go all the way back - http://resumbrae.com/ub/ - there's a large number of class pages for Dave Pape's classes! Nifty./me goes to reading...


daniel.santos

  • Guest
Re: Splash Sprites
« Reply #21 on: 28 September 2009, 10:18:44 »
OMFG!!! I HATE merging!!! :'(  :'(  :'(  :'(  :'(  :'(  :'( :'(  :'(  :'(  :'(  :'(  :'(

Well, even though I finally reverted all of my changes those 3 days I spent attempting to get things merged weren't wasted as I have learned a few valuable lessons.  Anyway, I finally got back to screwing with this and, whee! what fun! =)

I'll be modifying the wikia shortly, but I've added most of the code for the glBlendEquation as well.  If either are omitted, it just uses the default values.
« Last Edit: 18 June 2016, 13:09:34 by filux »

daniel.santos

  • Guest
Re: Splash Sprites
« Reply #22 on: 28 September 2009, 10:49:57 »
Ok, I've added the updated info here: https://docs.megaglest.org/GAE/Projectile_Particle_XML.  I tried the reverse colors thing with the battlemage attack and it did very weird things, I'm sure because so many particles overlap eachother in that particle system.  Either way, thanks for posting the info!  I imagine it would work better with a single particle or particles that are more spaced out.  Now I'm beginning to wonder if we need some mechanism to (optionally) draw all of these particles to some buffer 1st so we can use one blend function for drawing them to the buffer and a second to blend the resulting buffer with the frame buffer (or whatever it blends to :).
« Last Edit: 18 June 2016, 13:09:15 by filux »

 

anything