欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

keywords LightMode=Always

程序员文章站 2022-06-04 15:41:44
...

is there any shader that will executed always. that means we should not care about the camera’s rendering mode.
yep, unity support us the keyword Always to solve this problem.
next, we will give the shader code like this:

// Upgrade NOTE: replzaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "Course/Always" 
{
    SubShader 
    {
        pass
        {
            Tags{ "LightMode"="Always"}
            Blend One Zero
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"
            #include "Lighting.cginc"

            struct vertOut
            {
                float4 pos:SV_POSITION;
                float4 color:COLOR;
            };

            vertOut vert(appdata_base v)
            {
                vertOut o;
                o.pos=UnityObjectToClipPos(v.vertex);
                o.color=float4(1,0,0,1);
                return o;
            }

            float4 frag(vertOut i):COLOR
            {
                return i.color;
            }
            ENDCG
        }
    }
}

you can change the camera’s rendering mode to any of this:
keywords LightMode=Always

the object will be render to red in every circumstances.

the effect is :
keywords LightMode=Always

相关标签: lightmode always