BarycentricWireframeUv1

From Unify Community Wiki
Revision as of 19:27, 19 October 2009 by NCarter (Talk | contribs)

Jump to: navigation, search

The following shader assumes that you have mesh.uv1 set to barycentric uvs. You can set the line width, line color, and grid color.

C#

<csharp> 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; } </csharp>

ShaderLab - BarycentricWireframeUv1.shader

<shaderlab> 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

  1. pragma vertex vert
  2. pragma fragment frag
  3. 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 } </shaderlab>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox