Heat haze/Steath field redone

I’ve hacked together a simpler version of a heat haze/stealth field filter.
It has a very simple setup, all you need to do is hide some geometry from the main camera, override a shader input for it (np.setShaderInput(“mask”, 0.0)), an optional masking texture can be used if needed and that’s about it.
Screen:

Code:
[in the attachment]

EDIT:
If you want the distortion not to affect things in front of it (more or less), use this shader as ‘normals.cg’:

//Cg

void vshader(in float4 vtx_position : POSITION,            
             in float4 vtx_normal : NORMAL,
             in float4 vtx_texcoord0 : TEXCOORD0, 
             out float4 l_position : POSITION,
             out float4 l_color0 : COLOR0,
             out float3 l_normal : TEXCOORD0,
             out float4 l_texcoord : TEXCOORD1,
             uniform float4x4 itp_modelview,
             uniform float4x4 mat_modelproj)
{
  l_position = mul(mat_modelproj, vtx_position);
  l_normal = normalize(mul(itp_modelview, vtx_normal));
  l_texcoord = vtx_texcoord0;
}
 
void fshader(float4 l_color0 : COLOR0,
             float3 l_normal : TEXCOORD0,
             float3 l_texcoord : TEXCOORD1,
             uniform float mask,
             uniform float useMap,
             uniform sampler2D tex_0,
             out float4 o_color : COLOR)
{
  float4 map = tex2D(tex_0, l_texcoord.xy);  
  if (mask>0.9)      
    o_color=float4(0.0, 0.0, 0.0, map.a); 
  else  
    o_color=float4(l_normal, 1.0-map.r*useMap);
}

demo.zip (1.99 MB)

You not use depth comparison, it can cause side effect: objects in front of “stealth” also distorted.

I noticed that after I posted it, rendering all the non distorting objects black should fix it(more or less - some pixels on the edges can still be wrong) but is this faster then rendering the depth for both cameras? I wouldn’t think so.

It did take me about 45 minutes to make, and 30 minutes of that was making the fire volume model, so don’t expect it to be flawless :]

I’ve got very strange result with edited normals.cg. Can’t show behaviour on screen. It looks like broken digital TV signal. Possible I do something wrong (I can’t fully understand how it should work), or may be It again problem with my videodriver.

Can’t reproduce the bug on my end, but I modified it to use depth maps, and adjusted the shader a bit to make the effect a bit more subtle. I won’t post a screenshot because it’s hard to see the effect on a static image

Code:
demo2.zip (1.99 MB)

Oh, ok, it’s much better in my opinion. Thanks ) I’ll add link on this thread if you do not mind.

Sure, use it as you like it
It’s CC0 or MIT or BSD or WTF-GPL or whatever your original code was :wink: