Android AR 眼镜上 Vuforia 的 VideoBackground Shader 中的 UV 坐标翻转和颜色问题

问题描述 投票:0回答:1

我遇到了以下问题:

当我使用原始着色器代码时,AR 眼镜相机的输出是反转的。我尝试简单地翻转 UV 坐标,但生成的图像变成灰度并具有某种重影效果。

然后我继续修改着色器,图像方向变得正确,并且重影消失了。然而,输出图像完全变成红色。有谁知道如何将输出图像恢复为全彩?

我对着色器编程不熟悉。 将 Unity 编辑器与我的笔记本电脑相机一起使用时,输出图像的颜色是正确的。

这是我的代码:

Shader "Vuforia/Built-In/VideoBackground" {
    // Used to render the Vuforia Video Background

    Properties
    {
        [NoScaleOffset] _MainTex("Texture", 2D) = "white" {}
        [NoScaleOffset] _UVTex1("UV Texture 1", 2D) = "white" {}
        [NoScaleOffset] _UVTex2("UV Texture 2", 2D) = "white" {}
    }

    SubShader
    {
        Tags {"Queue" = "geometry-11" "RenderType" = "opaque" }
        Pass {
            ZWrite Off
            Cull Off
            Lighting Off

            CGPROGRAM

        //Custom Shaderwords for different texture formats
        #pragma multi_compile VUFORIA_RGB VUFORIA_YUVNV12 VUFORIA_YUVNV21 VUFORIA_YUV420P VUFORIA_YUVYV12

        #pragma vertex vert
        #pragma fragment frag

        #include "UnityCG.cginc"
        #include "VuforiaVideoBackground.cginc"

        struct appdata_t {
            float4 vertex:POSITION;
            float2 texcoord:TEXCOORD0;
        };

        struct v2f_custom {
            float4 pos : SV_POSITION;
            float2 uv: TEXCOORD0;
        };

        v2f_custom vert(appdata_t v) {
            v2f_custom o;
            o.pos = UnityObjectToClipPos(v.vertex);

            o.uv = v.texcoord;
            o.uv = float2(1.0-v.texcoord.x,1.0-v.texcoord.y);

            return o;
        }

        half4 frag(v2f_custom i):SV_Target {
            half4 c = tex2D(_MainTex,i.uv);

            #ifdef UNITY_COLORSPACE_GAMMA
                return c;
            #else
                return half4(GammaToLinearSpace(c.rgb), c.a);
            #endif
        }
        ENDCG
    }
   }
    Fallback "Legacy Shaders/Diffuse"
}

代码输出

在此处输入图像描述翻转UV

Android AR 眼镜上正常输出图像方向和正常颜色

android unity-game-engine shader augmented-reality
1个回答
0
投票

我改变了解决这个问题的方法。我正在将 AR 眼镜的摄像头信号渲染到 UI 元素上以用作视频背景。 Vuforia 官方文档提供了如何执行此操作的示例: https://developer.vuforia.com/library/platform-support/working-camera-unity#apply-a-shader-to-the-camera-images

© www.soinside.com 2019 - 2024. All rights reserved.