Heat vision 2d filter

Predator style heat vision for the BGE.


It’s not real heat vision, you have to add a lamp to illuminate the scene when you turn it on if the scene is dark, but it simulates the heat map style coloration of thermographic vision. You can combine it with other filters such as noise or blur to get a more interesting effect. I tried using depthTexture to get a true “seeing in the dark” type filter but the depth texture doesn’t pick up textures, transparent objects etc… so it wasn’t a good effect.

here’s the GLSL code:

uniform sampler2D bgl_RenderedTexture;

const float vignette_size = 0.4;
const float tolerance = 0.2;


void main(void)
{           
    vec4 col_value = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st);
    
    float col_avg = (col_value[0] + col_value[1] + col_value[2]) * 0.333;
                            
    float ratio = 2.0 * col_avg;
    float b = max(0.0, (1.0 - ratio));
    float r = max(0.0, (ratio - 1.0));
    float g = 1.0 - r - b;
 
    vec4 color_vision = vec4(r,g,b,1.0);
 
    vec2 deltaTexCoord = gl_TexCoord[0].st - vec2(0.5);
    vec2 powers = pow(deltaTexCoord,2.0);   
        
    float radiusSqrd = pow(vignette_size,2.0);    
    float gradient = smoothstep(radiusSqrd-tolerance, radiusSqrd+tolerance, powers.x+powers.y*0.3);

    gl_FragColor = mix(color_vision, vec4(1.0,0.0,0.0,1.0), gradient);
    gl_FragColor.a = 1.0;
    

}



Thanks to Martinsh for his old 2d shaders set which included vignette and other cool stuff which I’ve adapted to my needs here.

Pretty good! thanks for sharing :slight_smile:


Cool! Great job!

You can change the size of the vignette (red outer edge) effect by adjusting:

const float vignette_size = 0.4;
const float tolerance = 0.2;

Vignette_size makes the area smaller or bigger (-/+) and tolerance makes the edge of the circle harder or softer (-/+).
Have fun! :slight_smile:

Doesn’t seem to work in 2.75. :frowning:

please make it work for 2.75. I need something like this for my horror game.

Sent from my ASUS_T00I using Tapatalk

You could try to get emission of material(including if you use textures for it) and set heat basing on it. Also, if possible, heat X-ray.

Hi all, I used it just yesterday in 2.75 and it worked fine. It must be a graphics card issue…
I’m not sure how I fixed that last time but you could try putting an f in front of all the floats, so for example f0.3 instead of 0.3

This one also requires a light, actually most will. The one adriansnetlis posted can amplify small amounts of light though, so if you add a lamp with a very low energy setting like 0.05 it will work with the filter but the scene will look dark. You can increase the effect by setting the strength to 5.0 or even 15.0 if you have a very dark scene.

I’ve got another one I may post tonight but again it could have trouble with AMD cards…

Well, I’m saying that there’s no effect with this. Like, not even the vignette.

The one adriansnetlis posted can amplify small amounts of light though, so if you add a lamp with a very low energy setting like 0.05 it will work with the filter but the scene will look dark. You can increase the effect by setting the strength to 5.0 or even 15.0 if you have a very dark scene.

I did not know it did that. Thank you.

I’m just wondering why I don’t get any effect with this. It must be my graphics card.

If you check the console it should tell you which line is causing the error. Then tell me and I can try to fix it.

How do I check the console with a 2D filter?

EDIT: Scratch that, figured it out.

Fragment shader failed to compile with the following errors:
ERROR: 0:21: error(#202) No matching overloaded function found: pow
ERROR: error(#273) 1 compilation errors.  No code generated


Seems to be fixed by replacing

vec2 powers = pow(deltaTexCoord,2.0);

with

vec2 powers = (deltaTexCoord,2.0);

but then all I get is this:

EDIT:
Try;
pow(vec2 deltatexcoord, vec2(2.0))
That controls the size of the non red area so in your version it’s nearly 100% red.
Pow should compare two items of the same type. This part is lifted from one of martinsh’s old shader examples so I’m not sure about the fix.

What do I replace with that, though? If I replace

vec2 powers = pow(deltaTexCoord,2.0);

with it, I’m back to square one: it not working at all.

EDIT: Fixed it! Replaced with

    vec2 deltaTexCoord = gl_TexCoord[0].st - vec2(0.5);
    
    float power1 = pow(deltaTexCoord.x,2.0);
    float power2 = pow(deltaTexCoord.y,2.0);
    vec2 powers = vec2(power1, power2);  

I actually got quit a fun heat xray style shader by switching character meshes with a rigged skeleton, the skeleton model had the z buffer offset to 70 or something like that so it always rendered over other background objects.

Why am I thinking of sonar from Splinter Cell Blacklist?

[video]https://youtu.be/nXh9f0fN614?t=232[/video]

It looks like a feature used in a lot of games that usually is called extra vision or eagle vision or focus etc. Usually it affects object shaders, however, I don’t know if blender can remove GLSL shaders.


for obj in bge.logic.getCurrentScene().objects:
    if "enemy" in obj:
        redEmitShaderThingy(obj) #execute function that's first line looks like def redEmitShaderThingy(obj)
                                               #and there is full shader code in it later that I can't tell you now
    else:
        blueEmitShaderThingy(obj)

That’s a cool effect!