Skip to content

Make Compatible with Single Pass Instanced Mode #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions Assets/Wireframe/UCLA GameLab Wireframe Shaders.cginc
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
//https://answers.unity.com/questions/1702908/geometry-shader-in-vr-stereo-rendering-mode-single.html

#include "UnityCG.cginc"
#include "UCLA GameLab Wireframe Functions.cginc"

// DATA STRUCTURES //

struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;

UNITY_VERTEX_INPUT_INSTANCE_ID
};

// Vertex to Geometry
struct UCLAGL_v2g
{
float4 pos : POSITION; // vertex position
float2 uv : TEXCOORD0; // vertex uv coordinate

UNITY_VERTEX_INPUT_INSTANCE_ID
};

// Geometry to UCLAGL_fragment
Expand All @@ -15,6 +28,9 @@ struct UCLAGL_g2f
float4 pos : POSITION; // fragment position
float2 uv : TEXCOORD0; // fragment uv coordinate
float3 dist : TEXCOORD1; // distance to each edge of the triangle

UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};

// PARAMETERS //
Expand All @@ -27,11 +43,16 @@ sampler2D _MainTex; // Texture used for the line

// SHADER PROGRAMS //
// Vertex Shader
UCLAGL_v2g UCLAGL_vert(appdata_base v)
UCLAGL_v2g UCLAGL_vert(appdata v)
{
UCLAGL_v2g output;

UNITY_INITIALIZE_OUTPUT( UCLAGL_v2g, output );
UNITY_SETUP_INSTANCE_ID( v );
UNITY_TRANSFER_INSTANCE_ID( v, output );

output.pos = UnityObjectToClipPos(v.vertex);
output.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
output.uv = TRANSFORM_TEX (v.uv, _MainTex);

return output;
}
Expand All @@ -45,18 +66,30 @@ void UCLAGL_geom(triangle UCLAGL_v2g p[3], inout TriangleStream<UCLAGL_g2f> triS
UCLAGL_g2f pIn;

// add the first point
UNITY_INITIALIZE_OUTPUT( UCLAGL_g2f, pIn );
UNITY_SETUP_INSTANCE_ID( p[0] );
UNITY_TRANSFER_INSTANCE_ID( p[0], pIn );
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( pIn );
pIn.pos = p[0].pos;
pIn.uv = p[0].uv;
pIn.dist = float3(dist.x, 0, 0);
triStream.Append(pIn);

// add the second point
UNITY_INITIALIZE_OUTPUT( UCLAGL_g2f, pIn );
UNITY_SETUP_INSTANCE_ID( p[1] );
UNITY_TRANSFER_INSTANCE_ID( p[1], pIn );
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( pIn );
pIn.pos = p[1].pos;
pIn.uv = p[1].uv;
pIn.dist = float3(0, dist.y, 0);
triStream.Append(pIn);

// add the third point
UNITY_INITIALIZE_OUTPUT( UCLAGL_g2f, pIn );
UNITY_SETUP_INSTANCE_ID( p[2] );
UNITY_TRANSFER_INSTANCE_ID( p[2], pIn );
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( pIn );
pIn.pos = p[2].pos;
pIn.uv = p[2].uv;
pIn.dist = float3(0, 0, dist.z);
Expand Down