duck

duck

Jul 7th, 2010
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. // Per pixel bumped refraction.
  2. // Uses a normal map to distort the image behind
  3.  
  4. Shader "FX/HeatDistort" {
  5. Properties {
  6. _BumpAmt ("Distortion", range (0,128)) = 10
  7. _BumpMap ("Bumpmap (RGB)", 2D) = "bump" {}
  8. }
  9.  
  10. Category {
  11.  
  12. // We must be transparent, so other objects are drawn before this one.
  13. Tags { "Queue" = "Transparent"}
  14.  
  15. // ------------------------------------------------------------------
  16. // ARB fragment program
  17.  
  18. SubShader {
  19.  
  20. // This pass grabs the screen behind the object into a texture.
  21. // We can access the result in the next pass as _GrabTexture
  22. GrabPass {
  23. Name "BASE"
  24. Tags { "LightMode" = "Always" }
  25. }
  26.  
  27. // Main pass: Take the texture grabbed above and use the bumpmap to perturb it
  28. // on to the screen
  29. Pass {
  30. Name "BASE"
  31. Tags { "LightMode" = "Always" }
  32.  
  33. CGPROGRAM
  34. #pragma fragment frag
  35. #pragma fragmentoption ARB_precision_hint_fastest
  36. #pragma fragmentoption ARB_fog_exp2
  37.  
  38. samplerRECT _GrabTexture : register(s0);
  39. sampler2D _BumpMap : register(s1);
  40.  
  41.  
  42. struct v2f {
  43. float4 uv : TEXCOORD0;
  44. float2 uvbump : TEXCOORD1;
  45. };
  46.  
  47. uniform float _BumpAmt;
  48.  
  49. half4 frag( v2f i ) : COLOR
  50. {
  51. // calculate perturbed coordinates
  52. half2 bump = tex2D( _BumpMap, i.uvbump ).rg * 2 - 1;
  53. //i.uv.xy = bump * _BumpAmt * i.uv.w + i.uv.xy;
  54. float2 offset = bump * _BumpAmt * 0.01;
  55. i.uv.xy = offset * i.uv.z + i.uv.xy;
  56.  
  57. half4 col = texRECTproj( _GrabTexture, i.uv.xyw );
  58.  
  59. return col;
  60. }
  61.  
  62. ENDCG
  63. // Set up the textures for this pass
  64. SetTexture [_GrabTexture] {} // Texture we grabbed in the pass above
  65. SetTexture [_BumpMap] {} // Perturbation bumpmap
  66. SetTexture [_MainTex] {} // Color tint
  67. }
  68. }
  69.  
  70. // ------------------------------------------------------------------
  71. // Fallback for older cards and Unity non-Pro
  72.  
  73. SubShader {
  74.  
  75. Lighting Off
  76. ZWrite Off
  77. ColorMask A
  78. Pass {}
  79. }
  80. }
  81.  
  82. }
Add Comment
Please, Sign In to add comment