BarycentricWireframeUv1

From Unify Community Wiki
Revision as of 21:56, 17 January 2012 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#

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

ShaderLab - BarycentricWireframeUv1.shader

Invalid language.

You need to specify a language like this: <source lang="html4strict">...</source>

Supported languages for syntax highlighting:

4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, asm, asp, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, oobas, oracle11, oracle8, oxygene, oz, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, python, q, qbasic, rails, rebol, reg, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, uscript, vala, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic


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