Simulating a video projector

I get strange results using the projector component together with the standard asset ‘Projector Light.shader’ and a texture with wrap mode set to clamp. The projector emits light sideways and backwards as well as forward.

How do I set up the Projector component to simulate the behaviour of a video projector?

Carl Emil

yOU NEED THIS SCRIPT TO SHADER:
CREATE A SHADER AND COPY AND PAST THIS CODE:
THAN APLY THE MATERIAL CREATE IN PROJECTOR ADDITIVE, IN YOUR PROJECTOR

Shader “Projector/Additive” {
Properties {
_ShadowTex (“Cookie”, 2D) = “” { TexGen ObjectLinear }
_FalloffTex (“FallOff”, 2D) = “” { TexGen ObjectLinear }
}
Subshader {
Pass {
ZWrite off
Fog { Color (1, 1, 1) }
ColorMask RGB
Blend One One
SetTexture [_ShadowTex] {
combine texture, ONE - texture
Matrix [_Projector]
}
SetTexture [_FalloffTex] {
constantColor (0,0,0,0)
combine previous lerp (texture) constant
Matrix [_ProjectorClip]
}
}
}
}

Thanks, but it doesn’t make it better. It just gets a bit brighter.

What is the falloff texture supposed to look like?

~ce

The falloff texture is usually a gradient ramp, running horizontally. IIRC, it’s white on the left, fading to black on the right.

And yes, it’s exactly what you need to control that situation there.

Cheers

The falloff texture is needed, but more importantly is that the texture you’re feeding the projector can’t have any RGB information at the borders… ie, you need to have a transparent border around the image. In this case if you’re trying to use a video clip, which doesn’t support alpha channels, you will need to create a custom shader that uses the video clip as the main texture and a separate texture as the alpha border.

If you’re using an additive projector then you could put a black border around the video clip.

Thanks Harvester and Antenna!

Zero alpha border and a falloff gradient texture does not seem to fix the problem entirely. It is now overly bright and the image is still repeated in the backwards direction. I also get flickering on one of the walls when I turn the camera.

I would highly appreciate if someone could set up a simple example.

Carl Emil

Here is the project files so far.

1059912–39386–$VideoProjectorSimulator.unitypackage (2.96 MB)

I made the border black and bordered mipmaps in the import settings for both textures…

1059944–39392–$_Projector.unitypackage (3.41 MB)

Thanks Ethan. This is big improvement. However I still get some strange effects round the projector and when I turn the projector 360 degrees slowly sometimes it draws the projection in the opposing direction. I wonder how I can tweak this.

The shading looks different on the attached screen shot because I added a PointLight.

I can’t reproduce that issue. Can you post a screenshot of what you’re seeing? Do you mean that the projection shows up in front and behind the projector? If so try adjusting the falloff texture with more black at the beginning of the ramp (the white side).

Thanks again Ethan. I managed to get a perfect result by fiddling with the gradient texture and increasing the black border size on the projected image. I had to increase the border to 42px. It feels like an ugly hack (because pixels are wasted), but it works.

Hey, i tried to open the packages because i need the same effect. But when i try to import it, unity will throw me a error, that it can not be decompressed. Can anybody send me that package for the current untiy-version or zip it? that would be great

Try this …

1084740–40633–$SimulatedVideoProjector.unitypackage (2.78 MB)