J. Hegg
J. Hegg

Reputation: 2133

ARCore Sceneform ChromaKeyVideo Sampleproject how to just use the video feature

I took a look at the recently released sample project ChromaKeyVideo for ARCores Sceneform.

I want to use the feature to display a video in my ar scene but without the chroma key feature. In the example project they used textures to key out the background etc.

But how can I transform this sample to just display a .mp4 videofile? At the moment I have to use an implementation of a OpenGL Renderer. It would be very nice to use Sceneform for this instead. And obviously it is possible. But I don't know which materials I do have to use to just display a solid video.

So how do I have to change this sample to just display the full video without the chroma key feature?

Upvotes: 2

Views: 1454

Answers (1)

Clayton Wilkinson
Clayton Wilkinson

Reputation: 4572

You can create a new custom material that just uses the external texture. You can create a new .mat file in the sampledata/models directory named 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;
    }
}

Then in your .sfa file change the material source to externalTexture.mat:

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

Upvotes: 3

Related Questions