2

I am trying to build a shader that distorts the final image, to be more specific, it makes a wavy effect, kind of like this:

this.

But when the object moves, its "geometry" moves around (think of a distorting mirror).

This

This

is the image I want to apply the distortion.

Now, it doesn't have to be random, it doesn't need to be localized in a specific area. Just a static sine pattern across the whole rendered image is what I am looking for.

When I searched google for this question, the closest I found was this thread. But the OP wants to apply the effect on a texture, which is not what I want. Either way, I tried to use the code, and I got this:

this.

As you can see, the distortion was applied to the texture only and it works as a fixed texture and not to the scene as a whole. If I move the cube, the distortion acts as a texture, and move with the cube. Not really like a distorting mirror.

I also found out that I can't change the coordinates of the pixel on the fragment shader, for example, make that the pixel where the cube is, be more on the top, or more on the bottom (like the sine curve). The fragment shader just chooses the color where the fragment was rasterized.

So, is it even possible to do this kind of effect with GLSL shaders? If so, how?

Scheff's Cat
  • 19,528
  • 6
  • 28
  • 56
Hirosam
  • 111
  • 7
  • 4
    You need two rendering passes. The first renders your scene into a frame buffer which is bound to a texture. The second gets the texture as uniform and renders the post-effect you want to achieve to the default frame buffer. Whereby, you might achieve the intended effects just by the appropriate look-up and mapping of a texel for the current pixel in fragment shader. Tutorial: [Framebuffers](https://learnopengl.com/Advanced-OpenGL/Framebuffers) – Scheff's Cat Nov 05 '19 at 06:45
  • 1
    yep two pass is the way... – Spektre Nov 05 '19 at 07:48
  • @Scheff, awesome, thanks! I will take a look :) – Hirosam Nov 05 '19 at 16:45

0 Answers0