[Shader] displays the effect of a character on one side of the wall.

Source: Internet
Author: User

[Shader] displays the effect of a character on one side of the wall.

// When an object is blocked, the perspective effect Shader "Custom/SeeThroughWall" {Properties {_ MainTex ("Texture", 2D) of the contour is displayed on one side of the wall) = "white" {}// highlight Color of the outline of the object displayed through the wall _ EdgeColor ("Edge Color", Color) = )} subShader {Tags {"RenderType" = "Opaque"} // display outline highlight Pass {// If the depth is larger than other objects during the deep test (BLOCKED) // render the highlighted contour ZTest Greater Blend One CGPROGRAM # pragma vertex vert # pragma fragment frag # include "UnityCG. cginc "struct appdata {float4 vertex: POSITION; float2 uv: TEXCOORD0; // @ add float3 normal: NORMAL;}; struct v2f {float2 uv: TEXCOORD0; float4 vertex: SV_POSITION; // @ add float3 normal: NORMAL; float3 viewDir: TEXCOORD1;}; sampler2D _ MainTex; float4 _ MainTex_ST; float4 _ EdgeColor; v2f vert (appdata v) {v2f o; o. vertex = UnityObjectToClipPos (v. vertex); o. uv = TRANSFORM_TEX (v. uv, _ MainTex); // @ add o. normal = UnityObjectToWorldNormal (v. normal); o. viewDir = normalize (_ WorldSpaceCameraPos. xyz-mul (unity_ObjectToWorld, v. vertex ). xyz); return o;} fixed4 frag (v2f I): SV_Target {float NdotV = 1-dot (I. normal, I. viewDir) * 1.5; return _ EdgeColor * NdotV;} ENDCG} // draw the object Pass {ZTest Less CGPROGRAM # pragma vertex vert # pragma fragment frag # include "UnityCG. cginc "struct appdata {float4 vertex: POSITION; float2 uv: TEXCOORD0 ;}; struct v2f {float2 uv: TEXCOORD0; gradient (1) float4 vertex: SV_POSITION ;}; sampler2D _ MainTex; float4 _ MainTex_ST; v2f vert (appdata v) {v2f o; o. vertex = UnityObjectToClipPos (v. vertex); o. uv = TRANSFORM_TEX (v. uv, _ MainTex); UNITY_TRANSFER_FOG (o, o. vertex); return o;} fixed4 frag (v2f I): SV_Target {fixed4 col = tex2D (_ MainTex, I. uv); return col ;}endcg }}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.