- Home /
Make an object transparent when below 1.0A, and completely opaque at 1.0A?
Hi, I didnt think this would be a difficult task or maybe I've just made myself confused but I am trying to fade an object and unless I'm misunderstanding I have to set the rendering mode to transparent. But I do not wish to see particles and other such things through the object when it is at 100% alpha. Is there a way where I can still lower the alpha and therefore make the object transparent but while at 100% the object is completely opaque?
Cheers.
Answer by YoungDeveloper · Aug 12, 2015 at 08:39 AM
There's a actually a function which does exactly that in standart shader editor script. Download the source and look it up, I don't have the source on me right now.
Answer by Raffin · Aug 13, 2015 at 02:34 AM
Thanks for the help. I made it so that the shader is swapped whenever I need to drop the alpha below 1.0.
Also, when I built the game I needed to manually include the shader as I used Shader.Find() to replace the shader. Placing the downloaded shader from unity's download page inside "Assets/Resources" worked.
Answer by Eno-Khaon · Aug 13, 2015 at 02:44 AM
It sounds like you're looking for an attribute of a Transparent Cutout Shader. That said, if you're looking to make an alternative capable of doing both, the shader code could be approached with something like:
tex.a = floor(tex.a);
This would take your texture's alpha value and reduce all fractions down to the nearest whole number, so anything less than 1 would instead be 0.
For any shader purely based around all-or-nothing transparency (i.e. cutout), however, you would be better off utilizing a proper transparent cutout shader instead. Those can instead be based instead around clipping pixels based on the alpha value.
clip(tex.a - 1);
Not quite, as I wanted the whole object to fade gradually from 100% opacity to 0%. But with the shader I needed; leaving the shader at 100% opacity would have a problem with the Z order of particle systems. So I made it that when the opacity drops below 100% the shader is swapped. Thanks for the help though.
I had a similar problem and didn't want to swap shaders, so I used this custom shader:
Shader "Custom/diffuse_alpha" {
Properties{
_Color("$$anonymous$$ain Color", Color) = (1, 1, 1, 1)
_$$anonymous$$ainTex("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader{
Tags{ "RenderType" = "Transparent" "Queue" = "Transparent" }
// Render into depth buffer only
Pass{
Color$$anonymous$$ask 0
}
// Render normally
Pass{
ZWrite Off
Blend SrcAlpha One$$anonymous$$inusSrcAlpha
Color$$anonymous$$ask RGB
$$anonymous$$aterial{
Diffuse[_Color]
Ambient[_Color]
}
Lighting On
SetTexture[_$$anonymous$$ainTex] {
Combine texture * primary DOUBLE, texture * primary
}
}
}
FallBack "Diffuse"
}
Your answer
![](https://koobas.hobune.stream/wayback/20220611235508im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Opaque to Transparent animation effect on a textured object (Lerpz)? 1 Answer
Blending and Decaying Alphas 0 Answers
How to make this image semi-transparent? 3 Answers
Strange alpha result 0 Answers