DistFX version 0.2.0
Get Latest Release distfx.scm (https://github.com/ericoporto/distfx/releases/download/0.2.0/distfx.scm) | GitHub Repo (https://github.com/ericoporto/distfx) | Project with Demo! (https://github.com/ericoporto/distfx/releases/download/0.2.0/distfx_demo.zip)
AGS Script Module for Distortion Effects, based on Earthbound Battle Backgrounds.
(https://user-images.githubusercontent.com/2244442/199853408-98184522-5c9c-4426-ad4f-34b698cc86ab.gif) (https://ericoporto.github.io/distfx/)
Play with the demo! (https://ericoporto.github.io/distfx/)
Usage
In a room script, link before fade in and repeatedly execute, and try the example below.
DistFX fx; // somewhere with the same lifetime as the surface owner while distorted
Overlay* ovr;
DynamicSprite* spr;
function room_RepExec()
{
fx.Update(Room.GetDrawingSurfaceForBackground(), spr.GetDrawingSurface(), 2 /* effect */);
ovr.Graphic = spr.Graphic;
}
function room_Load()
{
if(ovr == null) {
spr = DynamicSprite.CreateFromBackground();
ovr = Overlay.CreateGraphical(0, 0, spr.Graphic, true);
}
}
Original Earthbound effects used a per pixel approach, but due to how AGS Script drawing performs and works, this module uses a tile based approach.
Script API
DistFX.Update
void DistFX.Update(DrawingSurface* source, DrawingSurface* dest, int effect);
Draws from a source surface to a destination surface using a distortion effect, from the effect bank. Currently, the available effects range is 1-135. Effect 0 appears as no effect but still goes through all the effect pipeline - and will use CPU resources the same.
DistFX.Reset
void DistFX.Reset();
Reset internal state, use on state change.
DistFX.DrawingTransparency
attribute int DistFX.DrawingTransparency;
Drawing Transparency, use for blurring the effects. Default is 0, range from 0 to 99.
DistFX.TileWidth
attribute int DistFX.TileWidth;
Distortion Tile Width, factor of source width, bigger is less resource intensive. Default is 64 pixels.
DistFX.TileHeight
attribute int DistFX.TileHeight;
Distortion Tile Height, factor of source height, bigger is less resource intensive. Default is 1 pixel.
License
This code is licensed with MIT LICENSE (https://github.com/ericoporto/distfx/blob/main/LICENSE).
Oh, well, this is awesome.
Brilliant!!! You are amazing
@eri0o 8-0
Thanks
@Mehrdad and
@newwaveburritos ! This one is more useful for low resolution games - or if you just want to effect a smaller area, say a TV screen in BG, a part that is underwater, or random abstract stuff.
I have some stuff I had sketched in the past and abandoned before releasing, and plan to revisit and see what I can finish. 8-)
This is maybe a dumb question but I'm having trouble getting this to work. I can run the demo just fine in AGS4 but when I move the scripts over into another project it doesn't seem to like it. I just made a new script and copied the body of the DistFX script and header over then added the other part of the code to the Room 1 script but when I try to compile I get:
Failed to save room room1.crm; details below
DistortionFX.ash(16): The struct 'DistFX' extends 'DistFX', and 'DistFX::get_DrawingTransparency' is already defined. See line 5
Line 5 is the header:
struct DistFX{
Is this an AGS4 thing or am I missing something (probably) obvious?
First, the scm is the way to import in a new project. Second, I have not tested it with the new compiler, maybe it doesn't need the individual get_ and set_ additional import qualifiers. Open the header and comment the two lines with get_ and set_ below each attribute definition, does doing so works?
I have only tested this and all my modules in 3.6.0.X, my guess is things are different in AGS4 and will possibly break there - same for all my modules.
That was the problem exactly. Thanks for your help!
Eri0o as usual creating things that I would've never thought possible in AGS! :cheesy:
The effects are fantastic, I wonder if they would work at higher resolutions.
Thanks
@lorenzo ! ;)
Quote from: lorenzo on Sat 05/11/2022 08:48:14I wonder if they would work at higher resolutions.
Probably not on the whole screen, but it may be useful for smaller things. If you do try something bigger, I would suggest experimenting with bigger sizes of TileWidth and TileHeight, and see if doesn't screw the effects too much. Usually you need a bigger width than you need a bigger height.
Quote from: eri0o on Sun 06/11/2022 22:45:44. If you do try something bigger, I would suggest experimenting with bigger sizes of TileWidth and TileHeight, and see if doesn't screw the effects too much.
Thank you for the suggestion, I'll give it a try!
Can't wait to fill my games with broken TVs and dream sequences, just to use these effects! :D
This is very cool! Thanks eri0o!!
Quote from: lorenzo on Wed 09/11/2022 13:50:06Can't wait to fill my games with broken TVs
I was thinking the same! I have two games in "production", and the first one involves tv's.
Thanks Eri0o!
Thanks for the great response! If you have any problems using it, please let me know here! ;-D
Added a new version 0.2.0
This version should work with AGS 3.5.1 release too! If you are running the example usage code, in AGS 3.5.1 Overlays can't have the graphic property written to, so the code for that usage would be
DistFX fx; // somewhere with the same lifetime as the output surface while distorted
Overlay* ovr;
DynamicSprite* spr;
function room_RepExec()
{
fx.Update(Room.GetDrawingSurfaceForBackground(), spr.GetDrawingSurface(), 2 /* effect */);
if(ovr != null) {
ovr.Remove();
ovr = null;
}
ovr = Overlay.CreateGraphical(0, 0, spr.Graphic, true);
}
function room_Load()
{
if(ovr == null) {
spr = DynamicSprite.CreateFromBackground();
ovr = Overlay.CreateGraphical(0, 0, spr.Graphic, true);
}
}
Beyond this, there is no significant change in code.