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.

 

Calin Leafshade

AGSBlend is *designed* for 32-bit sprites with alpha transparency. Since the background doesnt have that then you are essentially doing unnecessary calculations so you should use the built in functions.

Monsieur OUXX

 

Construed

Could this added functionality perhaps enable me to draw one sprite to another at a specified location on the sprite?
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Calin Leafshade


Construed

I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Construed

Any idea why the draw is coming out splintered like this?
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Calin Leafshade

Not without seeing the code.

But remember this only works for *32bit* sprites.

Construed

Ah, ok.

I'll have to start keeping track of the bits :D

Thanks- Jar
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Construed

#28
Sorry for bombing your thread, but i have one last question,
Is it possible to assign the drawing to an entire loop of sprites or just to an entire characters loops?

EDIT:Or perhaps a way to assign it to a large multitude of sprites at once?
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Ryan Timothy B

#29
Hey Calin,
First time I'm checking out this plugin. I actually haven't even done anything with it yet, but I'm already curious. Why aren't you using an extender function for DrawAlpha and the other functions or is that not possible with a plugin?

Also, if I create my own dynamicsprite with AGS, will it actually allow me to draw an alpha channeled sprite to that? Since a created sprite will be pure pink. Thanks a bunch.

Calin Leafshade

The plugin API doesnt expose the dynamic sprite struct but i guess you could make it an extender in the header if you really wanted.
Or alternatively you could wrap the function in an extender function if you feel its necessary (I know you know this. it's 1 line of code)

As for creating a new sprite it should work as expected since a new dynamic sprite with an alpha channel will init to 255,0,255,0 so the resulting blends will take the alpha channel into account.

There are a couple of reasons you shouldnt use this plugin anymore though if you are a programming whizz such as yourself.

Firstly it's inefficient. Every time a sprite is drawn the surface is locked and unlocked. For repeated draws this is terribly inefficient. I could have added a "locksprite() and releasesprite()" function but that increases the likelihood of errors for inexperienced scripters so i kept it simple.

Secondly the engine source is open now. You should just edit the drawsprite function in the engine source so you dont have to deal with a plugin for such base functionality.

Thirdly you sacrifice alot of the object orientation with c style functions like this. Ideally (if still using the plugin) you should rewrite it with its own drawing surface object using the Managed Object interface provided by the plugin API.

Ryan Timothy B

Unfortunately I don't know enough about C# (if that's what the engine and editor are created with) to add my own alpha blending abilities.

Although I am tempted, since I really want Character.Speaking to return true whenever the character is talking, regardless whether the character has a speech view set and is animating. But as I said, I don't yet know enough to even look into adding these features for myself.

Knox

Hi Calin,

Ive got this plugin working great and using it a lot. Its awesome!

I was wondering though, how could I make a simple gui background alpha sprite be applied over another gui in "screen" blend mode? Do I have to draw it to a dynamic sprite everytime that GUI is opened, or can I set something somewhere into the properties of the gui.background image directly (somehow). Its so that a sprite of a light-cone is blended over objects underneath it to make it look like its lighting that area.

Its number "8" in the enum eBlendModes.
--All that is necessary for evil to triumph is for good men to do nothing.

Calin Leafshade

Theres no mechanism for one gui being drawn onto another in a different blend mode so you would need to do all your drawing manually onto a *single* dynamic sprite and apply that to a single gui.

However the blending modes are limited due to the fact that they can only be blended with another single sprite and not with the sprites and stuff beneath it in the draw order.

For instance you cant use a gui in screen mode to draw on top of a room background below it.

Monsieur OUXX

 


Calin Leafshade

The plugin has been rendered obsolete by the latest version of AGS.

Except the Blur and Highpass functions maybe.

Crimson Wizard

Quote from: Calin Leafshade on Mon 02/12/2013 20:15:59
The plugin has been rendered obsolete by the latest version of AGS.
Why? 3.3.0 supports only "normal" alpha blending mode, while plugin presents about 20 special effects (Add, Subtract, Burn, etc).

Calin Leafshade

That's true I suppose. I never really considered those useful.

selmiak

Oh they are. Will they be in 3.3.1 or 3.4.0?
Of course they should be appliable to every object/GUI/whatnot seperately and not a gamewide default blending mode in general settings.

David Ostman

Quote from: selmiak on Mon 02/12/2013 23:30:32
Oh they are. Will they be in 3.3.1 or 3.4.0?
Of course they should be appliable to every object/GUI/whatnot seperately and not a gamewide default blending mode in general settings.
They are planned to be added to the engine natively? That would be amazing :D

dbuske

What if your blessings come through raindrops
What if your healing comes through tears...

Calin Leafshade


Knox

Quote from: David Ostman on Mon 02/12/2013 23:46:34
Quote from: selmiak on Mon 02/12/2013 23:30:32
Oh they are. Will they be in 3.3.1 or 3.4.0?
Of course they should be appliable to every object/GUI/whatnot seperately and not a gamewide default blending mode in general settings.
They are planned to be added to the engine natively? That would be amazing :D

Yeah it would, great plugin...would it be even "faster" once added to the engine natively?
--All that is necessary for evil to triumph is for good men to do nothing.

dbuske

I finally downloaded the newest AGS program. I assume I don't need agsblend.dll. Will I need the extra d3d dlls to get dx9 to work.
What if your blessings come through raindrops
What if your healing comes through tears...

Crimson Wizard

Quote from: dbuske on Mon 17/02/2014 02:51:53
I finally downloaded the newest AGS program. I assume I don't need agsblend.dll.
That depends on how do you use this plugin. Not all of its functions are incorporated into AGS.
For example, alternate blending modes, such as "Blur", "HighPass" etc were not implemented in AGS yet.

Knox

Hi,

Sorry for opening an old thread. I ran into a weird glitch and I also had a few questions regarding this plugin.

The glitch--> Since using 3.3.1 Alpha 1 (with custom resolutions), Ive noticed that using the PutAlpha function, it seems that some sprites get redrawn with semi-transparency in black/dark gray areas, when it should be opaque. Is this a problem with the plugin or 3.3.1 + custom res?

For my 2nd question, are there plans for this plugin to be merged into 3.3.1 with all the filters, Get/PutAlpha, etc?

Thanks!
--All that is necessary for evil to triumph is for good men to do nothing.

xBRANEx



Mehrdad

I had this file in my archive .But I'm not sure for last update. I hope useful for you :
https://www.dropbox.com/s/wgv08ktsjfyxtlw/agsblend.rar?dl=0

cheers
Mehrdad
My official site: http://www.pershaland.com/


eri0o

Hey, sorry for necroing. Has someone experimented with this plugin and FakeScreen? I am looking into it and it appears to work fast enough for 320x180 . Is something I am missing?

SMF spam blocked by CleanTalk