- Home /
Is it possible to create a transparent (empty) Texture2D that hides other textures under it?
I have a health gauge that has a sharp 45 degree angle. Basically I need someway to have an area on the screen under which other textures become invisible, but the alpha texture is still see-through.
I already tried rotating groups, etc. It works fine on normal GUI.matrix, but I have changed it so all of my other textures would scale nicely under every resolution.
How do I make the transparent hider texture? Or maybe there is some other approach?
By definition you can see something behind a transparent texture. What effect are you trying to achieve?
Put another non transparent texture just behind the transparent texture?
A texture which would hide a part of another texture which is covered. Imagine an invisibility cloak.
What other textures are beco$$anonymous$$g invisible? are they other HUD elements?
From what I can tell you want to use the stencil buffer for explicitly affecting other objects.
Perhaps you could clarify the effect you're trying to achieve with a mock-screenshot in paint of what you currently see, and what you want to see?
I'm sorry if my English knowledge is not great enough to explain in superb clarity :< In any case - I have tried rotating a group with the texture inside. It works fine, but my GUI.matrix is custom, therefore a 45 degree angle results in having the group rotated by 47 degrees (like what the hell). And the group also pixelates in a very stupid manner, so on low resolution the nice pointy end looks like a chewed up toy.
Answer by tanoshimi · Jun 23, 2014 at 07:34 PM
This should work - assuming that your red "pointy-ended" object is drawn with a transparent shader (and therefore in the transparent queue), then create a new material using this shader and put it on the transparent object that you want to use to mask it.
Shader "Mask" {
SubShader {
Tags {
"Queue" = "Transparent-1" // Needs to be in a queue *before* the thing that you want to mask
"IgnoreProjector" = "True"
}
Pass {
Cull Back
Blend Zero One
Lighting Off
CGPROGRAM
#include "UnityCG.cginc"
#pragma vertex vert
#pragma fragment frag
v2f_img vert (appdata_base v)
{
v2f_img o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
fixed4 frag (v2f_img IN) : COLOR
{
return fixed4(0,0,0,0);
}
ENDCG
}
}
}
This all seems to do exactly what is needed, but I'm new to shaders and obviously I have to go through a lot of tutorials, but, if you could spare another moment, maybe you can explain step by step on how to draw and assign all and overall use this? I draw my textures on screen using OnGUI(), how do I draw them with the shader attached, etc. I'm sorry, must sound as a complete empty-head.
Not at all. I'm $hyt at shaders too. Its a completely different kettle of fish to what you've encountered so far. Don't beat yourself up, this is an advanced topic :P
@tanoshimi, did you say the Texture mask I posted would require pro?
(off-topic: P$$anonymous$$d you some info on forum)
I somehow managed to make it work right this morning, thank you so much! I mean really, where else would you find a community so supportive and full of such fine people, thank you all! ^w^
How do I draw these textures on the screen so neatly?
"How do I draw these textures on the screen so neatly?"
This is a separate question but the answer is... select the texture, set the type to GUI in inspector and click apply