[More Mathematics] Sprite Displacement

Started by Calin Leafshade, Tue 22/06/2010 14:57:41

Previous topic - Next topic

Calin Leafshade

ok how's this for speed:

http://www.thethoughtradar.com/AGS/Distortionbin2.zip

I've dumped the displacement map to an array so it might be quicker.

but i have a feeling it's my multisampled rendering that is causing the slowdown.. I need to crop the reflection sprite somehow (which is currently the size of the whole screen);

GarageGothic

#21
Getting worse fps now, actually - around 22-24. Not sure that the array makes it that much faster (tried it for my voxel game but the performance increase was negligible compared to the drawback of increased room loading time). When you used GetPixel instead of array, did you keep the displacement map DrawingSurface in memory or recreate the DynamicSprite every loop?

Edit: Just looked at your code (next to last version) and I think you could gain some extra frames by not drawing directly to the background but to a smaller sprite displayed as an Object/Character. Also, use the red RGB component instead of blue if the image is grayscale anyway since it requires fewer calculations.

Calin Leafshade

#22
hmm, I've added some things to the code that are probably not very efficient but no matter what I take out I can't get my processor usage to change.. it always sticks around 10%, even if i take out the multisampling (which i thought would be the biggest hit)

heres another slightly optimised version,

http://www.thethoughtradar.com/AGS/Distortionbin3.zip

plus the source if you think you can fix it:

http://www.thethoughtradar.com/AGS/Distortion3src.zip

EDIT: I've tested this on a 10 year old processor and get a full 40fps with only 40% processor load so I dont see why your centrino should struggle GG.

GarageGothic

Calin, I discovered what was going on. Turned out that my laptop power savings mode was limiting the CPU use to 50% even when plugged in. Not sure how long that setting has been active (most other games have worked alright, but I did begin to consider reinstalling Windows). Once I changed the setting to 100% I get a consistent 40FPS in your latest test version. Sorry if I caused you to waste time on unnecessary optimizations. :-[

Dualnames

Also, no trouble here, the whole thing is very smooth. Perhaps adding objects would be a better way to test, unless of course that's the actual room.
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)

SSH

DOes this have perspective distortion on the shadowm, too?
12

Calin Leafshade

not really, no.

In the latest version the distortion sprite is shifted in relation to the characters distance from the centre of the screen (or the horizontal component of the vanishing point.)

I think what i need to do is make a 'map' of nodes and distort that map and then split the character sprite into a series of squares and distort those squares in relation to the map. This should stop the pixelly nature of the reflection but i'm not exactly sure how to distort/stretch a sprite in that way.

Monsieur OUXX

Quote from: Calin Leafshade on Fri 25/06/2010 11:33:46
what i need to do is make a 'map' of nodes and distort that map and then split the character sprite into a series of squares and distort those squares in relation to the map. This should stop the pixelly nature of the reflection.

I don't understand.
 

Calin Leafshade

ok, well:

currently the code samples the colour value beneath the sprite to be distorted and *moves* that pixel according to however much it is to be displaced. Now, because the pixel is just moved it creates two unwanted side effects:

Firstly it creates gaps between pixels. If 1 pixel is move 2 pixels to the left and the next one is moved only 1 pixel to the left then you have a gap between them.
secondly it allows two pixels to be moved to the same spot with the second pixel overlapping the first.

Now, if i created a grid of imaginary points the same size as the sprite and distorted those points I could use the data to cut the sprite into a series of squares (say 2x2 or 3x3) and distort those squares by resizing them by moving their 4 corners and letting the engine interpolate the gaps. Since i resize them in relation to the grid there would be no overlap and no gaps because pixels are not *moved* they are *stretched*

Jim Reed

That sounds like a good idea. You can resize them by the maximum displacememt possible. So if you cap the distortions at 3px max, you can use 3x3 squares for instance.

SMF spam blocked by CleanTalk