1、 appdata_tan: vertex consists of position, tangent, normal and one texture coordinate.appdata_tan:包含顶点位置,切线,法线 和一个纹理坐标。For example, this shader colors the mesh based on its normals and just uses appdata_base as vertex program input:例如:下面是这个着色器颜色网是基于它的法线,它仅仅在顶点程序中使用了appdata_base输入结构。Shader VertexInpu
2、tSimple SubShader Pass CGPROGRAM#pragma vertex vert#include UnityCG.cgincstruct v2f float4 pos : SV_POSITION; fixed4 color : COLOR;v2f vert (appdata_base v) v2f o; o.pos = mul (UNITY_MATRIX_MVP, v.vertex); o.color.xyz = v.normal * 0.5 + 0.5; return o;ENDCG If you want to access different vertex data
3、, you have to declare vertex structure yourself. The structure members must be from the following list:如果你想访问个别的顶点数据,你必须自己声明顶点结构。结构中的成员必须是属于以下列表中的: float4 vertex is the vertex positionfloat4 vertex 是顶点位置 float3 normal is the vertex normalfloat3 normal 是顶点法线 float4 texcoord is the first UV coordinate
4、float4 texcoord 是第一UV坐标 float4 texcoord1 is the second UV coordinatefloat4 texcoord1 是第二UV坐标 float4 tangent is the tangent vector (used for normal mapping)float4 tangent 是切线向量(用在法线贴图中) float4 color is per-vertex colorfloat4 color 是每个顶点(per-vertex)颜色Examples 范例Visualizing UVs 可视化UVThe following shade
5、r example uses vertex position and first texture coordinate as vertex shader input (defined in structure appdata). It is very useful to debug UV coordinates of the mesh. UV coordinates are visualized as red and green colors, and coordinates outside of 0.1 range have additional blue tint applied.以下着色
6、器示例通过顶点着色器输入结构使用了顶点位置和第一纹理坐标。这在网格中调试UV坐标是非常有用的。UV坐标是可见的红色和绿色,坐标以外应用的是取值范围在0到1之间的蓝色值。!Debug/UV 1 Pass Fog Mode Off #pragma fragment frag/ vertex input: position, UVstruct appdata float4 vertex : POSITION; float4 texcoord : TEXCOORD0; float4 uv :v2f vert (appdata v) o.pos = mul( UNITY_MATRIX_MVP, v.ve
7、rtex ); o.uv = float4( v.texcoord.xy, 0, 0 );half4 frag( v2f i ) : COLOR half4 c = frac( i.uv ); if (any(saturate(i.uv) - i.uv) c.b = 0.5; return c; Debug UV1 shader applied to a torus knot model将着色器应用到扣环模型上调式 UV1着色器的效果Similarly, this shader vizualizes the second UV set of the model:类似的,下面这个着色器可视化使用
8、的是第二UV模式:Debug/UV 2 position, second UV float4 texcoord1 : TEXCOORD1; o.uv = float4( v.texcoord1.xy, 0, 0 );Visualizing vertex colors 可视化顶点颜色The following shader uses vertex position and per-vertex colors as vertex shader input (defined in structure appdata).下面这个着色器通过顶点着色器输入结构使用了顶点位置和每个顶点颜色。Debug/Ve
9、rtex color position, color float4 color : o.color = v.color;Debug Colors shader applied to a model that has illumination baked into colors将着色器应用到模型上调试颜色着色器,颜色有光照烘培效果Visualizing normals 可视化法线The following shader uses vertex position and normal as vertex shader input (defined in structure appdata). No
10、rmals X,Y,Z components are visualized as R,G,B colors. Because the normal components are in -1.1 range, we scale and bias them so that the output colors are in displayable 0.1 range.下面这个着色器通过顶点着色器输入结构使用了顶点位置和法线。法线的X,Y,Z分量对应的是颜色的R,G,B。因为法线的取值范围是-1到1,而颜色取值范围是0到1,所以我们在这里使用了一个小技巧来解决这个问题。Debug/Normals po
11、sition, normal float3 normal : NORMAL; o.color.w = 1.0;Debug Normals shader applied to a model. You can see that the model has hard shading edges.将着色器应用到模型上调试法线着色器。 你可以看到模型的边缘有硬阴影。Visualizing tangents and binormals 可视化切线与副法线Tangent and binormal vectors are used for normal mapping. In Unity only the
12、tangent vector is stored in vertices, and binormal is derived from normal and tangent.切线和副法线向量是用在法线贴图上的。在Unity里是只在顶点中存储切线向量的,副法线是通过法线和切线得到的。The following shader uses vertex position and tangent as vertex shader input (defined in structure appdata). Tangent下面这个着色器通过顶点着色器输入结构使用了顶点位置和切线。切线的X,Y,Z分量对应的是颜
13、色的R,G,B。因为切线的取值范围是-1到1,而颜色取值范围是0到1,所以我们在这里使用了一个小技巧来解决这个问题。Debug/Tangents position, tangent float4 tangent : TANGENT; o.color = v.tangent * 0.5 + 0.5;Debug Tangents shader applied to a model.将着色器应用到模型上调试切线(Tangents)着色器。The following shader visualizes binormals. It uses vertex position, normal and tan
14、gent as vertex input. Binormal is calculated from normal and tangent. Just like normal or tangent, it needs to be scaled and biased into a displayable 0.1 range.下面这个着色器是可视化副法线着色器。它通过顶点着色器输入结构使用了顶点位置,法线和切线。副法线是通过法线与切线计算得来。取值范围就像法线或者切线,需要通过缩放与裁减来使颜色最终的颜色值在0到1的区间内。Debug/Binormals position, normal, tang
15、ent / calculate binormal float3 binormal = cross( v.normal, v.tangent.xyz ) * v.tangent.w; o.color.xyz = binormal * 0.5 + 0.5;Debug Binormals shader applied to a model. Pretty!页面最后更新:2012-01-19标签: 着色器语法 ShaderLab Shader 着色器 顶点数据 顶点程序 分类:Components|评论: 0| 翻译: 风里疯语 投资合作请联系ceeger 英文部分版权属Unity公司所有,中文部分Unity圣典 版权所有,未经许可,严禁转载 。浙ICP备10041254号-1
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1