ImageTracking_Video

Attention

The content of this page will be updated soon.

Demonstrate image tracking feature and video display on top of image.

  • Demonstrate how to load video with Unity VideoPlayer and play video on target

  • Demonstrate how to load video with Unity VideoPlayer and play transparent video with custom shader

  • Demonstrate how to change the video aspect ratio (Unity VideoPlayer feature) to fit image target

How to Use

../../_images/image_27.png
Mark 1: Display system status and operation hint.
Mark 2: Switch video aspect ratio mode.

Ways to fit video to the image

How the video fit the image (fit inside or stretch or others) can be controlled by VideoPlayer.aspectRatio. This is a Unity VideoPlayer feature.

Transparent video of side-by-side format

Transparent video here is a special type of video, it use a side-by-side format usually used by 3D video, its left side is the colored video, and right side is used as alpha channel for the left side.

../../_images/image_s2_3.png

The video itself has no special things, it is encoded by normal video encoder and multiplexed using normal container. To create such videos, you just need to double your video width and make the right side the alpha value you want for each pixel of the left part using any tool that can achieve this.

The only difference of using this video compared to other videos is the material.

../../_images/image_s2_2.png

The shader recalculates the pixel value to mix left and right side together.

fixed4 frag(v2f i) : SV_Target
{
    fixed4 color_a = tex2D(_MainTex, float2(i.uv.x / 2 + 0.5, i.uv.y));
    fixed4 color_rgb = tex2D(_MainTex, float2(i.uv.x / 2, i.uv.y));
    return fixed4(color_rgb.rgb, color_a.r);
}

The output in Unity will be like this, except the black part is transparent.

../../_images/image_s2_4.png