Blend SM2.shader 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. Shader "Enviro/BumpedDiffuseOverlaySM2" {
  2. //
  3. // Tomasz Stobierski 2012
  4. //
  5. Properties {
  6. _Color ("Main Color", Color) = (1,1,1,1)
  7. _Opacity ("Color over opacity", Range (0, 1)) = 1
  8. _MainTex ("Color over (RGBA)", 2D) = "white" {}
  9. _BumpMap ("Normalmap over", 2D) = "bump" {}
  10. _MainTex2 ("Color under (RGBA)", 2D) = "white" {}
  11. _BumpMap2 ("Normalmap under", 2D) = "bump" {}
  12. }
  13. SubShader {
  14. Tags { "RenderType"="Opaque" }
  15. LOD 400
  16. CGPROGRAM
  17. #pragma surface surf Lambert
  18. #pragma exclude_renderers flash
  19. sampler2D _MainTex;
  20. sampler2D _BumpMap;
  21. sampler2D _MainTex2;
  22. sampler2D _BumpMap2;
  23. fixed4 _Color;
  24. float _Opacity;
  25. struct Input {
  26. float2 uv_MainTex;
  27. float2 uv_BumpMap;
  28. float2 uv_MainTex2;
  29. float2 uv_BumpMap2;
  30. };
  31. void surf (Input IN, inout SurfaceOutput o) {
  32. float4 tex = tex2D(_MainTex, IN.uv_MainTex);
  33. float4 tex2 = tex2D(_MainTex2, IN.uv_MainTex2);
  34. float4 dest;
  35. _Opacity*=tex.a;
  36. dest.rgb = tex2.rgb<=0.5 ? 2*tex.rgb*tex2.rgb : 1-2*(1-tex.rgb)*(1-tex2.rgb);
  37. dest.rgb = lerp(tex2.rgb, dest.rgb, _Opacity);
  38. dest.rgb *= _Color.rgb;
  39. o.Albedo = dest.rgb;
  40. o.Alpha = tex2.a * _Color.a;
  41. float4 norm = tex2D(_BumpMap, IN.uv_BumpMap);
  42. float4 norm2 = tex2D(_BumpMap2, IN.uv_BumpMap2);
  43. dest = norm2<=0.5 ? 2*norm*norm2 : 1-2*(1-norm)*(1-norm2);
  44. dest = lerp(norm2, dest, _Opacity);
  45. o.Normal = UnpackNormal(dest);
  46. }
  47. ENDCG
  48. }
  49. SubShader {
  50. Tags { "RenderType"="Opaque" }
  51. LOD 400
  52. CGPROGRAM
  53. #pragma surface surf Lambert
  54. #pragma only_renderers flash
  55. sampler2D _MainTex;
  56. sampler2D _MainTex2;
  57. fixed4 _Color;
  58. float _Opacity;
  59. struct Input {
  60. float2 uv_MainTex;
  61. float2 uv_MainTex2;
  62. };
  63. void surf (Input IN, inout SurfaceOutput o) {
  64. float4 tex = tex2D(_MainTex, IN.uv_MainTex);
  65. float4 tex2 = tex2D(_MainTex2, IN.uv_MainTex2);
  66. float4 dest;
  67. _Opacity*=tex.a;
  68. dest.rgb = tex2.rgb<=0.5 ? 2*tex.rgb*tex2.rgb : 1-2*(1-tex.rgb)*(1-tex2.rgb);
  69. dest.rgb = lerp(tex2.rgb, dest.rgb, _Opacity);
  70. dest.rgb *= _Color.rgb;
  71. o.Albedo = dest.rgb;
  72. o.Alpha = tex2.a * _Color.a;
  73. }
  74. ENDCG
  75. }
  76. FallBack "Bumped Diffuse"
  77. }