标签:
Shader "Custom/T_3_0" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} } SubShader { CGPROGRAM #pragma surface surf Lambert sampler2D _MainTex; struct Input { float2 uv_MainTex; } ; void surf (Input IN, inout SurfaceOutput o) { half4 c = tex2D (_MainTex, IN.uv_MainTex); o.Albedo = c.rgb; o.Alpha = c.a; } ENDCG } }
struct Input { float2 uv_MainTex; float3 viewDir; float4 anyName:COLOR; float4 screenPos; float3 worldPos; float3 worldRefl; } ;
struct SurfaceOutput { half3 Albedo; half3 Normal; half3 Emission; half Specular; half Gloss; half Alpha; };
#pragma surface surf BlinnPhong alpha
(2)alphatest
加入一个变量,这里起名为_Cutoff, 然后在#pragma surface结尾处加上alphatest:_Cutoff。
效果是alpha值大于_Cutoff时,才会输出颜色
Shader "Custom/T_3_0" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 } SubShader { CGPROGRAM #pragma surface surf Lambert alphatest:_Cutoff sampler2D _MainTex; struct Input { float2 uv_MainTex; } ; void surf (Input IN, inout SurfaceOutput o) { half4 c = tex2D (_MainTex, IN.uv_MainTex); o.Albedo = c.rgb; o.Alpha = c.a; } ENDCG } }
(3)顶点函数
例:臃肿的模型
实现方法,将顶点向法线方向延伸一段距离
Shader "Example/Normal Extrusion" { Properties { _MainTex ("Texture", 2D) = "white" {} _Amount ("Extrusion Amount", Range(-1,1)) = 0.5 } SubShader { Tags { "RenderType" = "Opaque" } CGPROGRAM #pragma surface surf Lambert vertex:vert struct Input { float2 uv_MainTex; }; float _Amount; void vert (inout appdata_full v) { v.vertex.xyz += v.normal * _Amount; } sampler2D _MainTex; void surf (Input IN, inout SurfaceOutput o) { o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb; } ENDCG } Fallback "Diffuse" }
(4)finalcolor
finalcolor:ColorFunction
对颜色输出作最后的更改
Shader "Example/Tint Final Color" { Properties { _MainTex ("Texture", 2D) = "white" {} _ColorTint ("Tint", Color) = (1.0, 0.6, 0.6, 1.0) } SubShader { CGPROGRAM #pragma surface surf Lambert finalcolor:mycolor struct Input { float2 uv_MainTex; }; fixed4 _ColorTint; void mycolor (Input IN, SurfaceOutput o, inout fixed4 color) { //在这里对最后输出的颜色color进行修改 color *= _ColorTint; } sampler2D _MainTex; void surf (Input IN, inout SurfaceOutput o) { o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb; } ENDCG } }
Unity3D教程宝典之Shader篇:第十四讲Surface Shader
标签:
原文地址:http://www.cnblogs.com/zdlbbg/p/4329299.html