Heat Distortion

.

1583117--94561--$UnderWater BumpMap.png

Cool! Thanks for sharing

Looks nice :slight_smile:

Kind of like the heat refraction shader basing on NM particles from Unite 2008 … cool :slight_smile:

Thanks for sharing! This is great for underwater distortion. Just drop it on a plane in front of the camera and bam! I changed the range to a float for more precision with the strength.

Hmm… if I turn of AA the texture gets inverted? Is this a DirectX issue?

Yes, I am that person. The attached image shows what your sample package looks like on my mac with Unity 2.6.1f3 Pro.

I have no clue what is wrong there, as I explained in the other thread, other GrabPass shaders seem to work fine.

342167--11978--$odd_141.png

Your shader already explicitly defines the queue as transparent+10. However, just to test, I tried a few other values. Interestingly, as soon as I drop into the geometry queue (Geometry,Geometry+1, …, Geometry+999), the shader starts to partially work. That is, it correctly shows distorted grass in its entire area (with the fire particles rendered (undistorted) on top of it). Other solid geometry, like the walls and the logs are invisible within the spherical area. As soon as the queue hits Geometry+1000 (aka Transparent) it becomes the strange white egg from the picture.

So I guess the render queue is indeed somehow involved, but I still don’t know what is wrong exactly.

I know, but it happens anyway. Something is quite messed up, but I have no idea what.

is thais shader work on unity pro only ?

it can’t work on my secene

http://forum.unity3d.com/threads/83269-Heat-Distortion-shader-can-t-work-in-my-scene-how-can-I-make-it-work

Yes, refraction / haze are always unity pro only
You can easily identify this in the initial posting: GrabPass is Pro only

Old but very interesting water and Heat solutions from forestjohnson:

http://forum.unity3d.com/threads/4285-quot-Sweet-arse-quot-water

NB: it was a project for Unity 2.x so it needs some improvements with 3.4

Thanks for sharing meh11.

I came across this becuase I am looking for some heat distortion for my project.

For some reason everything is flipped in the distortion except during Deffered render mode. Would you know this could be fixed?

Thanks for any help!

Thanks for the reply.

That didn’t fix it but no problem.

FYI, unity 3.3+ has now a proper builtin function for calculating GrabPass coordinates (handles flipping for windows et al):

 float4 grabPassCoords = ComputeGrabScreenPos(o.pos) // o.pos is projected vertex

Hi ole!

Could you show us please, how to use the grabbed texture in screen space on the original position? (like the “render nothing” example)

I’ ve tried the following in a Surface Shader:

	float4 sPos = ComputeGrabScreenPos(IN.screenPos); // o.pos is projected vertex
	float2 uv = sPos.xy / sPos.w;
	o.Albedo = tex2D (_GrabTexture, uv).rgb;

In forward rendering the texture is not flipped anymore, however it is not placed correctly either.
In deferred rendering it is now flipped(and placed elsewhere) where it worked before:

	float2 uv = IN.screenPos.xy / IN.screenPos.w;
	o.Albedo = tex2D (_GrabTexture, uv).rgb;

Maybe I’m doing something wrong?

Thanks!

hello,

pasting a simplified code derived from our glass shader here that should work in all cases (if not it’s a bug) …

struct appdata_t {
	float4 vertex : POSITION;
	float2 texcoord: TEXCOORD0;
};

struct v2f {
	float4 vertex : POSITION;
	float4 uvgrab : TEXCOORD0;
	float2 uvbump : TEXCOORD1;
};

float4 _BumpMap_ST;

v2f vert (appdata_t v)
{
	v2f o;
	o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
	#if UNITY_UV_STARTS_AT_TOP
	float scale = -1.0;
	#else
	float scale = 1.0;
	#endif
	o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
	o.uvgrab.zw = o.vertex.zw;
	o.uvbump = TRANSFORM_TEX( v.texcoord, _BumpMap );
	return o;
}

sampler2D _GrabTexture;
float4 _GrabTexture_TexelSize;
sampler2D _BumpMap;

half4 frag( v2f i ) : COLOR
{
	half2 bump = UnpackNormal(tex2D( _BumpMap, i.uvbump )).rg; 
	float2 offset = bump * 0.1 * _GrabTexture_TexelSize.xy;
	i.uvgrab.xy = offset * i.uvgrab.z + i.uvgrab.xy;
	half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
	return col;
}

remember to use GrabPass {} in a pass before this one and then all you’d need to do is add some animation to the bump lookup (and maybe fade out edges etc.) to get heat haze / distortion.

why i use as your setp…but looks like this …everything … reverse…

But it reduce the frame rate and don’t know the exact reason…

It reduce the frame rate and don’t know the exact reason.

  // check if anti aliasing is used

    //if (_ProjectionParams.x < 0)

       screenPos.y = 1 - screenPos.y;

Just comment out the checking anti-aliasing part, then it will render correctly, but I not sure what kind impact will this bring if we turn on the AA.

–TwisterK