Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

104 lines
2.9 KiB

Shader "VRTK/OutlineBasic"
{
Properties
{
_OutlineColor("Outline Color", Color) = (1, 0, 0, 1)
_Thickness("Thickness", float) = 1
}
SubShader
{
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
}
// Fill the stencil buffer
Pass
{
Stencil
{
Ref 1
Comp Always
Pass Replace
ZFail Replace
}
ColorMask 0
}
// Draw the outline
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off // On (default) = Ignore lights etc. Should this be a property?
Stencil
{
Ref 0
Comp Equal
}
CGPROGRAM
#pragma vertex vert
#pragma geometry geom
#pragma fragment frag
#include "UnityCG.cginc"
half4 _OutlineColor;
float _Thickness;
struct appdata
{
float4 vertex : POSITION;
};
struct v2g
{
float4 pos : SV_POSITION;
};
v2g vert(appdata IN)
{
v2g OUT;
OUT.pos = UnityObjectToClipPos(IN.vertex);
return OUT;
}
void geom2(v2g start, v2g end, inout TriangleStream<v2g> triStream)
{
float width = _Thickness / 100;
float4 parallel = (end.pos - start.pos) * width;
float4 perpendicular = normalize(float4(parallel.y, -parallel.x, 0, 0)) * width;
float4 v1 = start.pos - parallel;
float4 v2 = end.pos + parallel;
v2g OUT;
OUT.pos = v1 - perpendicular;
triStream.Append(OUT);
OUT.pos = v1 + perpendicular;
triStream.Append(OUT);
OUT.pos = v2 - perpendicular;
triStream.Append(OUT);
OUT.pos = v2 + perpendicular;
triStream.Append(OUT);
}
[maxvertexcount(12)]
void geom(triangle v2g IN[3], inout TriangleStream<v2g> triStream)
{
geom2(IN[0], IN[1], triStream);
geom2(IN[1], IN[2], triStream);
geom2(IN[2], IN[0], triStream);
}
half4 frag(v2g IN) : COLOR
{
_OutlineColor.a = 1;
return _OutlineColor;
}
ENDCG
}
}
FallBack "Diffuse"
}