Best way to do a wavy sinwave underwater fx

Monkey Forums/Monkey Programming/Best way to do a wavy sinwave underwater fx

Supertino(Posted 2015) [#1]
You know that old snes style underwater wavy sin effects that waves the whole screen, whats the best way to do this so that it works in GLFW and Android?

Thinking I can grab the screen with readpixel, stripe the grabbed image into rows and draw the stripes and apply a sin effect to the parts. I have yet to try this as I am 99% sure this will be too slow to update 30fps. I'll proof it tonight.

Is there a fancy GL command set I can use?


nullterm(Posted 2015) [#2]
readpixel is a dead end, atleast as far as being too slow for 30fps. It'll work, but going back and forth from GPU to main back to GPU memory is going to stall.

If you go the GLES20 route, you can render to a texture, then use that rendered texture using vertex animation (xyz or uv, cheap n fast) or at the pixel shader level (not as cheap/fast on the GPU, but better visual results).

If you are already on the GLES20 route, here's another thread about setting up render textures: http://www.monkey-x.com/Community/posts.php?topic=9270

Edit, if you want to "cheat" and not go the GLES20... IF you don't mind doing it with a static image....

1. draw your scene with mojo
2. use ReadPixels once from the screen to an array
3. use Image.WritePixels to upload the pixel data

Then, (in realtime) something like...

That's per scanline, might be slightly faster to treat every 4 "y" scanlines as a bar and move them together.


Supertino(Posted 2015) [#3]
Thanks nullterm, that's gives me a starting point, I assumed read pixel would be a dead end and some GL stuff would likely be required. I'll look over the link you posted.

If it was a static image I could as you say grab the pixels once and go from there but it's a moving scene with moving objects.


nullterm(Posted 2015) [#4]
Yeah, then the mojo version won't work if it's all moving in real time.

GLES2 render to texture would be the way to go, it's just a bunch of work to setup all the vertex buffers, shaders, etc.

Once you have it working though, there's all kinds of cool effects you can do with "render to texture" and different vertex/pixel shaders.


Nobuyuki(Posted 2015) [#5]
ReadPixels() could be viable provided the screen didn't scroll too much and the background was mostly static. You could apply the strip effect to only the background (this was done in some games in the past). The idea is to reduce the number of ReadPixels() calls as much as possible. Depending on how you assemble the scene, you could also theoretically achieve the effect by slicing and warping each asset before blitting instead of capturing a portion of the screen afterwards and then slicing that. This potentially increases the number of draw calls quite a bit depending on how many lines of accuracy you were going for, however. See the following for an example of the latter:

http://www.monkey-x.com/Community/posts.php?topic=7492&app_id=244


Supertino(Posted 2015) [#6]
That looks nice Nobuyuki ill take a look over that this weekend.