- Home /
Masked RenderTexture not working in WebPlayer
Dear coomunity,
Im trying to create a circular avatar of the 3d character in the HUD. I use a camera projecting to a render texture. And drawing the texture with:
Graphics.DrawTexture(Rect(0,0,84,84), avatarTexture1, new Rect(0, 0, 1, 1), 0, 0, 0, 0, avatarMaterial);
Where avatarTexture1 is the rendertexture and avatarMaterial is a material with a mask shader.
I use a alpha mask in combination with the following shader:
Shader "MaskedTexture"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_Mask ("Culling Mask", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range (0,1)) = 0.1
}
SubShader
{
Tags {"Queue"="Transparent"}
Lighting Off
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
AlphaTest GEqual [_Cutoff]
Pass
{
SetTexture [_Mask] {combine texture}
SetTexture [_MainTex] {combine texture, previous}
}
}
}
This works perfectly in the Unity editor, but NOT in the webplayer. What could be the problem?
Ps. Drawing the avatar without the material attached works in the webplayer, but then the avatar is not masked (circle shape) which is what I need...
Answer by Royall · May 13, 2014 at 04:45 PM
It looks like I had to add "ZTest Always" to the SubShader which makes this new masked shader that also works in the webplayer:
Shader "MaskedTexture"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_Mask ("Culling Mask", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range (0,1)) = 0.1
}
SubShader
{
Tags {"Queue"="Transparent"}
Lighting Off
ZTest Always
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
AlphaTest GEqual [_Cutoff]
Pass
{
SetTexture [_Mask] {combine texture}
SetTexture [_MainTex] {combine texture, previous}
}
}
}
Really don't know why, but it works ;)
Your answer
Follow this Question
Related Questions
Strange shader behaviour on UI component 0 Answers
Shader problem with 2D fake lighting 1 Answer
My RenderTexture Can't see anything 0 Answers
Text To Texture/Image 1 Answer