Can anyone tell me how I get this to render in both eyes? Is it even possible? Its such an efficient render I’d love to use it but my game supports VR…and this will only render in the left eye of the headset!
Shader "Custom/InstancedAsteroidShader"
{
Properties
{
_MainTex("Texture", 2D) = "white" {} // Your 2x2 atlas texture.
}
SubShader
{
Tags { "Queue"="AlphaTest" "RenderType"="TransparentCutout" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
#pragma instancing_options assumeuniformscaling
#include "UnityCG.cginc"
// Uniform: the parent's (ring's) local-to-world matrix.
uniform float4x4 _ParentLocalToWorld;
// Buffer holding per-instance (local space) transformation matrices.
StructuredBuffer<float4x4> _Matrices;
// Buffer holding per-instance variant values (0,1,2,3).
StructuredBuffer<uint> _Variants;
sampler2D _MainTex;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
uint instanceID : SV_InstanceID;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert(appdata v)
{
v2f o;
// Get the instance matrix (stored in local space relative to the ring).
float4x4 instanceMatrix = _Matrices[v.instanceID];
// First transform the vertex in local asteroid space.
float4 localPos = mul(instanceMatrix, v.vertex);
// Then convert from ring-local space to world space.
float4 worldPos = mul(_ParentLocalToWorld, localPos);
// Finally, convert to clip space.
o.vertex = mul(UNITY_MATRIX_VP, worldPos);
// Determine the proper UV offset based on the variant.
uint variant = _Variants[v.instanceID];
float2 offset;
if (variant == 0u)
offset = float2(0.0, 0.0);
else if (variant == 1u)
offset = float2(0.5, 0.0);
else if (variant == 2u)
offset = float2(0.0, 0.5);
else // variant == 3u
offset = float2(0.5, 0.5);
// The original UVs are scaled down to 0..0.5 and shifted to the correct quadrant.
o.uv = v.uv * 0.5 + offset;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
// Discard pixels with low alpha (alpha cutoff).
clip(col.a - 0.5);
return col;
}
ENDCG
}
}
}