Search Unity

Resolved AR Rendering culls randomly

Discussion in 'AR' started by d4n3x, May 18, 2021.

  1. d4n3x

    d4n3x

    Joined:
    Jan 23, 2019
    Posts:
    24
    Dear Community,

    after long research and a lot of trial and error I hope somebody can give me a hint on my problem from an other viewpoint.

    The problem is the following:

    I have an AR - App where you are able to place some kind of fabrics in the room. There is one case where 2 fabrics(both semi transparent) are placed over each other. Here is where the problem kicks in. At the beginning both are displayed correctly - but when they both are moved(in fact the area where they are displayed gets smaller), suddenly the one in the back disappears and seems to be culled by the nearer one. I attached 2 pictures where you can see the effect.

    This is how it first looks:
    img_working.jpg
    img_working.jpg
    You can clearly see the other fabric if you look on the more white parts.

    And this shows how it looks after cropping the display area a bit:
    img_not_working.jpg
    img_not_working.jpg
    Here you can see that the backside fabric is no longer visible trough the front one. Only the parts on the left side which are not covered by the front fabric are still visible.

    Since the backside fabric is still active and somehow visible on the side I thought of a culling problem.
    I tried disabling dynamic Culling for the meshes, disabled culling on the camera, changed transparency sort order in the settings to 'perspective', disabled HDR on camera since this had some effect on the editor but doesn't seem on iPad.

    Also attached is the code for the shader of the semi-transparent fabrics as there is maybe something I missed.

    I hope that somebody has an idea or just a hint what could be the problem here since I am clearly running out of ideas.


    Shader "RGBplusAFalse" {
    Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    _AlphaTex ("AlphaTex (R)", 2D) = "black" {}
    _Blend ("Blend", Range (0, 1.2) ) = 1.0
    }

    SubShader {
    Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    LOD 300
    // extra pass that renders to depth buffer only
    Pass {
    ZWrite On
    ColorMask 0
    }

    // paste in forward rendering passes from Transparent/Diffuse
    UsePass "Transparent/Diffuse/FORWARD"
    CGPROGRAM
    #pragma surface surf Lambert alpha:fade

    sampler2D _MainTex;
    sampler2D _AlphaTex;
    fixed4 _Color;
    float _Blend;

    struct Input {
    float2 uv_MainTex;
    };

    void surf (Input IN, inout SurfaceOutput o) {
    fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    fixed4 alph = tex2D(_AlphaTex, IN.uv_MainTex);
    o.Albedo = c.rgb;

    o.Alpha = (1 - alph.r) * _Blend;

    }
    ENDCG
    }

    Fallback "Legacy Shaders/Transparent/Diffuse"
    }
     
    Last edited: May 25, 2021
    felixgruber likes this.
  2. d4n3x

    d4n3x

    Joined:
    Jan 23, 2019
    Posts:
    24
    felixgruber likes this.