- Home /
How to use a Transparent/Cutout shader with a Projector
Hello,
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" {
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_Cutoff ("Alpha Cutoff" , Range(0, 1)) = .5
_MainTex ("Texture", 2D) = ""
}
SubShader
{
ZWrite off
Fog { Color (0, 0, 0) }
Alphatest Greater [_Cutoff]
Cull Off
Color [_Color]
ColorMask RGB
Blend OneMinusSrcAlpha SrcAlpha
Offset -1, -1
Pass
{
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:
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:
Answer by Nodrak · Mar 01, 2014 at 05:17 AM
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.
Answer by Wolfram · Nov 14, 2012 at 05:03 PM
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.
Setting the Wrap $$anonymous$$ode to Clamp fixed the issue with it duplicating itself all over the whole level. What it didn't fix is drawing the texture only where the frustrum is. It now draws the texture as if the frustrum covers the entire level (which it doesn't). I'll have to have my artist try to clean up the alpha on the edges and see if that fixes it.
Thanks for the suggestions.
Yes, the edges are what is being repeated, so making them transparent will prevent your texture from "leaving" the frustum.
Answer by Quaker_SDR · Dec 21, 2014 at 11:31 AM
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 ?
I know this is extremely late but to answer for anyone wondering. According to the page http://docs.unity3d.com/$$anonymous$$anual/class-Projector.html
At the very bottom it explains about double projection at the very bottom of Hints, it reads:
When no Falloff Texture is used in the projector’s $$anonymous$$aterial, it can project both forward and backward, creating “double projection”. To fix this, use an alpha-only Falloff texture that has a black leftmost pixel column.
I hope that helps anyone!
Your answer
Follow this Question
Related Questions
Projector affected by light and shadows(car vinyls, blood spatter or bullet holes) 1 Answer
Weird Lines When Using Projector Unity 2020.3 0 Answers
Is that possible to create my own custom projector using unity camera 0 Answers
Projector Shader Problem 0 Answers
Projecting a square (or another shape) onto terrain 1 Answer