Skip to content

Commit 8839980

Browse files
authored
Merge pull request #393 from thebanjomatic/stereoinstancing
fix(stereo) allowing shaders to work with singlepass
2 parents f25cedc + 64f6d2c commit 8839980

File tree

11 files changed

+197
-150
lines changed

11 files changed

+197
-150
lines changed

Assets/HoloToolkit/Input/Shaders/Cursor.shader

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{
99
Tags { "RenderType"="Opaque" }
1010
LOD 100
11-
ZTest Always
11+
ZTest Always
1212

1313
Pass
1414
{
@@ -21,25 +21,31 @@
2121
struct appdata
2222
{
2323
float4 vertex : POSITION;
24+
UNITY_VERTEX_INPUT_INSTANCE_ID
2425
};
2526

2627
struct v2f
2728
{
2829
float4 vertex : SV_POSITION;
30+
UNITY_VERTEX_OUTPUT_STEREO
2931
};
3032

3133
float4 _Color;
3234

3335
v2f vert (appdata v)
3436
{
37+
UNITY_SETUP_INSTANCE_ID(v);
38+
3539
v2f o;
3640
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
41+
42+
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
3743
return o;
3844
}
3945

4046
fixed4 frag (v2f i) : SV_Target
4147
{
42-
fixed4 col = _Color;
48+
fixed4 col = _Color;
4349
return col;
4450
}
4551
ENDCG

Assets/HoloToolkit/Input/Shaders/CursorShader.shader

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,32 @@ Shader "HoloToolkit/Cursor"
5353
float4 vertex : POSITION;
5454
float4 color : COLOR;
5555
float2 texcoord : TEXCOORD0;
56+
UNITY_VERTEX_INPUT_INSTANCE_ID
5657
};
5758

5859
struct v2f
5960
{
6061
float4 vertex : SV_POSITION;
6162
fixed4 color : COLOR;
6263
half2 texcoord : TEXCOORD0;
64+
UNITY_VERTEX_OUTPUT_STEREO
6365
};
6466

6567
fixed4 _Color;
6668

6769
v2f vert(appdata_t IN)
6870
{
71+
UNITY_SETUP_INSTANCE_ID(IN);
72+
6973
v2f OUT;
7074
OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
7175
OUT.texcoord = IN.texcoord;
7276
#ifdef UNITY_HALF_TEXEL_OFFSET
7377
OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
7478
#endif
7579
OUT.color = IN.color * _Color;
80+
81+
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
7682
return OUT;
7783
}
7884

Assets/HoloToolkit/Input/Shaders/EditorHands.shader

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,32 @@
5353
float4 vertex : POSITION;
5454
float4 color : COLOR;
5555
float2 texcoord : TEXCOORD0;
56+
UNITY_VERTEX_INPUT_INSTANCE_ID
5657
};
5758

5859
struct v2f
5960
{
6061
float4 vertex : SV_POSITION;
6162
fixed4 color : COLOR;
6263
half2 texcoord : TEXCOORD0;
64+
UNITY_VERTEX_OUTPUT_STEREO
6365
};
6466

6567
fixed4 _Color;
6668

6769
v2f vert(appdata_t IN)
6870
{
71+
UNITY_SETUP_INSTANCE_ID(IN);
72+
6973
v2f OUT;
7074
OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
7175
OUT.texcoord = IN.texcoord;
7276
#ifdef UNITY_HALF_TEXEL_OFFSET
7377
OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
7478
#endif
7579
OUT.color = IN.color * _Color;
80+
81+
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
7682
return OUT;
7783
}
7884

Assets/HoloToolkit/SpatialMapping/Shaders/Occlusion.shader

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ Shader "HoloToolkit/Occlusion"
3333
struct v2f
3434
{
3535
float4 pos : SV_POSITION;
36+
UNITY_VERTEX_OUTPUT_STEREO
3637
};
3738

3839
v2f vert(appdata_base v)
3940
{
41+
UNITY_SETUP_INSTANCE_ID(v);
4042
v2f o;
4143
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
44+
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
4245
return o;
4346
}
4447

Assets/HoloToolkit/SpatialMapping/Shaders/Wireframe.shader

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ Shader "HoloToolkit/Wireframe"
3838
struct v2g
3939
{
4040
float4 viewPos : SV_POSITION;
41+
UNITY_VERTEX_OUTPUT_STEREO
4142
};
4243

4344
v2g vert(appdata_base v)
4445
{
46+
UNITY_SETUP_INSTANCE_ID(v);
4547
v2g o;
4648
o.viewPos = mul(UNITY_MATRIX_MVP, v.vertex);
49+
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
4750
return o;
4851
}
4952

@@ -54,6 +57,7 @@ Shader "HoloToolkit/Wireframe"
5457
float4 viewPos : SV_POSITION;
5558
float inverseW : TEXCOORD0;
5659
float3 dist : TEXCOORD1;
60+
UNITY_VERTEX_OUTPUT_STEREO
5761
};
5862

5963
[maxvertexcount(3)]
@@ -70,27 +74,26 @@ Shader "HoloToolkit/Wireframe"
7074
float2 vector2 = point1 - point0;
7175
float area = abs(vector1.x * vector2.y - vector1.y * vector2.x);
7276

77+
float3 distScale[3];
78+
distScale[0] = float3(area / length(vector0), 0, 0);
79+
distScale[1] = float3(0, area / length(vector1), 0);
80+
distScale[2] = float3(0, 0, area / length(vector2));
81+
7382
float wireScale = 800 - _WireThickness;
7483

7584
// Output each original vertex with its distance to the opposing line defined
7685
// by the other two vertices.
77-
7886
g2f o;
7987

80-
o.viewPos = i[0].viewPos;
81-
o.inverseW = 1.0 / o.viewPos.w;
82-
o.dist = float3(area / length(vector0), 0, 0) * o.viewPos.w * wireScale;
83-
triStream.Append(o);
84-
85-
o.viewPos = i[1].viewPos;
86-
o.inverseW = 1.0 / o.viewPos.w;
87-
o.dist = float3(0, area / length(vector1), 0) * o.viewPos.w * wireScale;
88-
triStream.Append(o);
89-
90-
o.viewPos = i[2].viewPos;
91-
o.inverseW = 1.0 / o.viewPos.w;
92-
o.dist = float3(0, 0, area / length(vector2)) * o.viewPos.w * wireScale;
93-
triStream.Append(o);
88+
[unroll]
89+
for (uint idx = 0; idx < 3; ++idx)
90+
{
91+
o.viewPos = i[idx].viewPos;
92+
o.inverseW = 1.0 / o.viewPos.w;
93+
o.dist = distScale[idx] * o.viewPos.w * wireScale;
94+
UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(i[idx], o);
95+
triStream.Append(o);
96+
}
9497
}
9598

9699
float4 frag(g2f i) : COLOR

Assets/HoloToolkit/SpatialUnderstanding/Materials/SpatialMappingSurface.shader

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ Shader "HoloToolkit/SpatialUnderstanding/Mapping"
3737
struct v2g
3838
{
3939
float4 viewPos : SV_POSITION;
40+
UNITY_VERTEX_OUTPUT_STEREO
4041
};
4142

4243
v2g vert(appdata_base v)
4344
{
45+
UNITY_SETUP_INSTANCE_ID(v);
4446
v2g o;
4547
o.viewPos = mul(UNITY_MATRIX_MVP, v.vertex);
48+
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
4649
return o;
4750
}
4851

@@ -53,6 +56,7 @@ Shader "HoloToolkit/SpatialUnderstanding/Mapping"
5356
float4 viewPos : SV_POSITION;
5457
float inverseW : TEXCOORD0;
5558
float3 dist : TEXCOORD1;
59+
UNITY_VERTEX_OUTPUT_STEREO
5660
};
5761

5862
[maxvertexcount(3)]
@@ -69,27 +73,27 @@ Shader "HoloToolkit/SpatialUnderstanding/Mapping"
6973
float2 vector2 = point1 - point0;
7074
float area = abs(vector1.x * vector2.y - vector1.y * vector2.x);
7175

76+
float3 distScale[3];
77+
distScale[0] = float3(area / length(vector0), 0, 0);
78+
distScale[1] = float3(0, area / length(vector1), 0);
79+
distScale[2] = float3(0, 0, area / length(vector2));
80+
7281
float wireScale = 800 - _WireThickness;
7382

7483
// Output each original vertex with its distance to the opposing line defined
7584
// by the other two vertices.
7685

7786
g2f o;
7887

79-
o.viewPos = i[0].viewPos;
80-
o.inverseW = 1.0 / o.viewPos.w;
81-
o.dist = float3(area / length(vector0), 0, 0) * o.viewPos.w * wireScale;
82-
triStream.Append(o);
83-
84-
o.viewPos = i[1].viewPos;
85-
o.inverseW = 1.0 / o.viewPos.w;
86-
o.dist = float3(0, area / length(vector1), 0) * o.viewPos.w * wireScale;
87-
triStream.Append(o);
88-
89-
o.viewPos = i[2].viewPos;
90-
o.inverseW = 1.0 / o.viewPos.w;
91-
o.dist = float3(0, 0, area / length(vector2)) * o.viewPos.w * wireScale;
92-
triStream.Append(o);
88+
[unroll]
89+
for (uint idx = 0; idx < 3; ++idx)
90+
{
91+
o.viewPos = i[idx].viewPos;
92+
o.inverseW = 1.0 / o.viewPos.w;
93+
o.dist = distScale[idx] * o.viewPos.w * wireScale;
94+
UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(i[idx], o);
95+
triStream.Append(o);
96+
}
9397
}
9498

9599
float4 frag(g2f i) : COLOR

0 commit comments

Comments
 (0)