Projecting a movie texture

Anybody know how to project a movie texture?

I modified the blob shadow project in the standard assets folder to project a MovieTexutre onto a plane. It works fine as long as the material in the projector properties is of type "Diffuse" if i change that to "Fx/Project Multiply" The texture is rendered black.

The problem is pretty straightforward.

As far as I can tell movieTextures do not support embedded alpha so in the shader ( ShadowProjection.shader - FX/Projector Multiply) the line 'AlphaTest Greater 0' will always fail on every pixel of the movieTexture as the alpha is never > 0, its always 0 as there is no alpha.

The solution then is to remove that line, you could change it to 'AlphaTest GEqual 0' which will work, but actually that lets everything pass, ignoring any alpha that might be in normal diffuse textures. By just deleting the line you should find movieTextures work fine and diffuse still work as expected, due to the blending.

Of course then you'll come across bleeding/smearing of the projected movieTexture, but thats a whole different issue.

.

How to fix bleeding/smearing in projected movieTextures

Projective MovieTextures Package - Demo and collection of shaders to support movieTexture projection.

Bleeding of the movieTexture, where the clamped pixels of its border smear across the scene is perfectly normal. Its caused by using TexGen to create the uv mapping onto models within the 'projector' frustrum. Unfortunately whilst within the frustrum the uv maps from 0 to 1, outside it continues (i.e. negative up and left, > 1 down and right). Since the texture is clamped, this results in the border textures smearing. If you change the wrapmode to repeat, you'd get the texture repeat outside the frustrum instead.

The Blob shadow demo and shader get around this by using a mask/cookie using its alpha, where it is zero at the edges thus preventing the smearing from being rendered. If movieTextures had alpha support it could be used to similar effect.

So the simplest method to fix this would appear to be adding an additional texture layer (a mask), one that uses its alpha to control what pixels are finally rendered to screen. By making the alpha pure white except for say 1 pixel black border around the edges and ensuring wrapmode=clamp, we can force the area that is normally smeared to be hidden as the alpha will be 0 and it will not be rendered.

You need to ensure the alpha is exactly the same dimensions as you movie, so the black border is not scaled and its best to use 'point' sampling as opposed to bilinear. The shaders themselves have more information on this.

The provided a demo package features a simple test scene and contains 6 shaders, Additive, Multiply and Replace projection modes, each with an alternative that supports the 'falloff' method provided by the original shadowProjection shader in Unity.

enjoy.

Hi. I tinkered a bit with the blob shadow projector and this piece of C# code. That was the closest I could get, so I thought I would just post it and see if anyone would pick it up and bring the question home.

C#:

using UnityEngine; 
using System.Collections; 

public class PlayMovieTexture : MonoBehaviour { 

  private Projector proj; 
  public MovieTexture tex; 

  void Start () { 
    proj = transform.GetComponent<Projector>(); 
    //proj.material.mainTexture.Play(); 
    proj.material.SetTexture("_ShadowTex",tex); 
    //proj.material.mainTexture = tex; 
    tex.Play(); 
  } 
} 

I ticked the "community wiki" box, so please just change the code if you see something that should be corrected. I might add that it is not working right now... but in theory, it should, so it is prone for a bug report. However, I want get this reviewed before filing a bug report.

cheers

Edit: Not tested this code, but then it was irrelevant to the original question as the problem was in the shader.