1. Unity中的shader
-
- Standard Surface Shader:会产生一个包含了标准光照模型的表面着色器模板
- Unlit Shader:会产生一个不包含光照(但包含雾效)的基本的顶点/片源着色器
- Image Effect Shader:实现各种屏幕后处理效果
- Compute Shader:利用GPU的并行性来进行一些与常规渲染流水线无关的计算
Shader "Custom/NewSurfaceShader" //NewSurfaceShader为shader文件名
{
Properties //材质和shader的桥梁
{
//定义一些属性 _名字(“显示的名称”,类型)
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader //可以包含多个但至少包含一个
{
//标签和状态设置
Tags { "RenderType"="Opaque" }
LOD 200
//编译指令,例如:
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.0
//CG代码
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
如果觉对你有帮助,大兄弟点个赞可好!