码迷,mamicode.com
首页 > 其他好文 > 详细

Vertex Modifier of Surface Shader

时间:2014-08-02 15:13:13      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   strong   io   数据   2014   

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:vert
10       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       ENDCG
22     } 
23     Fallback "Diffuse"
24   }

  bubuko.com,布布扣

  如果想传递给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       ENDCG
23     } 
24     Fallback "Diffuse"
25   }

  bubuko.com,布布扣

参考:file:///C:/Program%20Files%20(x86)/Unity/Editor/Data/Documentation/html/en/Manual/SL-SurfaceShaderExamples.html

Vertex Modifier of Surface Shader,布布扣,bubuko.com

Vertex Modifier of Surface Shader

标签:style   blog   http   color   strong   io   数据   2014   

原文地址:http://www.cnblogs.com/tekkaman/p/3886888.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!