2

I am working on a small 2d game where my wizards casts a spell I want to create an effect where the world warps as if the spell is bending Light much like hot air around a fire would. Right now I have a vertex shader warping the points of the rectangles I use to draw the world. There are two problems. The first is that there are not enough polygons in my simple 2d game for this to work seemlessly. The second is that my terrain is composed of hex tiles like a hex grid. Because the 4 points rectangle polygons do not represent where the 6 points of the hex grid join together, the warping of polygons causes the world to break apart and gaps appear below. Now I can change the world to use 6 points hex polygons instead of rectangles with hex textures but that would be out of scope.

Would it be possible to render my world somewhere offscreen then grab the offscreen frame as a texture then render it again with a higher polygon count? At that point I would use my warp vertex shader.

Also is there another way to do this?

genpfault
  • 51,148
  • 11
  • 85
  • 139
SpecialEd
  • 473
  • 5
  • 17

1 Answers1

2

You want to do this as a post processing effect in the pixel shader. Take your previous render target then use it as input for this post processing effect.

Guide for Rendering to Texture http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/

Fire does refraction but i'd learn from code about this swirling and modify it to effect the screen more like how you want it too. Doing refraction is a bit more difficult, but you can emulate it with the ideas within here and manipulating how you sample the uv's with noise.

http://www.geeks3d.com/20110428/shader-library-swirl-post-processing-filter-in-glsl/

This should get you pointed some what in the right direction.

Chase R Lewis
  • 2,119
  • 1
  • 22
  • 47
  • Thanks for the response I will investigate the links given and will update the answer when I get a chance to try this out. Unfortunately it’s just a personal project so not sure when I get a chance to try it out. – SpecialEd Oct 25 '17 at 22:13