Advertisement
Guest User

Untitled

a guest
May 28th, 2018
1,821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. Shader "Phigames/Mesh Distortion" {
  2.  
  3. Properties {
  4. _D("Distortion", range (-255,255)) = -20
  5. _CP("Color Strength", Range(0,255)) = 1
  6. _RP ("Rim Fade Power", Range(0.1, 8)) = 1
  7. }
  8.  
  9. Category {
  10.  
  11. Tags { "Queue"="Transparent" "RenderType"="Transparent" }
  12. ZWrite Off
  13.  
  14. SubShader {
  15.  
  16. GrabPass {}
  17.  
  18. Pass {
  19.  
  20. CGPROGRAM
  21. #pragma vertex vert
  22. #pragma fragment frag
  23. //#pragma multi_compile_fog
  24. #include "UnityCG.cginc"
  25.  
  26. struct v2f {
  27. float4 color : COLOR;
  28. float4 vertex : SV_POSITION;
  29. float4 uvgrab : TEXCOORD0;
  30. float3 normal : TEXCOORD1;
  31. UNITY_FOG_COORDS(3)
  32. };
  33.  
  34. float _D;
  35. sampler2D _GrabTexture;
  36. float4 _GrabTexture_TexelSize;
  37. float _CP;
  38. float _RP;
  39.  
  40. v2f vert (appdata_full v)
  41. {
  42. v2f o;
  43. o.color = v.color;
  44. o.vertex = UnityObjectToClipPos(v.vertex);
  45. o.uvgrab = ComputeGrabScreenPos(o.vertex);
  46. o.normal = UnityObjectToViewPos(v.normal);
  47.  
  48. // apply inverse rim distortion, to fade out normals away from camera
  49. half rim = dot (normalize(ObjSpaceViewDir(v.vertex)), v.normal);
  50. o.normal *= smoothstep(1 - _RP, 1, rim);
  51.  
  52. UNITY_TRANSFER_FOG(o,o.vertex);
  53. return o;
  54. }
  55.  
  56. half4 frag (v2f i) : SV_Target
  57. {
  58. half3 refracted = i.normal * abs(i.normal) * length(_GrabTexture_TexelSize.xy) * i.color.a * _D;
  59. i.uvgrab.xy = refracted.xy * i.uvgrab.w + i.uvgrab.xy;
  60. half4 refr = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab ));
  61. refr *= lerp(half4(1,1,1,1), i.color, length(refr.xy) * i.color.a * (abs(_D) / 255) * _CP);
  62. UNITY_APPLY_FOG(i.fogCoord, refr);
  63. return refr;
  64. }
  65.  
  66. ENDCG
  67. }
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement