Hi! I want a glas like material that i can fade out to complete invisibility. I understand that fade lets me do that, but i want it to also be glas like at higher alpha values. I would want it to switch from
#pragma surface surf Standard alpha
to #pragma surface surf Standard alpha:fade
when the alpha value goes below 0.2f.
I dont think the shader allows any comparisons or logic in this part of the code.
It would also be even better if the material could have two sliders, one for transparent, and one for fade.
But i think the material can not be both transparent and have fade. Thx
Edit: For now i just swap material with code at a certain alpha value.
You are correct, you cannot switch between those two alpha modes in a surface shader.
However you can replicate both using alpha:premul (which is what alpha alone is actually using when you’re also using the Standard shading model). Really the difference between alpha:fade and alpha:premul is in fade the alpha lowers the opacity of everything, where as premul only lowers the opacity of the albedo and the specular remains at full strength. So the solution is to use StandardSpecular instead of Standard and fade out the specular color to black below 0.2 alpha.
Your basic StandardSpecular Surface shader looks like this:
To fade out, rescale the alpha so that 0.2 to 0.0 is a 1.0 to 0.0 range and multiply the specular color:
o.Specular = specColor * saturate(o.Alpha / 0.2);
The result will be the diffuse lighting will get a little bit brighter while it’s fading out, so it’s not quite exactly the same, but it shouldn’t be noticeable. Alternatively you might be able to use a final color modifier and do:
void customFade(Input IN, SurfaceOutputStandardSpecular o, inout half4 color)
{
color.rgb *= saturate(o.Alpha / 0.2);
}
But I can’t remember exactly when the final color modifier runs and that may cause the shader to go prematurely dark when fading out instead of ever so slightly too bright.