Would it be possible for a plugin to be written that allows screen buffer distortion?
Have a look at this effect done in Adobe After Effects:
Displacement:
(http://www.shuugouteki.net/paul/Images/displacement.gif)
Result:
(http://www.shuugouteki.net/paul/Images/underwater.gif)
Is this possible in AGS?
Cheers,
Sparx.
I'd say it's absolutely possible with a plugin, but some work would be required.
Actually, I think it is even possible without a plugin. Just grab a dynamic of the whole screen and do whatever modification you want to it. It may be quite slow though.
I wrote a module (not yet released to the public) that allows you to turn Objects into "EffectObjects" that can work as lenses, mirrors and/or just provide distortion of whatever background/object/character is behind it. For a water distortion effect similar to what you describe it uses simple sine functions performed on columns and/or rows of pixels. Using a graphical displacement map would make it much, much slower as you would need to call GetPixel on every pixel of the displacement map. As is, it's still pretty tough on the CPU, but keeps decent framerates as long as you don't use too many or too large effect objects in the same scene.
For full-screen manipulation a plugin would be preferable, and absolutely necessary if you want to use displacement maps. I don't think it should be too difficult to code, but I don't have any real experience with plugins as I prefer using modules.
Would anyone be up for the challenge? It would be really cool to see some games made with real-time distortion effects such as the ones described. You could even do forcefields or shockwaves! 8)
Cheers,
Sparx.
i'm no expert on the subject but what with the DirectX engine couldn't this sort of stuff be done if shader support was implemented?
Thats kind of what I'm thinking. But something that could be run (in theory) on the PC equivilant of a PSP Processor.
Cheers,
Sparx. :)
If someone manages to write anything to do that effect we will have all AGS games under-water!!
QuoteIf someone manages to write anything to do that effect we will have all AGS games under-water!!
Or with cool room to room transitions! ;D
Sparx.
One thing I really could see this being used for, is heat waves. Like in Final Fantasy 3 where you fight in the desert with the heat waves in the background.
I love the idea of having this effect.
I could probably do a simple version of this (with hack programming of course--nothing but. :P), but definitely nothing like you've shown here. Especially with the displacement background.
Rather than me explaining how I would attempt to do this the overcomplicated way, I'll just show a picture.
(http://www.bryvis.com/images/other/agsf/distorteffect.png)
I would place a bunch x and y coords on the screen (Green), connect them all in the form of a triangle (incomplete demonstration pic above), and have the x and y coords randomly move around +/- 1 or 2 pixels on both x and y randomly. But never letting them break the triangle by going through itself. Then I'd check each pixel in the VERY first background (always keeping a fresh copy of this background for reference) and align them to their knew mathematical location in the new triangle. Wouldn't be too, too, hard but I bet AGS would hate it and your computer would as well.
Oh, and you'd have to keep a radius limit as to where the x+y coords could move and not beyond (you'd have to keep the x and y coords from the original triangle location to where it is now). Otherwise the effect would literally walk off the screen.
What you'd do with the 'stretched' pixel I wouldn't have a clue. And that is what would make the background look like poo. :P
Hey thats a pretty neat approximation! Good going Ryan. Does your method work or are you still testing it?
Good suggestion Ryan. Heatwaves are also very appropriate for screen displacement effects.
Also you could import the full-screen displacenment frames as an 8 bit grayscale 32 color set of sprites and add them into a looping view.
The image compression would certainly free up some more resources maybe even relax the proccessor a bit too?
Cheers,
Sparx.
Nah it was just an Idea of How I would do this myself. I only slapped some lines on your pic to give a visual explanation on how I'd do this, IF I were to attempt it.
It definitely wouldn't look as good as your Adobe effect, but I think it would still pass as water/heat etc just as long as the triangles didn't stretch or shrink too much.
Well we can always animated backgrounds and have custom displacement loops for characters. But a plugin that allows dynamic solution would be extremely beneficial.
Cheers,
Sparx.
Still I think Radiant, is definetely a coding beast concerning raw draw cool effects..ask him..or make him do it ;D
Radiant? You about buddy? I'd like to get your thoughts on such a plugin.
Cheers,
Sparx.
Well, thing is if it can be done internally with AGS Engine, I could definetely give it a shot. But concerning plugins, well I couldn't. I think the plugin is definetely something that would help AGS engine benefit.
As for the displacement, wondering does the displacement affect the characters, it should.
It should be done using Rawdraw taking input from Screenshot. However, what my concern and main difficult and obstacle as how to code is, what exactly does displacement do? Takes parts of the screen and moves them? Cause if it's that(as a main idea), it is definetely possible AGS internally.
Dualnames: It's definitely possible to do in-engine (see my previous post), and quite easy scripting wise. Only horribly slow to do full-screen - and even worse when using Direct3D mode. Even grabbing a single screenshot to DynamicSprite causes my framerate to stutter in Direct3D mode, I couldn't imagine at what pace the game would run if doing it every loop.
The most realistic solution would be to use pre-rendered animation frames for the distorted background, either done in an external application such as AfterEffects or dynamically generated upon room entry and only apply real-time distortion to the characters/objects. I should be able to add character support to my effect module if enough people are truly interested.
Let's say one would create five distorted images upon entering the room, and store these as the five possible cycling backgrounds- it wouldn't be as fluid an animation, but should save processor power. I like the general idea of a distortion plugin very much, but I see Dualnames point- it's eye candy that's easy to overuse.
I'll give it a shot..and if it succeeds at any point, I'll give it out. As for Ghost's words, well, yes it could get misused, but that happens with most of the cool things, even SSH star wars scroller can easily achieve the same effect. Just see how many games have Star Wars scrolling text effect.
Quote from: GarageGothic on Fri 21/11/2008 14:13:38
[..]Even grabbing a single screenshot to DynamicSprite causes my framerate to stutter in Direct3D mode, I couldn't imagine at what pace the game would run if doing it every loop.[..]
I don't understand why you'd need to take a screenshot between each frame. Explain this to me if you will.
I'm not too advanced with AGS yet, so I there may be limitations I'm not aware of yet. But I know how I'd do it in a program like Turbo Pascal, and it's very similar to how I'd do it in AGS.
Well, if you want to distort the full screen as in subspark's example, you need a DynamicSprite copy of the current screen (including objects and characters at their current position, with their current animation frame and current lighting) to then distort. Arguably you only need to grab the screen when something has changed, but since there's no easy way to determine when this has happened, we do it every frame.
Creating a DynamicSprite from a screenshot rather than just creating it from the background is much slower in Direct3D mode as the data must be read back from the video card's memory rather than system RAM. For this reason, instead of grabbing a screenshot to DynamicSprite, my EffectModule replicates the area behind the object in question by grabbing part of the background and then cycling through all the characters and objects in the room, checking if they're overlapping the object and if so, sizing and tinting their graphics to match the actual objects/characters) using DynamicSprite functions and then drawing them in baseline order to the background sprite. This method improves the speed considerably compared to using a screenshot, but I think it could cause quite a slowdown if used full-screen in a room with more than one or two characters and a few objects.
This is also why I suggest pre-distorting the background graphics (storing the frames as DynamicSprites you could have much more than 5 animation frames, though you would probably have to delete and then re-render the frames when saving/restoring to avoid 20+ MB savegame files). Running the realtime distortion only on characters should allow decent framerates.
There's been some great responses from everybody here. It's nice to see everybody experimenting either in their heads or in practice.
QuoteIt's eye candy that's easy to overuse.
Sure. But the same could be said for laser guns in movies or the fade transitions that Chris implemented into the modern AGS. ;)
"Something great is always remade because it is great and doesn't perish upon birth." I forget which philosopher said that.
Cheers,
Sparx.
QuoteIt's eye candy that's easy to overuse.
So are lens flares, but everybody knows that you shouldn't use them. If they try to, it's immediately shot down once it reaches the CL, GiP, or Database.
And I'd like to add that I'd love to see it, even though I wouldn't use it (anytime soon at least)
~Trent
Thanks for that. :P
Hmm, then let me rephrase: It's easy to overuse, and thus, it should be highly customizeable.
That's what I really had in mind, sorry if it came over the wrong way.
Not at all, I got what you meant. And I meant that if it does become a trend, it will control itself through the forums mentioned.
~Trent
Since the subject of this thread was so misleading in a way that made people think such a plugin has been made, I have decided to change it to something more reasonable. :P
Thanks Gilbet. Somehow I lost my question mark when I added [Cool Example Included] next to the original subject.
Cheers,
Sparx.