IceShaderDistortion.shader 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Effects/Ice/IceDistortion" {
  3. Properties {
  4. _Color ("Main Color", Color) = (1,1,1,1)
  5. _SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,1)
  6. _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
  7. _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
  8. _ReflectionStrength ("ReflectionStrength", Range (1, 20)) = 1
  9. _MainTex ("Base (RGB) Emission Tex (A)", 2D) = "white" {}
  10. _Opacity ("Material opacity", Range (-1, 1)) = 0.5
  11. _Cube ("Reflection Cubemap", Cube) = ""
  12. _BumpMap ("Normalmap", 2D) = "bump" {}
  13. _FPOW("FPOW Fresnel", Float) = 5.0
  14. _R0("R0 Fresnel", Float) = 0.05
  15. _Cutoff ("Cutoff", Range (0, 1)) = 0.5
  16. _LightStr ("Light strength", Range (0, 1)) = 1
  17. _BumpAmt ("Distortion", range (0,500)) = 10
  18. }
  19. SubShader {
  20. Tags { "Queue"="Transparent+1" "RenderType"="Transperent" }
  21. GrabPass {"_GrabTexture"}
  22. LOD 200
  23. ZWrite On
  24. CGPROGRAM
  25. #pragma vertex vert
  26. #pragma surface surf Lambert alpha
  27. #pragma glsl
  28. sampler2D _MainTex;
  29. sampler2D _BumpMap;
  30. samplerCUBE _Cube;
  31. float _BumpAmt;
  32. sampler2D _GrabTexture;
  33. float4 _GrabTexture_TexelSize;
  34. float4 _Color;
  35. float4 _ReflectColor;
  36. float _ReflectionStrength;
  37. float _Shininess;
  38. float _FPOW;
  39. float _R0;
  40. float _Opacity;
  41. float _Cutoff;
  42. float _LightStr;
  43. struct Input {
  44. float2 uv_MainTex;
  45. float2 uv_BumpMap;
  46. float3 viewDir;
  47. float3 worldRefl;
  48. INTERNAL_DATA
  49. float2 uv_BumpMapGlass;
  50. float4 proj : TEXCOORD0;
  51. };
  52. void vert (inout appdata_full v, out Input o) {
  53. UNITY_INITIALIZE_OUTPUT(Input,o);
  54. float4 oPos = UnityObjectToClipPos(v.vertex);
  55. #if UNITY_UV_STARTS_AT_TOP
  56. float scale = -1.0;
  57. #else
  58. float scale = 1.0;
  59. #endif
  60. o.proj.xy = (float2(oPos.x, oPos.y*scale) + oPos.w) * 0.5;
  61. o.proj.zw = oPos.zw;
  62. }
  63. void surf (Input IN, inout SurfaceOutput o) {
  64. half4 tex = tex2D(_MainTex, IN.uv_MainTex);
  65. half4 c = tex * _Color;
  66. o.Gloss = tex.a;
  67. o.Specular = _Shininess;
  68. o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
  69. float3 worldRefl = WorldReflectionVector (IN, o.Normal);
  70. half4 reflcol = texCUBE (_Cube, worldRefl);
  71. reflcol *= tex.a;
  72. half fresnel = saturate(1.0 - dot(o.Normal, normalize(IN.viewDir)));
  73. fresnel = pow(fresnel, _FPOW);
  74. fresnel = _R0 + (1.0 - _R0) * fresnel;
  75. reflcol = lerp(c, reflcol, fresnel);
  76. half2 offset = o.Normal.rg * _BumpAmt * _GrabTexture_TexelSize.xy;
  77. IN.proj.xy = offset * IN.proj.z + IN.proj.xy;
  78. half4 col = tex2Dproj(_GrabTexture, UNITY_PROJ_COORD(IN.proj));
  79. //o.Emission = reflcol.rgb * _ReflectColor.rgb * _ReflectionStrength * _LightStr;
  80. o.Emission = (col.rgb + reflcol.rgb* _ReflectionStrength * _LightStr) * _ReflectColor.rgb;
  81. o.Albedo = _Color ;
  82. o.Alpha = _Cutoff > tex.a ? tex.a+_Opacity : 0;
  83. }
  84. ENDCG
  85. }
  86. FallBack "Reflective/Bumped Diffuse"
  87. }