Thursday, October 21, 2010

Thermal vision pixel shader

This is how we can get thermal vision pixel shader:
1. Make some gradient (here we will use blue-yellow-red gradient).
2. Make thermal map texture (here we will substitute pixel luminance value for temperature)
3. Get pixel's temperature from thermal map texture and map it to gradient value.

GLSL code



#version 120

uniform sampler2D tex;

void main()
{
vec4 pixcol = texture2D(tex, gl_TexCoord[0].xy);
vec4 colors[3];
colors[0] = vec4(0.,0.,1.,1.);
colors[1] = vec4(1.,1.,0.,1.);
colors[2] = vec4(1.,0.,0.,1.);
float lum = (pixcol.r+pixcol.g+pixcol.b)/3.;
int ix = (lum < 0.5)? 0:1;
vec4 thermal = mix(colors[ix],colors[ix+1],(lum-float(ix)*0.5)/0.5);
gl_FragColor = thermal;
}



Tank

and after thermal vision shader applied:

1 comment:

  1. Very good code.

    Would it be difficult to make a convert of this code to Adobe Pixel Bender?

    Thank you

    ReplyDelete

Comment will be posted after comment moderation.
Thank you for your appreciation.