BarycentricWireframeUv1
From Unify Community Wiki
Revision as of 18:24, 17 January 2009 by Tgraupmann (Talk | contribs)
The following shader assumes that you have mesh.uv1 set to barycentric uvs. You can set the line width, line color, and grid color.
public Vector2[] GetBarycentricFixed() { Vector2[] uvs = new Vector2[4]; const int topLeft = 0; const int topRight = 1; const int bottomLeft = 2; const int bottomRight = 3; uvs[topLeft] = new Vector2(0,0); uvs[topRight] = new Vector2(1,0); uvs[bottomLeft] = new Vector2(0,1); uvs[bottomRight] = new Vector2(1,1); return uvs; }
Shader "BarycentricWireframeUv1" { Properties { _LineColor ("Line Color", Color) = (1,1,1,1) _GridColor ("Grid Color", Color) = (0,0,0,0) _LineWidth ("Line Width", float) = 0.1 } SubShader { Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" uniform float4 _LineColor; uniform float4 _GridColor; uniform float _LineWidth; // vertex input: position, uv1, uv2 struct appdata { float4 vertex : POSITION; float4 texcoord1 : TEXCOORD1; float4 color : COLOR; }; struct v2f { float4 pos : POSITION; float4 texcoord1 : TEXCOORD1; float4 color : COLOR; }; v2f vert (appdata v) { v2f o; o.pos = mul( glstate.matrix.mvp, v.vertex); o.texcoord1 = v.texcoord1; o.color = v.color; return o; } float4 frag(v2f i ) : COLOR { if (i.texcoord1.x < _LineWidth || i.texcoord1.y < _LineWidth) { return _LineColor; } if ((i.texcoord1.x - i.texcoord1.y) < _LineWidth && (i.texcoord1.y - i.texcoord1.x) < _LineWidth) { return _LineColor; } else { return _GridColor; } } ENDCG } } Fallback "Vertex Colored", 1 }