cancel
Showing results for 
Search instead for 
Did you mean: 

wireframe shader issue only in Quest 2 [Unity]

Carpy
Level 2
So I have a wireframe shader that is working correctly in Quest 1 and multiple other platforms, however, in Quest 2 only one eye renders.

Could anyone assist?, this of course only happens in multi-view  (single pass) rendering

here is the code:

Shader "Custom/WireframeTest"
{
Properties
{
_DispTex("Disp Texture", 2D) = "gray" {}
_Displacement("Displacement", Range(0, 1.0)) = 0.3
_Offset("Offset", Vector) = (0,0,0,0)
_WireColor("WireColor", Color) = (1,0,0,1)
_Color("Color", Color) = (1,1,1,1)
[Enum(Off,0,Back,1,Front,2)] _ShowBackfaces("Cull", Int) = 1
}
SubShader
{
Tags{ "Queue" = "Transparent"  "IgnoreProjector" = "True" "RenderType" = "Transparent" }

Pass
{
Blend SrcAlpha OneMinusSrcAlpha
ZTest Less
ZWrite Off
CGPROGRAM
#include "UnityCG.cginc"
#pragma target 5.0
#pragma vertex vert
#pragma geometry geom
#pragma fragment frag
#pragma multi_compile UseVertexColor_ON UseVertexColor_OFF

half4 _WireColor, _Color;

struct appdata {
float4 vertex : POSITION;
float4 color: COLOR;
float4 tangent : TANGENT;
float3 normal : NORMAL;
float2 texcoord : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct v2g
{
float4 pos : SV_POSITION;
float4 color: COLOR;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct g2f
{
float4 pos : SV_POSITION;
float4 color: COLOR;
float2 uv : TEXCOORD0;
float3 dist : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
};

sampler2D _DispTex;
float _Displacement;
float4 _Offset;

v2g vert(appdata v)
{
v2g OUT;

UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, OUT);

float d = tex2Dlod(_DispTex, float4(v.texcoord1.x + _Offset.x, v.texcoord1.y + _Offset.y, 0, 0)).r * _Displacement;
v.vertex.xyz += v.normal * d;
OUT.pos = UnityObjectToClipPos(v.vertex);
OUT.color = v.color;
OUT.uv = v.texcoord; // The UVs aren't used in this shader but are included in case you want to use them.

return OUT;
}

[maxvertexcount(3)]
void geom(triangle v2g IN[3], inout TriangleStream<g2f> triStream)
{
UNITY_SETUP_INSTANCE_ID(IN[0]);
UNITY_SETUP_INSTANCE_ID(IN[1]);
UNITY_SETUP_INSTANCE_ID(IN[2]);

float2 WIN_SCALE = float2(_ScreenParams.x / 1.5, _ScreenParams.y / 1.5);
// Frag position
float2 p0 = WIN_SCALE * IN[0].pos.xy / IN[0].pos.w;
float2 p1 = WIN_SCALE * IN[1].pos.xy / IN[1].pos.w;
float2 p2 = WIN_SCALE * IN[2].pos.xy / IN[2].pos.w;

// Barycentric position
float2 v0 = p2 - p1;
float2 v1 = p2 - p0;
float2 v2 = p1 - p0;

// Triangles area
float area = abs(v1.x*v2.y - v1.y * v2.x);

g2f OUT;
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);

OUT.pos = IN[0].pos;
OUT.color = IN[0].color;
OUT.uv = IN[0].uv;
OUT.dist = float3(area / length(v0),0,0);
triStream.Append(OUT);

OUT.pos = IN[1].pos;
OUT.color = IN[1].color;
OUT.uv = IN[1].uv;
OUT.dist = float3(0,area / length(v1),0);
triStream.Append(OUT);

OUT.pos = IN[2].pos;
OUT.color = IN[2].color;
OUT.uv = IN[2].uv;
OUT.dist = float3(0,0,area / length(v2));
triStream.Append(OUT);
}

half4 frag(g2f IN) : COLOR
{
// Distance of frag from triangles center
float d = min(IN.dist.x, min(IN.dist.y, IN.dist.z));
// Fade based on dist from center
float I = exp2(-1 * d*d);

#if UseVertexColor_OFF
return lerp(_Color, _WireColor, I);
#else 
return lerp(_Color * IN.color, _WireColor * IN.color, I); 
#endif

}

ENDCG
}

}
FallBack "Transparent/VertexLit"
}

1 REPLY 1

EndritP
Level 2
I don't know about your problem but I'm also having a shader issue (only in quest 2)