The best I could come up with is the below, but the distortion doesn’t seam as good as it should be. Any thoughts or suggestions?
Shader "Custom/Particles/Refraction" {
Properties {
_TintColor ( "Tint Color", Color ) = ( 0.5, 0.5, 0.5, 0.5 )
_MainTex ( "Particle Texture", 2D ) = "white" {}
_BumpMap ( "Normal", 2D ) = "bump" {}
_BumpAmt ( "Distortion", range ( 0, 128 ) ) = 10
}
Category {
Tags { "Queue"="Transparent" "RenderType"="Opaque" }
Blend One OneMinusSrcAlpha
SubShader {
GrabPass {
Name "BASE"
Tags { "LightMode" = "Always" }
}
Pass {
Name "BASE"
Tags { "LightMode" = "Always" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_particles
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord: TEXCOORD0;
};
struct v2f {
float4 vertex : POSITION;
float4 uvgrab : TEXCOORD0;
float2 uvbump : TEXCOORD1;
float2 uvmain : TEXCOORD2;
};
float _BumpAmt;
float4 _BumpMap_ST;
float4 _MainTex_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 );
o.uvmain = TRANSFORM_TEX( v.texcoord, _MainTex );
return o;
}
sampler2D _GrabTexture;
float4 _GrabTexture_TexelSize;
sampler2D _BumpMap;
sampler2D _MainTex;
fixed4 _TintColor;
half4 frag( v2f i ) : COLOR {
half2 bump = UnpackNormal( tex2D( _BumpMap, i.uvbump ) ).rg;
float2 offset = bump * _BumpAmt * _GrabTexture_TexelSize.xy;
i.uvgrab.xy = offset * i.uvgrab.z + i.uvgrab.xy;
half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD( i.uvgrab ) );
col.a = 0;
return col * _TintColor * tex2D( _MainTex, i.uvmain );
}
ENDCG
}
}
SubShader {
Blend DstColor Zero
Pass {
Name "BASE"
SetTexture [_MainTex] { combine texture }
}
}
}
}