GLSL Desert Mirage/Heat Wave Effect

Here is another GLSL code sample from my project. This one was fairly easy after they gave us the formula to use. Here is the code and image of the results.

Vert Shader

uniform sampler2D my_color_texture;
uniform float time;
varying vec2 texc;

void main()
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  texc = vec2(gl_MultiTexCoord0);

Frag Shader

varying vec2 texc;
uniform sampler2D my_color_texture;
uniform float time;

const float A = 0.03;
const float B = 200.0;
const float C = 5.0;

const float D = 0.003;
const float E = 13.0;
const float F = 9.0;
float x;
float y;

void main()
  gl_FragColor =  texture2D(my_color_texture, texc);
  gl_FragColor.a = 1.0; //Best to make sure nothing seems transparent
  float x =  A * sin(B * texc.x) * sin(C * time);
  float y =  D * sin(E * texc.y) * sin(F * time);
  vec2 c = vec2(texc.x + x, texc.y +y);
  vec4 diffuse_color =  texture2D(my_color_texture, c);
  gl_FragColor = diffuse_color;

Mess with the variables to get different affects.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Graveyard Database Logo

Has everything you want to know about grave yards. Plus has many celebrites and world leaders graves. Pssst it is my other site

Google + Profile
Check out Android Photo Mapping, its a app/site I been working on
Fabulou wholesale Petr Mrazek jersey is back. Best choice to get the wholesale Petr Mrazek jersey is suitable for all style of people.