- Home /
[Solved] Vertex Color/Alpha Transparency Rendering as Opaque
Hi all,
I've got this shader for my voxel engine that is to be used on fluid blocks:
Shader "Voxel/Fluid Vertex"
{
Properties
{
_Color("Color", Color) = (1, 1, 1, 1)
_MainTex("Albedo (RGB)", 2D) = "white" {}
_Glossiness("Smoothness", Range(0, 1)) = 0.5
_Metallic("Metallic", Range(0,1)) = 0.0
_Speed("Speed", float) = 2.0
_Alpha("Alpha", float) = 0.8
}
SubShader
{
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
LOD 200
Cull off
CGPROGRAM
#pragma surface surf Standard vertex:vert fullforwardshadows
#pragma target 3.0
float _Alpha;
float _Speed;
struct Input
{
float2 uv_MainTex;
float3 vertexColor;
};
struct v2f
{
float4 pos : SV_POSITION;
fixed4 color : COLOR;
};
void vert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
v.texcoord.x += _Time * _Speed;
o.vertexColor = v.color;
}
sampler2D _MainTex;
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf(Input IN, inout SurfaceOutputStandard o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb * IN.vertexColor;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a * _Alpha;
}
ENDCG
}
FallBack "Standard"
}
I'm learning about shaders, but still am very new with them. This is supposed to scroll the fluid texture, be influenced by vertex colors, and have transparency. This isn't entirely my shader. I only made a few modifications to it.
It scrolls just fine, it's influenced by vertex colors just fine.
The transparency part isn't working at all. It's 100% opaque.
I have the RenderType = Transparent, the SrcAlpha OneMinusSrcAlpha blending, etc. I've tried changing the alpha value and also changing the alpha of the vertex colors themselves, and neither does a thing.
I'm not sure what I'm doing wrong here! Help would be appreciated.
I wonder if this is a Unity bug... I grabbed someone else's voxel fluid shader that I know rendered the blocks transparent, and plugged it into my water. And my water still wasn't transparent! That shader was created years back and worked at that time, but doesn't seem to anymore.
Or could it be that the transparency of this object could be affected by some settings I have set in Unity, or the shaders of the other objects in the scene? I just can't see what is wrong here.
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
I was wondering about that... but it's still not working. Completely opaque water, even though my _Alpha property is set to 0.5 and the vertex colors specify an alpha of 150/255.
I'm trying to understand what else could influence this. I know when I put Unity's standard shader on and set it to transparent rendering type, it worked just fine to make my water transparent (but can't use that because I need vertex color support). I'm not sure what is different about this shader.
Oh, right! Surface shader! Sorry, forgot one more piece.
Looks like you'll also want to use:
#pragma surface surf Standard keepalpha vertex:vert fullforwardshadows
(keepalpha is the Unity 5 implementation, anyway)
Ah, that's what it was. I completely missed that topic. Thanks a lot!
If that were posted as an answer, I'd mark it as accepted.
Answer by WillNode · Apr 20, 2015 at 04:27 AM
Your _Alpha
property doesn't referenced in any of your code, try to change your shader code at line 60:
o.Alpha = c.a * _Alpha;
Thanks for the response! Unfortunately, it didn't solve my problem. I'm guessing there's another problem on top of that one. Still haven't managed to find it :(.