PLUGIN: AGSBlend. AGS Graphic Library - Source Available

Started by Calin Leafshade, Sun 01/08/2010 17:44:21

Previous topic - Next topic

Calin Leafshade

AGSBlend 1.0

Fixes alot of the bugs and adds some error checking. the function will return 0 on success and 1 if the coordinates are invalid (probably still a good idea to clamp them just incase though)

Allegro dependency has been removed.

binaries: http://svn.thethoughtradar.com/svn/AGSBlend/bin/

source: http://svn.thethoughtradar.com/svn/AGSBlend/src/

Includes the following functions:

int DrawAlpha(int destination, int sprite, int x, int y, int transparency)
Draws sprite source onto sprite destination at x, y with transparency

int GetAlpha(int sprite, int x, int y)
returns the alpha value for the pixel at x,y

int PutAlpha(int sprite, int x, int y, int alpha)
writes to the alpha channel at x, y

int Blur(int sprite, int radius)
box blurs a sprite with radius radius.

int HighPass(int sprite, int threshold)
High passes a sprite (useful for bloom and other effects.)

int DrawAdd(int destination, int sprite, int x, int y, float scale)
Draws a sprite additively


AGSBlend Alpha 0.1

Ok i'm putting this out for speedtests and giggles.

the plugin has three functions:

int DrawAlpha(int Dest, int Sprite, int y, int x, int trans)

This draws the sprite at slot "Sprite" on the sprite at slot "Dest" at coordinates x and y in relation to the destination sprite.
the trans value is between 0 and 100 (0 being full opacity and 100 being completely transparent)

all the alpha channel information is preserved so you can use it for particle effects on object and any gui composition you want.

int GetAlpha(int sprite, int x, int y)

This returns the alpha value (0-255) of pixel x,y on the sprite at slot 'sprite'

int PutAlpha(int sprite, int x, int y, int alpha)

This writes an alpha value ('alpha) to the sprite in slot 'sprite' at x,y

The above two features are really if you want to use the plugin for your own advance special fx. standard AGS functions can fiddle with the RGB values.

I'm also including a demo game. I'd be interested to see how far people can push it and still get 40fps.

I managed about 500 (big) particles on my 2.4ghz laptop so it seems pretty fast.

My blending algorithm was kinda just made up so i'm sure i can optimise it a little with some bitwise ops.

Currently the plugin requires the allegro DLL (which i have included) but its not really needed so i'll strip out all the references and rewrite the funcionality that it provides eventually.

I also plan to add Additive blending and other blending modes too.

CAVEATS: THE PLUGIN CONTAINS VERY LITTLE ERROR CHECKING SO BE CAREFUL WHEN USING IT. DO NOT DRAW OUTSIDE THE BOUNDS OF A SPRITE AND ONLY PASS 32-BIT SPRITES TO THE FUNCTIONS. Thank you :D

Plugin: http://www.thethoughtradar.com/AGS/AGSBlendPlugin.zip

Demogame http://www.thethoughtradar.com/AGS/AGSBlendDemoGame.zip

Have fun



GarageGothic

Damn, beaten to the punch :)

Excellent work, Calin. 700 particles seems to be the breaking point for me (2.4 GHz Centrino with a whole bunch of stuff open in the background), that's where fps starts flickering between 40 and 38. Anything much beyond that and it rapidly dips to 20.

Will keep working on my own implementation, mainly to see how SFML compares to Allegro, but it's not like there's much need for improvement beyond the goals you've already stated. Well done!

hedgefield

Yep, 700 was the point for me too whereafter things started getting a little flaky on my 2Ghz Core2 DUO. Though switching to DirectX allowed me to push the boundary up to 1020. Great module, can't wait to see where it goes and what people use it for!

Calin Leafshade

I tried it on my desktop and got up to about 1500 ^_^

but thats a quad core 2.8.

i never tried it on dx9 so it might go even higher.

although frankly even 700 sprites of that size is 490,000 pixels rendered 20 times a second (doing it every loops looks weird due to screen refreshing)
a 320x240 game only has 76,800 pixels to fill so it should be easily fast enough for low res games
even a 640x480 game only has 307,200 pixels on screen so it should be fine there too.

Crimson Wizard

Why do those called "particles"?  ::)

Anyway, my ole AMD Turion 2 Ghz laptop manages about 450-500 thingies, beyond this limit severe lags take place.

deltamatrix

I guess this cannot yet apply alpha channel on Characters or Room objects....it would be awesome if it could as I feel that this is a feature that AGS truly lacks.

It would also be cool if the alpha blend could be applied to a entire room (to provide a darkening effect)
BAD WOLF - TORCHWOOD - MR SAXON - THE BEES ARE DISAPPEARING - PANDORICA - RIVER SONG

Calin Leafshade

It can blend ANY 2 sprites together providing they are both 32-bit sprites with alpha channels

it's basically a replacement for the DrawingSurface.DrawImage function.

Characters and objects already support alpha channels its just that you couldn't dynamically blend the alpha channels at runtime.

Knox

Hey Calin,

Im testing this out and it awesome! I was wondering if you were planning on making some sort of "clear to alpha" function for this plugin? As in, you write something like:

int ClearToAlpha(int sprite);


This would just wipe the sprite clean and make it all transparent so when you want to redraw on it, you know the base is totally "clean"/transparent.

(If this is stupid let me know :P)


**EDIT**

Check out this thread: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=41597.0

Im guessing when you clear a surface (surface.Clear), that surface is no longer a 32 bit sprite or something and would explain why when you draw on top of it the gradient alpha is blocky/choppy?


**Never mind!! :)
**Great plugin :)
--All that is necessary for evil to triumph is for good men to do nothing.

Calin Leafshade

Ha ha well just to clarify:

Any drawingsurface functions seem to completely flatten the alpha channel so if you use the function in this plugin you can't use any drawing surface functions since it will destroy all the alpha information.

Having said that, an 'Alpha Clear' function might not be a bad idea as a kind of 32-bit alternative to the drawingsurface function.

I'll add it once i've finished getting rid of the allegro dependency and adding some error checking.

Knox

QuoteI'll add it once i've finished getting rid of the allegro dependency and adding some error checking.

Hey Calin, any news on getting rid of allegro for the plugin?  ;D

Also, I might not understand how things work but now that you guys are working on the editor, can AGSBlend be added into AGS (does that make sense?)...instead of just a plugin? Im guessing that's an engine thing, right...

Again, Im not sure if what Im saying makes sense since Im not sure how plugins + things like this work.
--All that is necessary for evil to triumph is for good men to do nothing.

Calin Leafshade

Ok this seems like a good opportunity to release this:

AGSBlend 1.0

Fixes alot of the bugs and adds some error checking. the function will return 0 on success and 1 if the coordinates are invalid (probably still a good idea to clamp them just incase though)

Allegro dependency has been removed.

http://www.thethoughtradar.com/AGS/ASGBlend1.0.zip

Includes the following functions:

int DrawAlpha(int destination, int source, int x, int y, int transparency)
Draws sprite source onto sprite destination at x, y with transparency

int GetAlpha(int sprite, int x, int y)
returns the alpha value for the pixel at x,y

int PutAlpha(int sprite, int x, int y, int alpha)
writes to the alpha channel at x, y

int Blur(int Sprite, int radius)
box blurs a sprite with radius radius.

int HighPass(int Sprite, int threshold)
High passes a sprite (useful for bloom and other effects.)

int DrawAdd(int Dest, int Sprite, int x, int y, float scale)
Draws a sprite additively

I need to clean up the code and then I'll release the source since its a real mess at the moment.

Knox

Nice!

For DrawSprite, what are the parameters "int viewx, int viewy, int basey"...I noticed this changed from the previous version, but Im not sure what to put there.
--All that is necessary for evil to triumph is for good men to do nothing.

Calin Leafshade

#12
Ahh well i was trying something out that was a little strange, I have uploaded a new version without those parameters here:

http://svn.thethoughtradar.com/svn/AGSBlend/bin/

unless you're using the custom blend modes it might be a good idea to stick with DrawAlpha since it will be slightly faster.

If anyone is interested i've added the source to a completely pointless svn repository (mainly so i can learn how it all works. Learning by doing!).

You can find the source here:

http://svn.thethoughtradar.com/svn/AGSBlend/src/

If anyone wants to improve on the algorithms, they are welcome to do so.
The box blur is especially weak.

I'd like to build a general purpose graphics library for AGS with things like Gaussian blur, filtered resize, and anti aliased shape drawing (SteveMcCrea's module can't do it on 32-bit surfaces due to limitations of the engine)

If anyone is interested in helping, let me know and I'll allow you commit privileges for the svn.

The basics are there and it's easy to see from the code how to get the sprite arrays.
From there you can basically do anything you like with the sprite.
My mathematics isnt really good enough for some of the more hardcore functions but i'm sure some of you are (Khris, McCrea, Tzachs, SSH, whoever)


Dualnames

Sorry to sound like a dick, is that the same plugin that was awesome but the more tight the effect was, the slower the game became? I mean, is there any improvement on the speed? Cause the effect is awesome, don't ever think I'm not saying that.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Calin Leafshade

The bloom thing I demoed a couple of months ago was just a way of using the functions provided by this plugin.
Thats not what the plugin *does*

Although you can still use bloom on small areas of the screen (McCarthy 2 does this perfectly fine)

This release is an optimised release DLL so it should actually be quicker.

All the plugin does currently is allow users to draw 32-bit sprites on top of other 32-bit sprites, mixing the two alpha channels.

It also has functions for blur and high pass.

The reason i think it would be a good idea to use this plugin as a general graphics library is that its all native C++ and so it's faster than using AGS script.


Knox

This is great! I love this plugin, saves me lots of work!

You say to use the DrawAlpha instead of the DrawSprite...how much faster is it? I should check that out then.
--All that is necessary for evil to triumph is for good men to do nothing.

dbuske

Apparently doesn't work with the latest editor.  I fet the message of a missing .dll.  I download the dll and it still does not work.
What if your blessings come through raindrops
What if your healing comes through tears...

Calin Leafshade

Editor version will not affect it and it works fine for me.

Which dll does it say is missing?

dbuske

Sorry, for some reason it works now.  Murphy's law just to make me a liar.
What if your blessings come through raindrops
What if your healing comes through tears...

Monsieur OUXX

- If I just want to blit a sprite into my background (or directly on top of it) with a certain global alpha value, do you think I should use the plugin, or is the built-in AGS function faster?
- What if I want to blit SEVERAL sprites in a row (I guess locking the background and getting its graphic is quite slow) ?

Actually maybe I should just make them objetcs and fiddle with their .opacity property.

 

SMF spam blocked by CleanTalk