BarycentricWireframeUv1

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Reverted edits by Joseph05408 (Talk); changed back to last version by NCarter)
(language edit, I know glsl is not shaderlab, but still...)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The following shader assumes that you have mesh.uv1 set to barycentric uvs. You can set the line width, line color, and grid color.
+
The following shader assumes that you have mesh.uv set to barycentric uvs. You can set the line width, line color, and grid color.
  
 
==C#==
 
==C#==
<csharp>
+
<syntaxhighlight lang="csharp">
 
public Vector2[] GetBarycentricFixed()
 
public Vector2[] GetBarycentricFixed()
 
{
 
{
Line 20: Line 20:
 
return uvs;
 
return uvs;
 
}
 
}
</csharp>
+
</syntaxhighlight>
  
 
==ShaderLab - BarycentricWireframeUv1.shader==
 
==ShaderLab - BarycentricWireframeUv1.shader==
<shaderlab>
+
<syntaxhighlight lang="glsl">
 
Shader "BarycentricWireframeUv1" {
 
Shader "BarycentricWireframeUv1" {
 
Properties {
 
Properties {
Line 89: Line 89:
 
Fallback "Vertex Colored", 1
 
Fallback "Vertex Colored", 1
 
}
 
}
</shaderlab>
+
</syntaxhighlight>

Latest revision as of 17:51, 20 March 2015

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

[edit] C#

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

[edit] ShaderLab - BarycentricWireframeUv1.shader

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
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox