Commit a7256bb1 authored by Nathan De Castro's avatar Nathan De Castro
Browse files

Cleaned up code and sorted pith detection

parent 2a8caa54
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Rainbow Wireframe
m_Shader: {fileID: 4800000, guid: 2fd7d2ad6e49f5b44ac540005c095ff5, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 5
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _MainTex
second:
m_Texture: {fileID: 2800000, guid: f2aff80574802eb4dabbce2988cb2067, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _Thickness
second: 5
m_Colors:
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
fileFormatVersion: 2
guid: 150603c95ae82bb4a9364677de3f13c1
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Wireframe Cutout Double-Sided
m_Shader: {fileID: 4800000, guid: 2fd7d2ad6e49f5b44ac540005c095ff5, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 5
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _Texture
second:
m_Texture: {fileID: 2800000, guid: f2aff80574802eb4dabbce2988cb2067, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _Thickness
second: 1
m_Colors:
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
fileFormatVersion: 2
guid: b32739538a682ec4ebed92fcaecfca21
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Wireframe Cutout
m_Shader: {fileID: 4800000, guid: 4bfb1e8c9d6a5bb48ba43b94540861d6, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 5
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _Texture
second:
m_Texture: {fileID: 2800000, guid: f2aff80574802eb4dabbce2988cb2067, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _Thickness
second: 1
m_Colors:
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
fileFormatVersion: 2
guid: 8c01d0306d0fd354c90ea755d194993e
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Wireframe Double-Sided
m_Shader: {fileID: 4800000, guid: 0ee0c86dac5512f40a5c118571d81117, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 5
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _Texture
second:
m_Texture: {fileID: 2800000, guid: f2aff80574802eb4dabbce2988cb2067, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _Thickness
second: 1
m_Colors:
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
fileFormatVersion: 2
guid: 097b51d400f87c24193f3686d4e2478f
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Wireframe
m_Shader: {fileID: 4800000, guid: cf65339624d9ffc46bd34050d17c8f58, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 5
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _Texture
second:
m_Texture: {fileID: 2800000, guid: f2aff80574802eb4dabbce2988cb2067, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _Thickness
second: 1
m_Colors:
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
fileFormatVersion: 2
guid: 019466160e4e2f7409f1e582431bf409
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 54f7496149a96ec4e87d82be6ab0b1b8
folderAsset: yes
timeCreated: 1490712099
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
Shader "UCLA Game Lab/Wireframe/Single-Sided Cutout"
{
Properties
{
_Color ("Line Color", Color) = (1,1,1,1)
_MainTex ("Main Texture", 2D) = "white" {}
_Thickness ("Thickness", Float) = 1
}
SubShader
{
Pass
{
Tags { "RenderType"="Opaque" "Queue"="Geometry" }
Blend SrcAlpha OneMinusSrcAlpha
LOD 200
CGPROGRAM
#pragma target 5.0
#include "UnityCG.cginc"
#include "UCLA GameLab Wireframe Functions.cginc"
#pragma vertex vert
#pragma fragment frag
#pragma geometry geom
// Vertex Shader
UCLAGL_v2g vert(appdata_base v)
{
return UCLAGL_vert(v);
}
// Geometry Shader
[maxvertexcount(3)]
void geom(triangle UCLAGL_v2g p[3], inout TriangleStream<UCLAGL_g2f> triStream)
{
UCLAGL_geom( p, triStream);
}
// Fragment Shader
float4 frag(UCLAGL_g2f input) : COLOR
{
float4 col = UCLAGL_frag(input);
if( col.a < 0.5f ) discard;
else col.a = 1.0f;
return col;
}
ENDCG
}
}
}
fileFormatVersion: 2
guid: 4bfb1e8c9d6a5bb48ba43b94540861d6
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
Shader "UCLA Game Lab/Wireframe/Double-Sided Cutout"
{
Properties
{
_Color ("Line Color", Color) = (1,1,1,1)
_MainTex ("Main Texture", 2D) = "white" {}
_Thickness ("Thickness", Float) = 1
}
SubShader
{
Pass
{
Tags { "RenderType"="Opaque" "Queue"="Geometry" }
Blend SrcAlpha OneMinusSrcAlpha
Cull Off
LOD 200
CGPROGRAM
#pragma target 5.0
#include "UnityCG.cginc"
#include "UCLA GameLab Wireframe Functions.cginc"
#pragma vertex vert
#pragma fragment frag
#pragma geometry geom
// Vertex Shader
UCLAGL_v2g vert(appdata_base v)
{
return UCLAGL_vert(v);
}
// Geometry Shader
[maxvertexcount(3)]
void geom(triangle UCLAGL_v2g p[3], inout TriangleStream<UCLAGL_g2f> triStream)
{
UCLAGL_geom( p, triStream);
}
// Fragment Shader
float4 frag(UCLAGL_g2f input) : COLOR
{
float4 col = UCLAGL_frag(input);
if( col.a < 0.5f ) discard;
else col.a = 1.0f;
return col;
}
ENDCG
}
}
}
fileFormatVersion: 2
guid: 2fd7d2ad6e49f5b44ac540005c095ff5
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
Shader "UCLA Game Lab/Wireframe/Double-Sided"
{
Properties
{
_Color ("Line Color", Color) = (1,1,1,1)
_MainTex ("Main Texture", 2D) = "white" {}
_Thickness ("Thickness", Float) = 1
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
// First pass that renders the back faces of the model (cull front faces)
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
Cull Front
LOD 200
CGPROGRAM
#pragma target 5.0
#include "UnityCG.cginc"
#include "UCLA GameLab Wireframe Functions.cginc"
#pragma vertex vert
#pragma fragment frag
#pragma geometry geom
// Vertex Shader
UCLAGL_v2g vert(appdata_base v)
{
return UCLAGL_vert(v);
}
// Geometry Shader
[maxvertexcount(3)]
void geom(triangle UCLAGL_v2g p[3], inout TriangleStream<UCLAGL_g2f> triStream)
{
UCLAGL_geom( p, triStream);
}
// Fragment Shader
float4 frag(UCLAGL_g2f input) : COLOR
{
return UCLAGL_frag(input);
}
ENDCG
}
// Second pass to render the fronts of polygons.
// Guarantees render order of back then front to avoid render artifacts
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
Cull Back
LOD 200
CGPROGRAM
#pragma target 5.0
#include "UnityCG.cginc"
#include "UCLA GameLab Wireframe Functions.cginc"
#pragma vertex vert
#pragma fragment frag
#pragma geometry geom
// Vertex Shader
UCLAGL_v2g vert(appdata_base v)
{
return UCLAGL_vert(v);
}
// Geometry Shader
[maxvertexcount(3)]
void geom(triangle UCLAGL_v2g p[3], inout TriangleStream<UCLAGL_g2f> triStream)
{
UCLAGL_geom( p, triStream);
}
// Fragment Shader
float4 frag(UCLAGL_g2f input) : COLOR
{
return UCLAGL_frag(input);
}
ENDCG
}
}
}
fileFormatVersion: 2
guid: 0ee0c86dac5512f40a5c118571d81117
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
//Algorithms and shaders based on code from this journal
//http://cgg-journal.com/2008-2/06/index.html
#ifndef UCLA_GAMELAB_WIREFRAME
#define UCLA_GAMELAB_WIREFRAME
#include "UnityCG.cginc"
// DATA STRUCTURES //
// Vertex to Geometry
struct UCLAGL_v2g
{
float4 pos : POSITION; // vertex position
float2 uv : TEXCOORD0; // vertex uv coordinate
};
// Geometry to UCLAGL_fragment
struct UCLAGL_g2f
{
float4 pos : POSITION; // fragment position
float2 uv : TEXCOORD0; // fragment uv coordinate
float3 dist : TEXCOORD1; // distance to each edge of the triangle
};
// PARAMETERS //
//float4 _Texture_ST; // For the Main Tex UV transform
float _Thickness = 1; // Thickness of the wireframe line rendering
float4 _Color = {1,1,1,1}; // Color of the line
float4 _MainTex_ST; // For the Main Tex UV transform
sampler2D _MainTex; // Texture used for the line
// SHADER PROGRAMS //
// Vertex Shader
UCLAGL_v2g UCLAGL_vert(appdata_base v)
{
UCLAGL_v2g output;
output.pos = mul(UNITY_MATRIX_MVP, v.vertex);
output.uv = TRANSFORM_TEX (v.texcoord, _MainTex);//v.texcoord;
return output;
}
// Geometry Shader
[maxvertexcount(3)]
void UCLAGL_geom(triangle UCLAGL_v2g p[3], inout TriangleStream<UCLAGL_g2f> triStream)
{
//points in screen space
float2 p0 = _ScreenParams.xy * p[0].pos.xy / p[0].pos.w;
float2 p1 = _ScreenParams.xy * p[1].pos.xy / p[1].pos.w;
float2 p2 = _ScreenParams.xy * p[2].pos.xy / p[2].pos.w;
//edge vectors
float2 v0 = p2 - p1;
float2 v1 = p2 - p0;
float2 v2 = p1 - p0;
//area of the triangle
float area = abs(v1.x*v2.y - v1.y * v2.x);
//values based on distance to the edges
float dist0 = area / length(v0);
float dist1 = area / length(v1);
float dist2 = area / length(v2);
UCLAGL_g2f pIn;
//add the first point
pIn.pos = p[0].pos;
pIn.uv = p[0].uv;
pIn.dist = float3(dist0,0,0);
triStream.Append(pIn);
//add the second point
pIn.pos = p[1].pos;
pIn.uv = p[1].uv;
pIn.dist = float3(0,dist1,0);
triStream.Append(pIn);
//add the third point
pIn.pos = p[2].pos;
pIn.uv = p[2].uv;
pIn.dist = float3(0,0,dist2);
triStream.Append(pIn);
}
// Fragment Shader
float4 UCLAGL_frag(UCLAGL_g2f input) : COLOR
{
//find the smallest distance
float val = min( input.dist.x, min( input.dist.y, input.dist.z));
//calculate power to 2 to thin the line
val = exp2( -1/_Thickness * val * val );
//blend between the lines and the negative space to give illusion of anti aliasing
float4 targetColor = _Color * tex2D( _MainTex, input.uv);
float4 transCol = _Color * tex2D( _MainTex, input.uv);
transCol.a = 0;
return val * targetColor + ( 1 - val ) * transCol;
}
#endif
\ No newline at end of file
fileFormatVersion: 2
guid: fae11a358e6184143864aff7322aa72a
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
Shader "UCLA Game Lab/Wireframe/Single-Sided"
{
Properties
{
_Color ("Line Color", Color) = (1,1,1,1)
_MainTex ("Main Texture", 2D) = "white" {}
_Thickness ("Thickness", Float) = 1
}
SubShader
{
Pass
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
LOD 200