引子
Surface Shader
最简单的SurfaceShader
1 | Shader "Custom/T_3_0" { |
struct Input {
float2 uv_MainTex;
float3 viewDir;
float4 anyName:COLOR;
float4 screenPos;
float3 worldPos;
float3 worldRefl;
} ;
1 | uv_MainTex: uv |
struct SurfaceOutput {
half3 Albedo;
half3 Normal;
half3 Emission;
half Specular;
half Gloss;
half Alpha;
};
1 | Albedo:漫反射颜色 |
pragma surface surf BlinnPhong alpha
1 |
|
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
}
}
1 |
|
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"
}
1 | ### finalcolor |
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
}
}
```