Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by JasonBricco · Apr 20, 2015 at 01:22 AM · shadertransparencyalphavoxelfluid

[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.

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JasonBricco · Apr 20, 2015 at 08:26 PM 0
Share

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.

avatar image Eno-Khaon · Apr 20, 2015 at 08:30 PM 0
Share
 Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
avatar image JasonBricco · Apr 20, 2015 at 08:35 PM 0
Share

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.

avatar image Eno-Khaon · Apr 20, 2015 at 08:50 PM 1
Share

Oh, right! Surface shader! Sorry, forgot one more piece.

http://forum.unity3d.com/threads/alpha-no-longer-affecting-transparency-after-unity-5-upgrade.313560/

Looks like you'll also want to use:

 #pragma surface surf Standard keepalpha vertex:vert fullforwardshadows

(keepalpha is the Unity 5 implementation, anyway)

avatar image JasonBricco · Apr 20, 2015 at 08:57 PM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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;
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JasonBricco · Apr 20, 2015 at 05:00 AM 0
Share

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 :(.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing custom shader. Add alpha cutout 1 Answer

All objects are getting transparent ? 1 Answer

How do I add transparency to a cg vertex lit shader 2 Answers

Adding Alpha-Transparency to Shader 0 Answers

Shader help (Animating Alpha values does not work on it!) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges