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

Single Pass Stereo Instancing compatibility. #10

Open
electricpuppets opened this issue Jun 17, 2022 · 1 comment
Open

Single Pass Stereo Instancing compatibility. #10

electricpuppets opened this issue Jun 17, 2022 · 1 comment

Comments

@electricpuppets
Copy link

Attempted to rewrite the shader to make it compatible with SinglePass Stereo Rendering. As below, it works in multipass and it also works in the scene camera but not on the VR headset (strange result on the headset, half black half brown jaggedly...Here it is, any suggestions?

Shader "Custom/RenderFeature/KawaseBlur"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
// _offset ("Offset", float) = 0.5
}

SubShader
{
    Tags { "RenderType"="Opaque" }
    LOD 100

    Pass
    {
        CGPROGRAM
        #pragma vertex vert
        #pragma fragment frag
        // make fog work
        #pragma multi_compile_fog

        #include "UnityCG.cginc"

        struct appdata
        {
            float4 vertex : POSITION;
            float2 uv : TEXCOORD0;

            UNITY_VERTEX_INPUT_INSTANCE_ID //Insert
        };

        struct v2f
        {
            float4 uv : TEXCOORD0;
            UNITY_FOG_COORDS(1)
            float4 vertex : SV_POSITION;

            UNITY_VERTEX_OUTPUT_STEREO //Insert
        };

        uniform sampler2D _MainTex2;
        UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex); //Insert
        
        float4 _MainTex_ST;
        float4 _MainTex2_ST;
        float4 _MainTex_TexelSize;
        
        
        float _offset;

        v2f vert (appdata v)
        {
            v2f o;
            UNITY_SETUP_INSTANCE_ID(v); //Insert
            UNITY_INITIALIZE_OUTPUT(v2f, o); //Insert
            UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); //Insert
            o.vertex = UnityObjectToClipPos(v.vertex.xyz);
            float2 worldXY = mul(unity_ObjectToWorld, v.vertex).xy;
            o.uv.xy = TRANSFORM_TEX(worldXY, _MainTex);
            return o;
        }
        


        fixed4 frag (v2f input) : SV_Target
        {
            float2 res = _MainTex_TexelSize.xy;
            float i = _offset;
            UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); //Insert
            fixed4 col = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, input.uv);
            col.rgb = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, UnityStereoScreenSpaceUVAdjust(input.uv, _MainTex_ST)).rgb;
            col.rgb += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, UnityStereoScreenSpaceUVAdjust((input.uv + float2(i, i) * res), _MainTex_ST)).rgb;
            col.rgb += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, UnityStereoScreenSpaceUVAdjust((input.uv + float2(i, -i) * res), _MainTex_ST)).rgb;
            col.rgb += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, UnityStereoScreenSpaceUVAdjust((input.uv + float2(-i, i) * res), _MainTex_ST)).rgb;
            col.rgb += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, UnityStereoScreenSpaceUVAdjust((input.uv + float2(-i, -i) * res), _MainTex_ST)).rgb;
            col.rgb /= 5.0f;
            return col;
        }
        ENDCG
    }
}

}

@raymondscopiclabs
Copy link

Were you able to solve it? Currently attempting to do the same.

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

No branches or pull requests

2 participants