Unity #pragma multi_compile说明
2021-02-03 04:17
标签:sel osi oid form namespace 选择 sdn article 根据 示例shader 示例脚本 Unity #pragma multi_compile说明 标签:sel osi oid form namespace 选择 sdn article 根据 原文地址:https://www.cnblogs.com/nafio/p/12805688.htmlhttps://blog.csdn.net/ak47007tiger/article/details/100007655
multi_compile
Shader "DC/Shader/ShaderLab/MultiCompile"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
[KeywordEnum(R,G,B)] _CL("ColorSelect", Float) = 0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _CL_R _CL_G _CL_B
//使用 __ 减少一个编译选项,编译选项最多256个
#pragma multi_compile __ DB_ON
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
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
{
#if DB_ON
return fixed4(1,1,0,1);
#elif _CL_R
return fixed4(1,0,0,1);
#elif _CL_G
return fixed4(0,1,0,1);
#elif _CL_B
return fixed4(0,0,1,1);
#else
fixed4 col = tex2D(_MainTex, i.uv);
return col;
#endif
}
ENDCG
}
}
}
using UnityEngine;
namespace DC
{
public class MultiCompile : MonoBehaviour
{
public Material mat;
public void OnEnable()
{
mat.EnableKeyword("DB_ON");
// Shader.EnableKeyword("ON");
}
public void OnDisable()
{
mat.DisableKeyword("DB_ON");
// Shader.DisableKeyword("DB_ON");
}
}
}
文章标题:Unity #pragma multi_compile说明
文章链接:http://soscw.com/index.php/essay/50259.html