首页 > 代码库 > Vertex Modifier of Surface Shader
Vertex Modifier of Surface Shader
【Vertex Modifier of Surface Shader】
Surface shader compilation directive vertex:functionName
可以用于指定顶点着色器。A function that takes inout appdata_full
parameter.
appdata_full是什么结构?
1 Shader "Example/Normal Extrusion" { 2 Properties { 3 _MainTex ("Texture", 2D) = "white" {} 4 _Amount ("Extrusion Amount", Range(-1,1)) = 0.5 5 } 6 SubShader { 7 Tags { "RenderType" = "Opaque" } 8 CGPROGRAM 9 #pragma surface surf Lambert vertex:vert10 struct Input {11 float2 uv_MainTex;12 };13 float _Amount;14 void vert (inout appdata_full v) {15 v.vertex.xyz += v.normal * _Amount;16 }17 sampler2D _MainTex;18 void surf (Input IN, inout SurfaceOutput o) {19 o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;20 }21 ENDCG22 } 23 Fallback "Diffuse"24 }
如果想传递给surface自定义数据(per-pixel),顶点函数需要添加out Input 参数如下:
1 Shader "Example/Custom Vertex Data" { 2 Properties { 3 _MainTex ("Texture", 2D) = "white" {} 4 } 5 SubShader { 6 Tags { "RenderType" = "Opaque" } 7 CGPROGRAM 8 #pragma surface surf Lambert vertex:vert 9 struct Input {10 float2 uv_MainTex;11 float3 customColor;12 };13 void vert (inout appdata_full v, out Input o) {14 UNITY_INITIALIZE_OUTPUT(Input,o);15 o.customColor = abs(v.normal);16 }17 sampler2D _MainTex;18 void surf (Input IN, inout SurfaceOutput o) {19 o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;20 o.Albedo *= IN.customColor;21 }22 ENDCG23 } 24 Fallback "Diffuse"25 }
参考:file:///C:/Program%20Files%20(x86)/Unity/Editor/Data/Documentation/html/en/Manual/SL-SurfaceShaderExamples.html
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。