How to use a Transparent/Cutout shader with a Projector


I’m attempting to make a “cone” AOE target indicator for a game I’m working on. I have created a texture with the correct alpha channels to use with a Transparent/Cutout/Diffuse shader so that when I adjust the Alpha Cutoff value, it widens/narrows the cone angle appropriately. Next I need to have it conform to the terrain, so I want to use a Projector, but I can’t seem to get it to work properly.

Here is my current shader code:

Shader "AoE Target/Cone Projector" {
    	_Color ("Main Color", Color) = (1,1,1,1)   	
		_Cutoff ("Alpha Cutoff" , Range(0, 1)) = .5
		_MainTex ("Texture", 2D) = ""

    	ZWrite off
        Fog { Color (0, 0, 0) }
        Alphatest Greater [_Cutoff] 
        Cull Off
        Color [_Color]
        ColorMask RGB
        Blend OneMinusSrcAlpha SrcAlpha
        Offset -1, -1
            SetTexture[_MainTex] { 
            	combine texture * primary, ONE - texture
           		Matrix [_Projector]


It correctly renders the cutout texture so that I can adjust the angle of the cone, but it is repeated across the whole terrain, everywhere in the scene, not just where the projector’s frustrum collides with the terrain (which is what I want).

For example:
alt text

Perhaps I’m trying to do something that can’t be done? Or maybe I’m going about it the wrong way.

For a reference of what I’m trying to accomplish, see this image from League of Legends: alt Image from League of Legends

To prevent the projected image from being visible outside its frustum, you’ll need to set the Wrap Mode of the texture to “Clamp”, it is mentioned in the documentation.
Also ensure that the outermost rim of your texture either has 0% alpha, or at least always lies below your cutoff value, otherwise that border will be repeated outside the frustum.

I was wracking my head around this issue for hours, tinkering with the falloff map to figure out what it does and changing the size of my ‘cookie’ texture vs the size of the projector. Nothing.

Then I remembered, hidden away in the Standard Assets folder where the Projectors are, the tiny file that said quietly to ‘turn mip maps off when importing cookie texture’.

Needless to say this is the only place I saw offer this little gem. The cookie texture is getting Mip Maps generated for it on import, which can/will ruin the edge of your texture.

Locate your Cookie texture, and change the type to advanced. The default settings are fine, baring the Generate Mip Maps box. Uncheck it.

Double check your Wrap mode is in Clamp.
I’ve seen recommendations to use Point Filtering for Projectors, YMMV.

Also the Falloff Texture appears to be a Distance based filter. The only Pixels that had impact on the projector were the bottom row. These represented distance from source on the left, giving you a resolution of your choice. (256x1 worked as well as 16x1, depending on how much Distance Based Falloff Granularity you want) As per the hidden gem on the Unity site. Ensure the Leftmost Pixel is Black to prevent bi-directional projection.

Hope this helps.

Hi all,

I am trying to do like projecting a texture on the dress, But i dunno why its coming on otherside of the dress too, Can any one help me ?