I have a shader that I’m using in a Hololens 2 project, but I’m realising now that it’s only rendered on one side because it doesn’t support GPU instancing. I have no experience with shaders, but I tried to adjust it as described in the fragment shader example from this page:
This didn’t work though, the objects are still only visible on one eye, but twice with a slight offset.
Can someone help me with that?
Here’s the shader with the adjustments:
Shader "MyShader"
{
Properties
{
....
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent"}
LOD 100
Pass
{
zwrite off
blend one one
cull off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#pragma multi_compile SCAN2_OFF SCAN2_ON
...
struct appdata
{
float4 vertex : POSITION;
float4 normal : NORMAL;
float4 color : COLOR;
float2 uv_main : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
float4 color : COLOR;
float2 uv_main : TEXCOORD0;
float2 scanlines_uv : TEXCOORD1;
float2 scan2_uv : TEXCOORD2;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_DEFINE_INSTANCED_PROP(float4, _Color)
UNITY_DEFINE_INSTANCED_PROP(float4, _RimColor)
UNITY_DEFINE_INSTANCED_PROP(float4, _MainTex_ST)
UNITY_DEFINE_INSTANCED_PROP(float4, _Scanlines_ST)
UNITY_DEFINE_INSTANCED_PROP(float4, _Scan2_ST)
UNITY_INSTANCING_BUFFER_END(Props)
v2f vert (appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, o);
...
return o;
}
fixed4 frag (v2f i) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(i);
fixed4 main = tex2D(_MainTex, i.uv_main) * _Brightness;
...
return UNITY_ACCESS_INSTANCED_PROP(Props, main * max(pri,msk) * rim * fixed4(0.5,0.5,0.5,0.5));
}
ENDCG
}
}
CustomEditor "MyShaderGUI"
}