|
| 1 | +// 2 pass shader to draw object with blurry texture and slightly transparent when behind walls |
| 2 | + |
| 3 | +Shader "UnityLibrary/Standard/Effects/SeeThroughWalls" |
| 4 | +{ |
| 5 | + Properties |
| 6 | + { |
| 7 | + _Color("Color", Color) = (1,1,1,1) |
| 8 | + _MainTex("Albedo (RGB)", 2D) = "white" {} |
| 9 | + _Glossiness("Smoothness", Range(0,1)) = 0.5 |
| 10 | + _Metallic("Metallic", Range(0,1)) = 0.0 |
| 11 | + _BlurSize("BlurSize", float) = 10 |
| 12 | + _SeeThroughOpacity("SeeThroughOpacityAdjust", Range(0,1)) = 0.5 |
| 13 | + } |
| 14 | + |
| 15 | + SubShader |
| 16 | + { |
| 17 | + // Regular Pass |
| 18 | + Tags { "RenderType" = "Opaque" } |
| 19 | + LOD 200 |
| 20 | + |
| 21 | + CGPROGRAM |
| 22 | + // Physically based Standard lighting model, and enable shadows on all light types |
| 23 | + #pragma surface surf Standard fullforwardshadows |
| 24 | + |
| 25 | + // Use shader model 3.0 target, to get nicer looking lighting |
| 26 | + #pragma target 3.0 |
| 27 | + |
| 28 | + sampler2D _MainTex; |
| 29 | + |
| 30 | + struct Input |
| 31 | + { |
| 32 | + float2 uv_MainTex; |
| 33 | + }; |
| 34 | + |
| 35 | + half _Glossiness; |
| 36 | + half _Metallic; |
| 37 | + fixed4 _Color; |
| 38 | + |
| 39 | + // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader. |
| 40 | + // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing. |
| 41 | + // #pragma instancing_options assumeuniformscaling |
| 42 | + UNITY_INSTANCING_BUFFER_START(Props) |
| 43 | + // put more per-instance properties here |
| 44 | + UNITY_INSTANCING_BUFFER_END(Props) |
| 45 | + |
| 46 | + void surf(Input IN, inout SurfaceOutputStandard o) |
| 47 | + { |
| 48 | + // Albedo comes from a texture tinted by color |
| 49 | + fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; |
| 50 | + o.Albedo = c.rgb; |
| 51 | + // Metallic and smoothness come from slider variables |
| 52 | + o.Metallic = _Metallic; |
| 53 | + o.Smoothness = _Glossiness; |
| 54 | + o.Alpha = c.a; |
| 55 | + } |
| 56 | + ENDCG |
| 57 | + |
| 58 | + // see through pass |
| 59 | + |
| 60 | + Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" } |
| 61 | + LOD 200 |
| 62 | +// Blend OneMinusDstColor One // Soft Additive |
| 63 | + Blend SrcAlpha OneMinusSrcAlpha // Traditional transparency |
| 64 | +// Blend One OneMinusSrcAlpha // Premultiplied transparency |
| 65 | +// Blend One One // Additive |
| 66 | +// Blend OneMinusDstColor One // Soft Additive |
| 67 | +// Blend DstColor Zero // Multiplicative |
| 68 | +// Blend DstColor SrcColor // 2x Multiplicative |
| 69 | + |
| 70 | + ZWrite Off |
| 71 | + ZTest Greater |
| 72 | + |
| 73 | + CGPROGRAM |
| 74 | + // Physically based Standard lighting model, and enable shadows on all light types |
| 75 | + #pragma surface surf Standard alpha:fade |
| 76 | + |
| 77 | + // Use shader model 3.0 target, to get nicer looking lighting |
| 78 | + #pragma target 3.0 |
| 79 | + |
| 80 | + sampler2D _MainTex; |
| 81 | + float4 _MainTex_TexelSize; |
| 82 | + float _BlurSize; |
| 83 | + float _SeeThroughOpacity; |
| 84 | + |
| 85 | + struct Input |
| 86 | + { |
| 87 | + float2 uv_MainTex; |
| 88 | + }; |
| 89 | + |
| 90 | + half _Glossiness; |
| 91 | + half _Metallic; |
| 92 | + fixed4 _Color; |
| 93 | + |
| 94 | + UNITY_INSTANCING_BUFFER_START(Props) |
| 95 | + // put more per-instance properties here |
| 96 | + UNITY_INSTANCING_BUFFER_END(Props) |
| 97 | + |
| 98 | + void surf(Input IN, inout SurfaceOutputStandard o) |
| 99 | + { |
| 100 | + // small blur effect on the texture |
| 101 | + fixed4 cR = tex2D(_MainTex, float2(IN.uv_MainTex.x + _MainTex_TexelSize.x * _BlurSize,IN.uv_MainTex.y)); |
| 102 | + fixed4 cL = tex2D(_MainTex, float2(IN.uv_MainTex.x - _MainTex_TexelSize.x * _BlurSize,IN.uv_MainTex.y)); |
| 103 | + fixed4 cT = tex2D(_MainTex, float2(IN.uv_MainTex.x,IN.uv_MainTex.y + _MainTex_TexelSize.y * _BlurSize)); |
| 104 | + fixed4 cB = tex2D(_MainTex, float2(IN.uv_MainTex.x,IN.uv_MainTex.y - _MainTex_TexelSize.y * _BlurSize)); |
| 105 | + fixed4 c = (cR + cL + cT + cB) * 0.25; |
| 106 | + o.Albedo = c; |
| 107 | + o.Metallic = _Metallic; |
| 108 | + o.Smoothness = _Glossiness; |
| 109 | + // make object also bit transparent |
| 110 | + o.Alpha = c.a* _SeeThroughOpacity; |
| 111 | + } |
| 112 | + ENDCG |
| 113 | + |
| 114 | + } // subshader |
| 115 | + FallBack "Diffuse" |
| 116 | +} // shader |
0 commit comments