首页 > 解决方案 > ARCore Sceneform ChromaKeyVideo Sampleproject 如何使用视频功能

问题描述

我查看了最近发布的 ARCores Sceneform 示例项目ChromaKeyVideo

我想使用该功能在我的 ar 场景中显示视频,但没有色度键功能。在示例项目中,他们使用纹理来抠出背景等。

但是我怎样才能将这个示例转换为只显示一个 .mp4 视频文件?目前我必须使用 OpenGL 渲染器的实现。使用 Sceneform 代替它会非常好。显然这是可能的。但我不知道我必须使用哪些材料才能显示一个可靠的视频。

那么如何更改此示例以仅显示没有色度键功能的完整视频?

标签: androidarcoresceneform

解决方案


您可以创建仅使用外部纹理的新自定义材质。您可以在 sampledata/models 目录中创建一个新的 .mat 文件,名为externalTexture.mat

// Copyright 2018 Google LLC. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
material {
    "name" : "Chroma Key Video Material",
    "defines" : [
        "baseColor"
    ],
    "parameters" : [
        {
           // The texture displaying the frames of the video.
           "type" : "samplerExternal",
           "name" : "videoTexture"
        }
    ],
    "requires" : [
        "position",
        "uv0"
    ],
    "shadingModel" : "unlit",
    // Blending is "masked" instead of "transparent" so that the shadows account for the
    // transparent regions of the video instead of just the shape of the mesh.
    "blending" : "masked",
    // Material is double sided so that the video is visible when walking behind it.
    "doubleSided" : true
}

fragment {
    void material(inout MaterialInputs material) {
        prepareMaterial(material);

        vec2 uv = getUV0();

        if (!gl_FrontFacing) {
          uv.x = 1.0 - uv.x;
        }

        material.baseColor = texture(materialParams_videoTexture, uv).rgba;
    }
}

然后在您的 .sfa 文件中将材质源更改为 externalTexture.mat:

     source: "sampledata/models/externalTexture.mat",

推荐阅读