Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: Calin Leafshade on Sun 01/08/2010 17:44:21

Title: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Calin Leafshade on Sun 01/08/2010 17:44:21
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


Title: Re: Plugin - AGSBlend. Real Alpha Blending and Alpha Channel Manipulation
Post by: GarageGothic on Sun 01/08/2010 18:03:06
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!
Title: Re: Plugin - AGSBlend. Real Alpha Blending and Alpha Channel Manipulation
Post by: hedgefield on Mon 02/08/2010 18:50:43
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!
Title: Re: Plugin - AGSBlend. Real Alpha Blending and Alpha Channel Manipulation
Post by: Calin Leafshade on Mon 02/08/2010 19:18:29
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.
Title: Re: Plugin - AGSBlend. Real Alpha Blending and Alpha Channel Manipulation
Post by: Crimson Wizard on Mon 02/08/2010 19:20:49
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.
Title: Re: Plugin - AGSBlend. Real Alpha Blending and Alpha Channel Manipulation
Post by: deltamatrix on Tue 03/08/2010 21:08:26
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)
Title: Re: Plugin - AGSBlend. Real Alpha Blending and Alpha Channel Manipulation
Post by: Calin Leafshade on Tue 03/08/2010 21:44:21
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.
Title: Re: Plugin - AGSBlend. Real Alpha Blending and Alpha Channel Manipulation
Post by: Knox on Thu 12/08/2010 23:04:53
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 :)
Title: Re: Plugin - AGSBlend. Real Alpha Blending and Alpha Channel Manipulation
Post by: Calin Leafshade on Fri 13/08/2010 06:20:42
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.
Title: Re: PLUGIN: AGSBlend. Real Alpha Blending and Alpha Channel Manipulation
Post by: Knox on Sat 08/01/2011 18:07:13
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.
Title: Re: PLUGIN: AGSBlend. Real Alpha Blending and Alpha Channel Manipulation
Post by: Calin Leafshade on Sat 08/01/2011 22:47:26
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.
Title: Re: PLUGIN: AGSBlend. Real Alpha Blending and Alpha Channel Manipulation
Post by: Knox on Sun 09/01/2011 01:02:16
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.
Title: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Calin Leafshade on Sun 09/01/2011 13:30:43
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)

Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Dualnames on Sun 09/01/2011 18:33:36
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.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Calin Leafshade on Sun 09/01/2011 19:20:54
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.

Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Knox on Sun 09/01/2011 20:51:44
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.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: dbuske on Sat 15/01/2011 20:58:23
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.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Calin Leafshade on Sat 15/01/2011 21:46:49
Editor version will not affect it and it works fine for me.

Which dll does it say is missing?
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: dbuske on Sun 16/01/2011 00:19:11
Sorry, for some reason it works now.  Murphy's law just to make me a liar.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Monsieur OUXX on Mon 14/02/2011 15:39:13
- 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.

Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Calin Leafshade on Mon 14/02/2011 15:59:45
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.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Monsieur OUXX on Mon 14/02/2011 16:33:21
Thank you Sir
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Construed on Wed 16/02/2011 06:30:45
Could this added functionality perhaps enable me to draw one sprite to another at a specified location on the sprite?
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Calin Leafshade on Wed 16/02/2011 11:50:20
Thats kinda what it's for yea.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Construed on Wed 16/02/2011 12:04:49
Nice, just what i was looking for!
Thanks.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Construed on Wed 16/02/2011 12:43:41
Any idea why the draw is coming out splintered like this?
(http://i1190.photobucket.com/albums/z454/grimreapyou/NewBitmapImage-2.jpg)
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Calin Leafshade on Wed 16/02/2011 14:48:39
Not without seeing the code.

But remember this only works for *32bit* sprites.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Construed on Wed 16/02/2011 18:56:45
Ah, ok.

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

Thanks- Jar
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Construed on Wed 16/02/2011 19:41:40
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?
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Ryan Timothy B on Sat 02/07/2011 01:50:35
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.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Calin Leafshade on Sat 02/07/2011 07:37:12
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.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Ryan Timothy B on Sat 02/07/2011 18:34:33
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.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Knox on Wed 31/08/2011 18:30:54
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.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Calin Leafshade on Thu 01/09/2011 13:53:27
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.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Monsieur OUXX on Mon 02/12/2013 15:42:42
Download link broken. anybody has it?
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Crimson Wizard on Mon 02/12/2013 16:57:51
We have a version with few portability fixes in ags repository: https://github.com/adventuregamestudio/ags/tree/master/Plugins/agsblend
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Calin Leafshade on Mon 02/12/2013 20:15:59
The plugin has been rendered obsolete by the latest version of AGS.

Except the Blur and Highpass functions maybe.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Crimson Wizard on Mon 02/12/2013 21:18:42
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).
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Calin Leafshade on Mon 02/12/2013 21:29:40
That's true I suppose. I never really considered those useful.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: 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.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: 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
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: dbuske on Tue 03/12/2013 13:15:29
Looks like the thought radar site was hijacked.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Calin Leafshade on Tue 03/12/2013 16:56:59
Nah, I just let it expire.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Knox on Tue 03/12/2013 17:33:19
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?
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: dbuske on Mon 17/02/2014 02:51:53
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.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Crimson Wizard on Mon 17/02/2014 07:30:10
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.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Knox on Wed 02/07/2014 17:57:11
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!
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: xBRANEx on Mon 05/06/2017 20:02:25
Does anyone have a working link for this?
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Mehrdad on Tue 06/06/2017 05:53:34
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
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: Crimson Wizard on Tue 06/06/2017 13:42:24
As stated in this thread before, this plugin is open source.
https://github.com/adventuregamestudio/ags/tree/master/Plugins/agsblend

Someone could just rebuild it.
Title: Re: PLUGIN: AGSBlend. AGS Graphic Library - Source Available
Post by: eri0o on Thu 14/06/2018 12:49:02
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?