AR camera with white overlay with Unity and ARCore












0















I'm Using Unity and ARCore. Problem is, when i use the gamma color space the AR Camera works fine. but, using the Linear Color Space It creates a white overlay on top of the AR camera. I must have to use the Linear Color Space. What should i do ?










share|improve this question



























    0















    I'm Using Unity and ARCore. Problem is, when i use the gamma color space the AR Camera works fine. but, using the Linear Color Space It creates a white overlay on top of the AR camera. I must have to use the Linear Color Space. What should i do ?










    share|improve this question

























      0












      0








      0


      2






      I'm Using Unity and ARCore. Problem is, when i use the gamma color space the AR Camera works fine. but, using the Linear Color Space It creates a white overlay on top of the AR camera. I must have to use the Linear Color Space. What should i do ?










      share|improve this question














      I'm Using Unity and ARCore. Problem is, when i use the gamma color space the AR Camera works fine. but, using the Linear Color Space It creates a white overlay on top of the AR camera. I must have to use the Linear Color Space. What should i do ?







      unity3d arcore arcamera






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 '18 at 4:30









      RinkuRinku

      164




      164
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Ok, Solved this. I've to make a custom shader for the arcamera backgound.
          Create(or copy the arbackground material) a material and assign the bellow shader and replace with ar material.



          Shader "ARCore/ARBackground(Linear)"
          {
          Properties {
          _MainTex ("Texture", 2D) = "white" {}
          _UvTopLeftRight ("UV of top corners", Vector) = (0, 1, 1, 1)
          _UvBottomLeftRight ("UV of bottom corners", Vector) = (0 , 0, 1, 0)
          }

          // For GLES3
          SubShader
          {
          Pass
          {
          ZWrite Off

          GLSLPROGRAM

          #pragma only_renderers gles3

          #ifdef SHADER_API_GLES3
          #extension GL_OES_EGL_image_external_essl3 : require
          #endif

          uniform vec4 _UvTopLeftRight;
          uniform vec4 _UvBottomLeftRight;

          #ifdef VERTEX

          varying vec2 textureCoord;

          void main()
          {
          #ifdef SHADER_API_GLES3
          vec2 uvTop = mix(_UvTopLeftRight.xy, _UvTopLeftRight.zw, gl_MultiTexCoord0.x);
          vec2 uvBottom = mix(_UvBottomLeftRight.xy, _UvBottomLeftRight.zw, gl_MultiTexCoord0.x);
          textureCoord = mix(uvTop, uvBottom, gl_MultiTexCoord0.y);

          gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
          #endif
          }

          #endif

          #ifdef FRAGMENT
          varying vec2 textureCoord;
          uniform samplerExternalOES _MainTex;

          void main()
          {
          #ifdef SHADER_API_GLES3
          gl_FragColor = texture(_MainTex, textureCoord);
          //gamma to linear conversion
          gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(2.2));
          #endif
          }

          #endif

          ENDGLSL
          }
          }

          Subshader
          {
          Pass
          {
          ZWrite Off

          CGPROGRAM

          #pragma exclude_renderers gles3
          #pragma vertex vert
          #pragma fragment frag

          #include "UnityCG.cginc"

          uniform float4 _UvTopLeftRight;
          uniform float4 _UvBottomLeftRight;

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

          struct v2f
          {
          float2 uv : TEXCOORD0;
          float4 vertex : SV_POSITION;
          };

          v2f vert(appdata v)
          {
          float2 uvTop = lerp(_UvTopLeftRight.xy, _UvTopLeftRight.zw, v.uv.x);
          float2 uvBottom = lerp(_UvBottomLeftRight.xy, _UvBottomLeftRight.zw, v.uv.x);

          v2f o;
          o.vertex = UnityObjectToClipPos(v.vertex);
          o.uv = lerp(uvTop, uvBottom, v.uv.y);

          // Instant preview's texture is transformed differently.
          o.uv = o.uv.yx;
          o.uv.x = 1.0 - o.uv.x;

          return o;
          }

          sampler2D _MainTex;

          fixed4 frag(v2f i) : SV_Target
          {
          return tex2D(_MainTex, i.uv);
          }
          ENDCG
          }
          }

          FallBack Off
          }





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386254%2far-camera-with-white-overlay-with-unity-and-arcore%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Ok, Solved this. I've to make a custom shader for the arcamera backgound.
            Create(or copy the arbackground material) a material and assign the bellow shader and replace with ar material.



            Shader "ARCore/ARBackground(Linear)"
            {
            Properties {
            _MainTex ("Texture", 2D) = "white" {}
            _UvTopLeftRight ("UV of top corners", Vector) = (0, 1, 1, 1)
            _UvBottomLeftRight ("UV of bottom corners", Vector) = (0 , 0, 1, 0)
            }

            // For GLES3
            SubShader
            {
            Pass
            {
            ZWrite Off

            GLSLPROGRAM

            #pragma only_renderers gles3

            #ifdef SHADER_API_GLES3
            #extension GL_OES_EGL_image_external_essl3 : require
            #endif

            uniform vec4 _UvTopLeftRight;
            uniform vec4 _UvBottomLeftRight;

            #ifdef VERTEX

            varying vec2 textureCoord;

            void main()
            {
            #ifdef SHADER_API_GLES3
            vec2 uvTop = mix(_UvTopLeftRight.xy, _UvTopLeftRight.zw, gl_MultiTexCoord0.x);
            vec2 uvBottom = mix(_UvBottomLeftRight.xy, _UvBottomLeftRight.zw, gl_MultiTexCoord0.x);
            textureCoord = mix(uvTop, uvBottom, gl_MultiTexCoord0.y);

            gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
            #endif
            }

            #endif

            #ifdef FRAGMENT
            varying vec2 textureCoord;
            uniform samplerExternalOES _MainTex;

            void main()
            {
            #ifdef SHADER_API_GLES3
            gl_FragColor = texture(_MainTex, textureCoord);
            //gamma to linear conversion
            gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(2.2));
            #endif
            }

            #endif

            ENDGLSL
            }
            }

            Subshader
            {
            Pass
            {
            ZWrite Off

            CGPROGRAM

            #pragma exclude_renderers gles3
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            uniform float4 _UvTopLeftRight;
            uniform float4 _UvBottomLeftRight;

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

            struct v2f
            {
            float2 uv : TEXCOORD0;
            float4 vertex : SV_POSITION;
            };

            v2f vert(appdata v)
            {
            float2 uvTop = lerp(_UvTopLeftRight.xy, _UvTopLeftRight.zw, v.uv.x);
            float2 uvBottom = lerp(_UvBottomLeftRight.xy, _UvBottomLeftRight.zw, v.uv.x);

            v2f o;
            o.vertex = UnityObjectToClipPos(v.vertex);
            o.uv = lerp(uvTop, uvBottom, v.uv.y);

            // Instant preview's texture is transformed differently.
            o.uv = o.uv.yx;
            o.uv.x = 1.0 - o.uv.x;

            return o;
            }

            sampler2D _MainTex;

            fixed4 frag(v2f i) : SV_Target
            {
            return tex2D(_MainTex, i.uv);
            }
            ENDCG
            }
            }

            FallBack Off
            }





            share|improve this answer




























              1














              Ok, Solved this. I've to make a custom shader for the arcamera backgound.
              Create(or copy the arbackground material) a material and assign the bellow shader and replace with ar material.



              Shader "ARCore/ARBackground(Linear)"
              {
              Properties {
              _MainTex ("Texture", 2D) = "white" {}
              _UvTopLeftRight ("UV of top corners", Vector) = (0, 1, 1, 1)
              _UvBottomLeftRight ("UV of bottom corners", Vector) = (0 , 0, 1, 0)
              }

              // For GLES3
              SubShader
              {
              Pass
              {
              ZWrite Off

              GLSLPROGRAM

              #pragma only_renderers gles3

              #ifdef SHADER_API_GLES3
              #extension GL_OES_EGL_image_external_essl3 : require
              #endif

              uniform vec4 _UvTopLeftRight;
              uniform vec4 _UvBottomLeftRight;

              #ifdef VERTEX

              varying vec2 textureCoord;

              void main()
              {
              #ifdef SHADER_API_GLES3
              vec2 uvTop = mix(_UvTopLeftRight.xy, _UvTopLeftRight.zw, gl_MultiTexCoord0.x);
              vec2 uvBottom = mix(_UvBottomLeftRight.xy, _UvBottomLeftRight.zw, gl_MultiTexCoord0.x);
              textureCoord = mix(uvTop, uvBottom, gl_MultiTexCoord0.y);

              gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
              #endif
              }

              #endif

              #ifdef FRAGMENT
              varying vec2 textureCoord;
              uniform samplerExternalOES _MainTex;

              void main()
              {
              #ifdef SHADER_API_GLES3
              gl_FragColor = texture(_MainTex, textureCoord);
              //gamma to linear conversion
              gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(2.2));
              #endif
              }

              #endif

              ENDGLSL
              }
              }

              Subshader
              {
              Pass
              {
              ZWrite Off

              CGPROGRAM

              #pragma exclude_renderers gles3
              #pragma vertex vert
              #pragma fragment frag

              #include "UnityCG.cginc"

              uniform float4 _UvTopLeftRight;
              uniform float4 _UvBottomLeftRight;

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

              struct v2f
              {
              float2 uv : TEXCOORD0;
              float4 vertex : SV_POSITION;
              };

              v2f vert(appdata v)
              {
              float2 uvTop = lerp(_UvTopLeftRight.xy, _UvTopLeftRight.zw, v.uv.x);
              float2 uvBottom = lerp(_UvBottomLeftRight.xy, _UvBottomLeftRight.zw, v.uv.x);

              v2f o;
              o.vertex = UnityObjectToClipPos(v.vertex);
              o.uv = lerp(uvTop, uvBottom, v.uv.y);

              // Instant preview's texture is transformed differently.
              o.uv = o.uv.yx;
              o.uv.x = 1.0 - o.uv.x;

              return o;
              }

              sampler2D _MainTex;

              fixed4 frag(v2f i) : SV_Target
              {
              return tex2D(_MainTex, i.uv);
              }
              ENDCG
              }
              }

              FallBack Off
              }





              share|improve this answer


























                1












                1








                1







                Ok, Solved this. I've to make a custom shader for the arcamera backgound.
                Create(or copy the arbackground material) a material and assign the bellow shader and replace with ar material.



                Shader "ARCore/ARBackground(Linear)"
                {
                Properties {
                _MainTex ("Texture", 2D) = "white" {}
                _UvTopLeftRight ("UV of top corners", Vector) = (0, 1, 1, 1)
                _UvBottomLeftRight ("UV of bottom corners", Vector) = (0 , 0, 1, 0)
                }

                // For GLES3
                SubShader
                {
                Pass
                {
                ZWrite Off

                GLSLPROGRAM

                #pragma only_renderers gles3

                #ifdef SHADER_API_GLES3
                #extension GL_OES_EGL_image_external_essl3 : require
                #endif

                uniform vec4 _UvTopLeftRight;
                uniform vec4 _UvBottomLeftRight;

                #ifdef VERTEX

                varying vec2 textureCoord;

                void main()
                {
                #ifdef SHADER_API_GLES3
                vec2 uvTop = mix(_UvTopLeftRight.xy, _UvTopLeftRight.zw, gl_MultiTexCoord0.x);
                vec2 uvBottom = mix(_UvBottomLeftRight.xy, _UvBottomLeftRight.zw, gl_MultiTexCoord0.x);
                textureCoord = mix(uvTop, uvBottom, gl_MultiTexCoord0.y);

                gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
                #endif
                }

                #endif

                #ifdef FRAGMENT
                varying vec2 textureCoord;
                uniform samplerExternalOES _MainTex;

                void main()
                {
                #ifdef SHADER_API_GLES3
                gl_FragColor = texture(_MainTex, textureCoord);
                //gamma to linear conversion
                gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(2.2));
                #endif
                }

                #endif

                ENDGLSL
                }
                }

                Subshader
                {
                Pass
                {
                ZWrite Off

                CGPROGRAM

                #pragma exclude_renderers gles3
                #pragma vertex vert
                #pragma fragment frag

                #include "UnityCG.cginc"

                uniform float4 _UvTopLeftRight;
                uniform float4 _UvBottomLeftRight;

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

                struct v2f
                {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
                };

                v2f vert(appdata v)
                {
                float2 uvTop = lerp(_UvTopLeftRight.xy, _UvTopLeftRight.zw, v.uv.x);
                float2 uvBottom = lerp(_UvBottomLeftRight.xy, _UvBottomLeftRight.zw, v.uv.x);

                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = lerp(uvTop, uvBottom, v.uv.y);

                // Instant preview's texture is transformed differently.
                o.uv = o.uv.yx;
                o.uv.x = 1.0 - o.uv.x;

                return o;
                }

                sampler2D _MainTex;

                fixed4 frag(v2f i) : SV_Target
                {
                return tex2D(_MainTex, i.uv);
                }
                ENDCG
                }
                }

                FallBack Off
                }





                share|improve this answer













                Ok, Solved this. I've to make a custom shader for the arcamera backgound.
                Create(or copy the arbackground material) a material and assign the bellow shader and replace with ar material.



                Shader "ARCore/ARBackground(Linear)"
                {
                Properties {
                _MainTex ("Texture", 2D) = "white" {}
                _UvTopLeftRight ("UV of top corners", Vector) = (0, 1, 1, 1)
                _UvBottomLeftRight ("UV of bottom corners", Vector) = (0 , 0, 1, 0)
                }

                // For GLES3
                SubShader
                {
                Pass
                {
                ZWrite Off

                GLSLPROGRAM

                #pragma only_renderers gles3

                #ifdef SHADER_API_GLES3
                #extension GL_OES_EGL_image_external_essl3 : require
                #endif

                uniform vec4 _UvTopLeftRight;
                uniform vec4 _UvBottomLeftRight;

                #ifdef VERTEX

                varying vec2 textureCoord;

                void main()
                {
                #ifdef SHADER_API_GLES3
                vec2 uvTop = mix(_UvTopLeftRight.xy, _UvTopLeftRight.zw, gl_MultiTexCoord0.x);
                vec2 uvBottom = mix(_UvBottomLeftRight.xy, _UvBottomLeftRight.zw, gl_MultiTexCoord0.x);
                textureCoord = mix(uvTop, uvBottom, gl_MultiTexCoord0.y);

                gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
                #endif
                }

                #endif

                #ifdef FRAGMENT
                varying vec2 textureCoord;
                uniform samplerExternalOES _MainTex;

                void main()
                {
                #ifdef SHADER_API_GLES3
                gl_FragColor = texture(_MainTex, textureCoord);
                //gamma to linear conversion
                gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(2.2));
                #endif
                }

                #endif

                ENDGLSL
                }
                }

                Subshader
                {
                Pass
                {
                ZWrite Off

                CGPROGRAM

                #pragma exclude_renderers gles3
                #pragma vertex vert
                #pragma fragment frag

                #include "UnityCG.cginc"

                uniform float4 _UvTopLeftRight;
                uniform float4 _UvBottomLeftRight;

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

                struct v2f
                {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
                };

                v2f vert(appdata v)
                {
                float2 uvTop = lerp(_UvTopLeftRight.xy, _UvTopLeftRight.zw, v.uv.x);
                float2 uvBottom = lerp(_UvBottomLeftRight.xy, _UvBottomLeftRight.zw, v.uv.x);

                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = lerp(uvTop, uvBottom, v.uv.y);

                // Instant preview's texture is transformed differently.
                o.uv = o.uv.yx;
                o.uv.x = 1.0 - o.uv.x;

                return o;
                }

                sampler2D _MainTex;

                fixed4 frag(v2f i) : SV_Target
                {
                return tex2D(_MainTex, i.uv);
                }
                ENDCG
                }
                }

                FallBack Off
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 '18 at 6:15









                RinkuRinku

                164




                164
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386254%2far-camera-with-white-overlay-with-unity-and-arcore%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud

                    Zucchini