Skip to content
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

Shapes2D doesn't work with VR with single pass instanced #9

Open
all-iver opened this issue Jul 14, 2020 · 1 comment
Open

Shapes2D doesn't work with VR with single pass instanced #9

all-iver opened this issue Jul 14, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@all-iver
Copy link
Owner

But according to a user it can be made to work easily by following the instructions on this page: https://docs.unity3d.com/Manual/SinglePassInstancing.html

@all-iver all-iver added the enhancement New feature or request label Jul 14, 2020
@MathiasWorm
Copy link

MathiasWorm commented Feb 22, 2024

thank @all-iver

the solution looks like that:

open your shapes.shader file and insert the lines flagged with //Inserted

struct appdata_t {
    float4 vertex : POSITION;
    float4 color : COLOR;
    float2 texcoord : TEXCOORD0;
    UNITY_VERTEX_INPUT_INSTANCE_ID  // Inserted
    };
            
struct v2f {
    float4 pos : SV_POSITION;
    float2 uv : TEXCOORD0;
    float4 modelPos : TEXCOORD1;
    fixed4 color : COLOR;

    UNITY_VERTEX_OUTPUT_STEREO  // Inserted
    };

v2f vert(appdata_t v) {
    v2f o;

    UNITY_SETUP_INSTANCE_ID(v);     // Inserted
    UNITY_INITIALIZE_OUTPUT(v2f, o);    // Inserted
    UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);   // Inserted

    o.pos = UnityObjectToClipPos(v.vertex);
    // translate input uv coords (which are from 0 - 1 on either dimension) to something more 
    // useful (-0.5 to 0.5).
    o.uv = v.texcoord.xy - 0.5;
    o.modelPos = v.vertex;
    // hijack modelPos.z to be distance from camera plane since it 
    // isn't being used for anything else.  used for pixel size.
    o.modelPos.z = -UnityObjectToViewPos(v.vertex).z;
    // for Unity versions < 5.4.0f3
    // o.modelPos.z = -mul(UNITY_MATRIX_MV, v.vertex).z;
    o.color = v.color;
    return o;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants