BGE GLSL Shader save texture

Hi i’m working to generate real time ocean surface through ocean spectrum in BGE, the code to generate the spectrum is ready, now the only thing to do is an inverse FFT to obtain height field. I don’t know how to performe it in GLSL, the only solution is to save the texture and do the transform in python. is there any way to save a texture from glsl?

this is the ocean spectrum. now i have to save it in a texture.

Yes, but it’s slow and I wouldn’t suggest trying to use it in any sort of real-time sense.

You create a Render To Texture (bge.texture.ImageRender) with a camera that points at the plane with your shader on it, and then you can extract the image data from that.
The issue is that it is really, really slow to get the data from the GPU to the CPU. So what I would suggest is to try keep it all in the GPU. Either compute the heightfield in the same shader (you may have to multi-sample) or use ImageRender, but instead of extracting the data back to the CPU, use it as a texture input to another shader.

I will try thanks

Oooh a water shader! : D

I definitely have to second sdfgeoff’s suggestion, do as much as you can (everything if possible) on the GPU.

My math and blender GLSL are a bit rusty, but I’ll gladly help where I can ^___^

Looking forward to future updates : D

Thanks john. I’m studyin how to perform FFT in a shader. The steps to achieve this project are:

  • List item compute the spectrum of the ocean
  • List item get the heigth field from the spectrum through an inverse Fast Fourier Transform
  • List item then apply the heigth field to a plane

I’ve alredy done a test in python with numpy and matplot lib and it worked. But it’s very slow becaise i have to calculate all frames and then make a video.

My inspiration is martins upitis. But as aleays he is unbelievable and i can’t reach him but i’m trying with all i have to improve.