MODULE: DistFX 0.2.0

Started by eri0o, Thu 03/11/2022 23:31:43

Previous topic - Next topic

eri0o

DistFX version 0.2.0

Get Latest Release distfx.scm | GitHub Repo | Project with Demo!

AGS Script Module for Distortion Effects, based on Earthbound Battle Backgrounds.



Play with the demo!

Usage

In a room script, link before fade in and repeatedly execute, and try the example below.

Code: ags
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
Code: ags
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
Code: ags
void DistFX.Reset();
Reset internal state, use on state change.

DistFX.DrawingTransparency
Code: ags
attribute int DistFX.DrawingTransparency;
Drawing Transparency, use for blurring the effects. Default is 0, range from 0 to 99.

DistFX.TileWidth
Code: ags
attribute int DistFX.TileWidth;
Distortion Tile Width, factor of source width, bigger is less resource intensive. Default is 64 pixels.

DistFX.TileHeight
Code: ags
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.

newwaveburritos

Oh, well, this is awesome.

Mehrdad

Brilliant!!! You are amazing @eri0o  8-0
My official site: http://www.pershaland.com/

eri0o

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-)

newwaveburritos

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:

Code: ags
struct DistFX{

Is this an AGS4 thing or am I missing something (probably) obvious?

eri0o

#5
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.

newwaveburritos

That was the problem exactly.  Thanks for your help!

lorenzo

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.

eri0o

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.

lorenzo

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
 

shaun9991

This is very cool! Thanks eri0o!!
Support Cloak and Dagger Games on Patreon: https://www.patreon.com/user?u=460039

glurex

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!

eri0o

Thanks for the great response! If you have any problems using it, please let me know here!  ;-D

eri0o

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

Code: ags
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.

SMF spam blocked by CleanTalk