Unity图形学之Shader顶点变化
1.Unity3D 5.0 以后:Pass被隐藏起来,通过调节SurfaceOutputStandard 和 SurfaceOutputStandardSpecular的参数 就能出现比较好的效果
#pragma surface surf Standard fullforwardshadows
void surf (Input IN, inout SurfaceOutputStandard o)
#pragma surface surf StandardSpecular fullforwardshadows
void surf (Input IN, inout SurfaceOutputStandardSpecular o)
2.自定义灯光渲染接口:
#pragma surface surf Lambert finalcolor:mycolor vertex:myvert
(1)Vertex:定义 顶点着色器的入口函数
(2)Surf:Surface 入口函数 可以看成是 片段着色器
(3)Lambert:定义 灯光作用的入口函数
(4)Finalcolor: 计算雾 最后一次计算像素 的入口函数
(5)Surface vertex:
3.Inout:表示即是 输入也是 输出
Float:精度是32
Half:精度是16
Fixed:精度是12
Shader "Custom/TestVertex"
{
Properties
{
_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
_ChangeRange ("Position",float) = 2.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Lambert vertex:myvert
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
half _ChangeRange;
//顶点着色器 一般是改变位置大小
void myvert(inout appdata_base v){
//v.vertex.xyz *=2;
//v.vertex.xyz +=2;
//v.vertex.xyz *=_ChangeRange;
v.vertex.xyz += v.normal *_ChangeRange;
}
//SurfaceOutput 作为下一个流程的输入 传递给灯光Lambert
void surf (Input IN, inout SurfaceOutput o)
{
//从_MainTex进行纹理采样
o.Albedo = tex2D(_MainTex,IN.uv_MainTex).rgb;
}
ENDCG
}
FallBack "Diffuse"
}
4.渲染流程:
Vertex——>Surf——> Lambert——>Finalcolor