Unity怎样获得 shader 为 Self-Illumin/Diffuse 的alpha值

来源:互联网 发布:什么桌面壁纸软件好 编辑:程序博客网 时间:2024/05/18 01:12

unity  的  build-in shader     “Self-Illumin/Diffuse” 源码如下

Shader "Self-Illumin/Diffuse" {
Properties {
    _Color ("Main Color"Color) = (1,1,1,1)
    _MainTex ("Base (RGBGloss (A)"2D) = "white" {}
    _Illum ("Illumin (A)"2D) = "white" {}
    _EmissionLM ("Emission (Lightmapper)"Float) = 0
}
SubShader {
    Tags { "RenderType"="Opaque" }
    LOD 200
    
CGPROGRAM
#pragma surface surf Lambert

sampler2D _MainTex;
sampler2D _Illum;
fixed4 _Color;

struct Input {
    float2 uv_MainTex;
    float2 uv_Illum;
};

void surf (Input INinout SurfaceOutput o) {
    fixed4 tex = tex2D(_MainTexIN.uv_MainTex);
    fixed4 c = tex * _Color;
    o.Albedo = c.rgb;
    o.Emission = c.rgb * tex2D(_IllumIN.uv_Illum).a;
    o.Alpha = c.a;
}
ENDCG

FallBack "Self-Illumin/VertexLit"
}

如果你想通过Inspector面板获得_Color的alpha值,只用把CGPROGRAM的#pragma行改为

#pragma surface surf Lambert alpha   即可(就是添加了个alpha),

至于Tags { "RenderType"="Opaque" } 是否需要把Opaque改成Transparent(这样有什么好处?!)

有待进一步学习探索。。。tag 里面加上"Queue" = "Transparent"可以保证此物体最后渲染,至少是在

Opaque之后

0 0
原创粉丝点击