[Shader Library] Predator’s Thermal Vision Post Processing Filter (GLSL)

Shader Library - Thermal Vision
How the Predator sees a Qoob mesh



Here is a new post FX shader, that will take place in Geeks3D’s shader library. This shader shows how to implement a Predator-like thermal vision post processing effect in GLSL (the real time shading language of OpenGL).


Download

You can grab the GLSL shader and the GeeXLab demo here:
Download GXL PostFX - Thermal Vision Version 2010.10.29
Left-click to download (right-click disabled)

This demo requires GeeXLab 0.2.7 (for Qoob mesh support) and does not use
Python so you can use the version of GeeXLab without Python.

Unzip the source code somewhere, start GeeXLab and drop the file DEMO.xml in GeeXLab.


Performance: GTX 460 vs HD 6870

And because at Geeks3D we love benchmarks, here are the average FPS of the MSI N460GTX Cyclone 768D5 OC vs ASUS EAH6870:

Testbed:
- CPU: Core i7 960 @ 3.2GHz
- RAM: 4GB DDR3 Corsair Dominator
- Motherboard: GIGABYTE X58-A UD5
- Windows 7 64-bit
- PSU: Corsair AX1200


Avg FPS: 850 – ASUS EAH6870
Avg FPS: 480 – MSI N460GTX Cyclone 768D5

Reminds me my first serious Radeon, the Radeon 9700 PRO, versus the GeForce 4… Radeon cards are rather powerful when we talk about VBO rendering. The main graphics work of this demo is the rendering of the Qoob mesh (made up of 79’874 vertices and 159’744 triangles). And I must say that AMD cards are still very fast when it comes to vertex processing!

Shader Library - Thermal vision PostFX
Thanks to the tweak bar, you can modify in real time the different parameters


The Thermal Vision GLSL Shader

Language: OpenGL 2 – GLSL

Type: Post processing filter.

Inputs

  • sceneTex (sampler2D): the final scene image.

Ouputs: color buffer

Shader code:

[Vertex_Shader]
void main(void)
{
  gl_Position = ftransform();
  gl_TexCoord[0] = gl_MultiTexCoord0;
}
[Pixel_Shader]
uniform sampler2D sceneTex; // 0
uniform float vx_offset;
void main() 
{ 
  vec2 uv = gl_TexCoord[0].xy;
  
  vec3 tc = vec3(1.0, 0.0, 0.0);
  if (uv.x < (vx_offset-0.005))
  {
    vec3 pixcol = texture2D(sceneTex, uv).rgb;
    vec3 colors[3];
    colors[0] = vec3(0.,0.,1.);
    colors[1] = vec3(1.,1.,0.);
    colors[2] = vec3(1.,0.,0.);
    float lum = (pixcol.r+pixcol.g+pixcol.b)/3.;
    int ix = (lum < 0.5)? 0:1;
    tc = mix(colors[ix],colors[ix+1],(lum-float(ix)*0.5)/0.5);
  }
  else if (uv.x>=(vx_offset+0.005))
  {
    tc = texture2D(sceneTex, uv).rgb;
  }
	gl_FragColor = vec4(tc, 1.0);
}

Of course, the thermal vision produced by this shader is not exact (because we would need a way to know the heat at each pixel, via a kind of heatmap) but the effect is cool ;)

To better reflect the human vision, the luminance can be computed with the following code:

float lum = dot(vec3(0.30, 0.59, 0.11), pixcol.rgb);


Credits

This thermal vision shader is a modified version for GeeXLab of Agnius Vasiliauskas‘s original work.




Geeks3D.com

↑ Grab this Headline Animator