Unity Shader Cull(双面显示)

先不概述了原理我也不是很理解,但找到办法就分享出来。
首先使用Unity并不是很熟的原因吧,双面显示很简单的东西都得设及Shader创建,那不说多了直接进入正题!
首先先创建个URP,资产栏创建 ShaderGraph—URP—LitshaderGraph
在这里插入图片描述
我们就得到了一个标准编辑器的一个东西
在这里插入图片描述
双击打开编辑器后点击空白地方找到左上角GraphSettings属性下的RenderFace 设置属性默认Front Back反向 Both前置 这个呢 我理解官方说明文档上的差不多参照,网站上看见很多带Two Sided开关的不知道怎么创建的,根据实际情况就不一一一列举了
参考:CullMode
在这里插入图片描述
事情到这呢!双面显示就解决了吧!
在这里插入图片描述

那么如果是创建shader—StandardSurfaceShader 怎么增加属性,也尝试了下,首先创建
在这里插入图片描述
我们会得到一个S的一个编辑器,右击找到Show is Explorer 打开本地位置,这边呢看大家自己喜欢用什么样的编辑器打开,系统自带txt也能打开,高大上可以用VS,这边呢用的N++平时简单的编辑文档用的挺好!
在这里插入图片描述
这是打开默认这样,

Shader "Custom/NewSurfaceShader"
{
    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
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200
		Cull Off			//增加这条就默认给的双面显示依次给Fronet 称为正面剔除Back称为背面剔除
        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        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(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard 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.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

参考文档:ShaderLab command: Cull

猜你喜欢

转载自blog.csdn.net/beita126/article/details/129863304
今日推荐