GlassWithoutGrab.shader 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. Shader "FX/Glass/Stained BumpDistort (no grab)"
  2. {
  3. Properties
  4. {
  5. _BumpAmt ("Distortion", range (0,64)) = 10
  6. _TintAmt ("Tint Amount", Range(0,1)) = 0.1
  7. _MainTex ("Tint Color (RGB)", 2D) = "white" {}
  8. _BumpMap ("Normalmap", 2D) = "bump" {}
  9. }
  10. Category
  11. {
  12. // We must be transparent, so other objects are drawn before this one.
  13. Tags
  14. {
  15. "Queue"="Transparent" "RenderType"="Opaque"
  16. }
  17. SubShader
  18. {
  19. Pass
  20. {
  21. Name "BASE"
  22. Tags
  23. {
  24. "LightMode" = "Always"
  25. }
  26. CGPROGRAM
  27. #pragma vertex vert
  28. #pragma fragment frag
  29. #pragma multi_compile_fog
  30. #include "UnityCG.cginc"
  31. struct appdata_t
  32. {
  33. float4 vertex : POSITION;
  34. float2 texcoord: TEXCOORD0;
  35. };
  36. struct v2f
  37. {
  38. float4 vertex : POSITION;
  39. float4 uvgrab : TEXCOORD0;
  40. float2 uvbump : TEXCOORD1;
  41. float2 uvmain : TEXCOORD2;
  42. UNITY_FOG_COORDS(3)
  43. };
  44. float _BumpAmt;
  45. half _TintAmt;
  46. float4 _BumpMap_ST;
  47. float4 _MainTex_ST;
  48. sampler2D _GrabBlurTexture;
  49. float4 _GrabBlurTexture_TexelSize;
  50. sampler2D _BumpMap;
  51. sampler2D _MainTex;
  52. v2f vert(const appdata_t v)
  53. {
  54. v2f o;
  55. o.vertex = UnityObjectToClipPos(v.vertex);
  56. #if UNITY_UV_STARTS_AT_TOP
  57. const float scale = -1.0;
  58. #else
  59. float scale = 1.0;
  60. #endif
  61. o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y * scale) + o.vertex.w) * 0.5;
  62. o.uvgrab.zw = o.vertex.zw;
  63. o.uvbump = TRANSFORM_TEX(v.texcoord, _BumpMap);
  64. o.uvmain = TRANSFORM_TEX(v.texcoord, _MainTex);
  65. UNITY_TRANSFER_FOG(o, o.vertex);
  66. return o;
  67. }
  68. half4 frag(v2f i) : SV_Target
  69. {
  70. // calculate perturbed coordinates
  71. // we could optimize this by just reading the x & y without reconstructing the Z
  72. const half2 bump = UnpackNormal(tex2D(_BumpMap, i.uvbump)).rg;
  73. const float2 offset = bump * _BumpAmt * _GrabBlurTexture_TexelSize.xy;
  74. i.uvgrab.xy = offset * i.uvgrab.z + i.uvgrab.xy;
  75. half4 col = tex2Dproj(_GrabBlurTexture, UNITY_PROJ_COORD(i.uvgrab));
  76. const half4 tint = tex2D(_MainTex, i.uvmain);
  77. col = lerp(col, tint, _TintAmt);
  78. UNITY_APPLY_FOG(i.fogCoord, col);
  79. return col;
  80. }
  81. ENDCG
  82. }
  83. }
  84. }
  85. }