Unity显示被遮挡的模型

具体显示为这个效果:
在这里插入图片描述

同事在网上找了一个受光的材质

Shader "Custom/RoleShader"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
        _OcclusionColor("Occlusion Color", Color) = (1,1,1,1)
        _Width ("Width",Range(0,1)) = 0.01
        _Intensity("Intensity",Range(0,1)) = 1
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        Pass
        {
            ZTest Greater
            ZWrite Off

            Blend SrcAlpha OneMinusSrcAlpha

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile_instancing
            #pragma target 3.0
            #include "UnityCG.cginc"

            struct v2f
            {
                float4 worldPos : SV_POSITION;
                float3 viewDir : TEXCOORD0;
                float3 worldNor : TEXCOORD1;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            //fixed4 _OcclusionColor;
            fixed _Width;
            half _Intensity;
            UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
                UNITY_DEFINE_INSTANCED_PROP(fixed4, _OcclusionColor)
            UNITY_INSTANCING_BUFFER_END(Props)
            v2f vert(appdata_base v)
            {
                v2f o;
                UNITY_SETUP_INSTANCE_ID(v);
                UNITY_TRANSFER_INSTANCE_ID(v, o);
                o.worldPos = UnityObjectToClipPos(v.vertex);
                o.viewDir = normalize(WorldSpaceViewDir(v.vertex));
                o.worldNor = UnityObjectToWorldNormal(v.normal);

                return o;
            }

            float4 frag(v2f i) : SV_Target
            {

                UNITY_SETUP_INSTANCE_ID(i);
                fixed4 color = UNITY_ACCESS_INSTANCED_PROP(Props, _OcclusionColor);
                half NDotV = saturate( dot(i.worldNor, i.viewDir));
                NDotV = pow(1 - NDotV, _Width) * _Intensity;
                color.rgb = color.rgb;
                color.a =color.a>0.5 ? NDotV : 0;
                return color;
            }

            ENDCG
        }

        CGPROGRAM
        #pragma surface surf SimpleLambert fullforwardshadows
            // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0
        half4 LightingSimpleLambert (SurfaceOutput s, half3 lightDir, half atten) {
            half NdotL = dot (s.Normal, lightDir);
            half4 c;
            c.rgb = s.Albedo * _LightColor0.rgb * (NdotL * atten);
            c.a = s.Alpha;
            return c;
        }

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props1)
            // put more per-instance properties here
            //UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
        UNITY_INSTANCING_BUFFER_END(Props1)

        void surf (Input IN, inout SurfaceOutput o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Specular = _Metallic;
            o.Gloss = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

在这里插入图片描述
但是美术那边的这个小人受光的时候十分粗糙,于是手改了一个不受光的

Shader "Unlit/RoleShaderUnlit"
{
  Properties
  {
      _MainTex("Texture", 2D) = "white" {}
  _OcclusionColor("Occlusion Color", Color) = (1,1,1,1)
  }
    SubShader
      {
          Tags { "RenderType" = "Opaque" }
          LOD 100

          Pass
          {
            Blend SrcAlpha One
            ZWrite off
            Lighting off
            ztest greater


            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
                    // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"

            struct appdata
            {
              float4 vertex : POSITION;
              float2 uv : TEXCOORD0;
            };

            struct v2f
            {
              float2 uv : TEXCOORD0;
              UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
              float4  color:COLOR;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;
            float4 _OcclusionColor;

            v2f vert(appdata v)
            {
              v2f o;
              o.vertex = UnityObjectToClipPos(v.vertex);
              o.uv = TRANSFORM_TEX(v.uv, _MainTex);
              UNITY_TRANSFER_FOG(o,o.vertex);
              o.color = _OcclusionColor;
              return o;
            }

            fixed4 frag(v2f i) : COLOR
            {
            return i.color;
            }
              ENDCG
          }

          Pass
          {
              ZWrite on
              ZTest less

              CGPROGRAM
              #pragma vertex vert
              #pragma fragment frag
              // make fog work
              #pragma multi_compile_fog

              #include "UnityCG.cginc"

              struct appdata
              {
                  float4 vertex : POSITION;
                  float2 uv : TEXCOORD0;
              };

              struct v2f
              {
                  float2 uv : TEXCOORD0;
                  UNITY_FOG_COORDS(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
              {
                // sample the texture
                fixed4 col = tex2D(_MainTex, i.uv);
              // apply fog
              UNITY_APPLY_FOG(i.fogCoord, col);
              return col;
          }
          ENDCG
      }
      }
}

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值