Unity Video Texure Maps


Make a folder in your Assets folder called StreamingAssets.
Place a video file in the Assets folder of your Unity project.

Keep the pixel size small such as 426x240.
Keep the bitrate low such as 300-700 Kbps.
The framerate should not be over 30 fps.
Keep the video duration short.

Use h.264 .mp4  (h.265 works)
These formats might work, depending on the codec: .mov .mpg .mpeg .mp4 .avi .asf

In Unity:
Select your object
Select Add Component in the Inspector 
     Choose Video->Video Player
          Change the Source to URL
         Hit Browse... to find your movie in your Assets/SteamingAssets folder.
          Turn on Loop if you prefer.

          If the video does not have have audio, turn off Audio Output Mode

Create a new material shader:
      Select Shader->Unlit/Texture (In the Inspector)
Drag the Material onto your object

Pay the Game to see the texture

Directions to use Adobe After Effects  

Directions to use Adobe Media Encoder to make a  H.264 movie

Add 3D sound to videoPlayer script
By Alex Rickett UCLA Game Lab
Unity does not provide 3D sound for the videoPlayer.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;

public class WebGLVideoPseudo3DSound : MonoBehaviour

    public float minVolumeDistance = 10;
    public float maxVolumeDistance = 1;
    public float minVolume = 0;
    public float maxVolume = 1;

    VideoPlayer _vp;
    private void Start()
        _vp = this.GetComponent<VideoPlayer>();
        minVolumeDistance *= minVolumeDistance;
        maxVolumeDistance *= maxVolumeDistance;
        if (!_vp.canSetDirectAudioVolume)
            Debug.LogError("can't change volume! canSetDirectAudioVolume == false");

    void Update()
        float distance = (Camera.main.transform.position - this.transform.position).sqrMagnitude;
        float normDistance = Mathf.InverseLerp(minVolumeDistance, maxVolumeDistance, distance);
        float volume = Mathf.Lerp(minVolume, maxVolume, normDistance);
        _vp.SetDirectAudioVolume(0, volume);

Sprite Sheet for Short Low Resolution Video or Animation Sequence

You will use an image sequence to make a single image that contains all the frames. A script will play the sheet as an animation texture map.

Use After Effects or any program to generate a short animation sequence.

Download and install GlueIT to create a sprite sheet.

Run GlueIT:
     Select Add, choose all your files. (png works, the images need to be the same size.)
     Input the number of columns
     Save your file into your Assets folder.
     Give it an informative name such as sheet_11columns_20rows_220_frames.png

How to calculate columns and rows:
Unity has some texture limits. The default is 2048x2048. Keeping this number low and exponential will help performance.
My sequence has 220 180x100 images
     2048 / 180 pixels = 11.37, so I could use 11 columns.
     2048 / 100 pixels = 20.48, so I could use up to 20 rows
     11 columns x 20 rows = 220 frames
     My sheet will be 1980x2000 pixels

Create a Sprite Sheet Shader
In Unity:
Select Assets->New Shader->Unlit Shader
A shader is code to generate an image.
     Name the shader test_Shader

Double Click the shader in your Assets to edit the script.

Replace all the code with this script:
Shader "Custom/test_Shader" {
 Properties {
  _Color("Color", Color) = (1,1,1,1)
  _Glossiness("Smoothness", Range(0,1)) = 1
  _Metallic("Metallic", Range(0,1)) = 1
  _MainTex ("Color Spritesheet", 2D) = "white" {}
  _NormalTex ("Normals Spritesheet", 2D) = "white" {}

  _Columns("Columns (int)", int) = 3
  _Rows("Rows (int)", int) = 3
  _FrameNumber ("Frame Number (int)", int) = 0
  _TotalFrames ("Total Number of Frames (int)", int) = 9
  _Cutoff ("Alpha Cutoff", Range(0,1)) = 1
  _AnimationSpeed ("Animation Speed", float) = 0
 SubShader {
  Tags { "RenderType"="Opaque" "DisableBatching"="True"}
  LOD 200
  Cull Off

  #pragma surface surf Standard fullforwardshadows alphatest:_Cutoff addshadow
  #pragma target 3.0

  sampler2D _MainTex;
  sampler2D _NormalTex;

  struct Input {
   float2 uv_MainTex;
   float4 color : COLOR;

  float4 _Color;
  half _Glossiness;
  half _Metallic;
  int _Columns;
  int _Rows;
  int _FrameNumber;
  int _TotalFrames;

  float _AnimationSpeed;

  void surf (Input IN, inout SurfaceOutputStandard o) {

   _FrameNumber += frac(_Time[0] * _AnimationSpeed) * _TotalFrames;

   float frame = clamp(_FrameNumber, 0, _TotalFrames);

   float2 offPerFrame = float2((1 / (float)_Columns), (1 / (float)_Rows));

   float2 spriteSize = IN.uv_MainTex;
   spriteSize.x = (spriteSize.x / _Columns);
   spriteSize.y = (spriteSize.y / _Rows);

   float2 currentSprite = float2(0,  1 - offPerFrame.y);
   currentSprite.x += frame * offPerFrame.x;
   float rowIndex;
   float mod = modf(frame / (float)_Columns, rowIndex);
   currentSprite.y -= rowIndex * offPerFrame.y;
   currentSprite.x -= rowIndex * _Columns * offPerFrame.x;
   float2 spriteUV = (spriteSize + currentSprite); //* _FrameScale

   fixed4 c = tex2D(_MainTex, spriteUV) * _Color;

   o.Normal = UnpackNormal(tex2D(_NormalTex, spriteUV));
   o.Metallic = _Metallic;
   o.Smoothness = _Glossiness;
   //change Albedo to Emission for backlit
   o.Albedo = c.rgb;
   o.Alpha = c.a;
 FallBack "Transparent/Cutout/Diffuse"

Create a Material
Select Assets->Create->Material
     Name the material
     In the Inspector change the Shader option to your test_Shader, it is listed under Custom
     Change the number of Columns and Rows to match you sheet.
     Input the Total Number of Frames
    Input the Animation Speed   1
     Drag the sheet png onto Color Texture

Drag the material onto your model.