Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 kitfox-com · Sep 05, 2017 at 09:46 PM · shadertransparencyalphafadeout

Transparency not working in Windows build

I'm having some trouble with a mesh that is rendering with alpha fine in my viewport not being rendered with alpha when I run it in my Windows build.

I have a skinned character that I'm using for an enemy that is using the standard shader for rendering. When it is killed, I play a fall over animation and then want it to slowly fade out. I'm doing this by changing the shader's color's alpha each Update():

         if (!init)
         {
             init = true;

             //Switch from opaque to transparent
             Material m = meshRend.materials[0];
             m.SetFloat("_Mode", 2);
             m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
             m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
             m.SetInt("_ZWrite", 0);
             m.DisableKeyword("_ALPHATEST_ON");
             m.EnableKeyword("_ALPHABLEND_ON");
             m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
             m.renderQueue = 3000;

             return false;
         }

         elapsedTime += Time.deltaTime;
         float val = Mathf.Max(1 - (elapsedTime / waitTime), 0);
         meshRend.material.color = new Color(1, 1, 1, val);

This works fine when I'm running in the Unity editor window, but when I'm running my windows build, the alpha fade doesn't happen (although the Z test does appear to be disabled once my init section is run).

I read in another thread that this might be due to Unity not compiling shaders with options that are not be used. I tried including the Standard shader in the list of shaders in Project Settings/Graphics/Always Included Shaders (as per one suggestion), but that just caused Unity to freeze during the build. I also tried creating a standard shader material that rendered with transparency, set it's alpha to .5 and assigned it to a dummy cube in my scene (to force Unity to render using a Standard shader with alpha). However, while the cube did render with transparency, my character is still not fading out.

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by kitfox-com · Sep 06, 2017 at 12:54 AM

I figured it out. FIrst I created a new Shader Variant Collecton object in my project, then I edited it to add an entry for a standard shader with a ForwardBase DIRECTIONAL_ALPHA_ON. Then I editied my Project Settings/Graphics/ Shader Preloading to include a reference to my Shader Variant Collection in the Preloaded Shaders array.

The Unity docs go into more details:

https://docs.unity3d.com/Manual/OptimizingShaderLoadTime.html

Comment
Add comment · Show 4 · 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 OregonPete · Jun 12, 2018 at 03:54 PM 1
Share

Hi, I'm having a similar issue and read your solution with interest. Problem is, I couldn't figure out how to add the DIRECTIONAL_ALPHA_ON keyword. I can add the Standard shader to the variant collection, but when I click in the inspector to add a keyword, it won't list the one I need. How did you manage it? Is there any place where I can enter the keyword manually? Thanks!

avatar image r433scriven OregonPete · Aug 18, 2020 at 05:21 PM 1
Share

I had this exact problem too and the shader variant popup window where you select keywords is absolutely awful. You are unable to scroll down the long list of keywords or even type something in. I did however find a solution to manually put in the "DIRECTIONAL_ALPHA_ON".

So in the shader variant window I selected the only one I could see, DIRECTIONAL_ALPHATEST_ON. This isn't the one we need but we can override it. Then I clicked on the shader variant collection asset in the unity project window and opened the file location. There opened the .shadervariants file with my preferred text editor.

Here I saw the "DIRECTIONAL_ALPHATEST_ON" that I entered in the shader variant window and I replaced that with the "DIRECTIONAL_ALPHA_ON."

This solved my problem but Unity should really really update their shader variant window since this was pretty ridiculous.

avatar image OregonPete r433scriven · Mar 30 at 11:36 PM 0
Share

Wow, it's been a long time since I've worked with Unity. But I finally saw your response, and I was able to edit the file without incident. Sadly, the transparency issue persists. Perhaps I need to explicitly add the shader variant to the material?

avatar image Reekin · Dec 27, 2020 at 09:03 AM 0
Share

I tried creating a new SVC and Add Standard-ForwadBase DIRECTIONAL_ALPHA_ON with my text editor, but it still doesn't work. The Project Setting window can not track the standard variant either, that's really weird and confusing. Where can I learn more about when to use "DIRECTIONAL_ALPHA_ON"?

avatar image
0

Answer by Morph12345 · Dec 03, 2017 at 09:41 PM

Hi, I have the same issue (i want to make an object transparent when the player is hidden, like a roof when the player is in the house).
I use the same code as you from "Material m = ..." to "...queue = 3000".
I tried to create a new Shader Variant Collection, I had theses keyword :

  1. ForwardBase DIRECTIONAL_ALPHATEST_ON

  2. ForwardBase DIRECTIONAL_ALPHABEND_ON

  3. ForwardBase DIRECTIONAL_ALPHAPREMULTIPLY_ON

And then I save it and added it in the graphic settings as the doc says.

But the problem is still there.
Did you remenber if you did anything else ? or maybe how to try to debug this.
Thanks :)

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 kitfox-com · Dec 07, 2017 at 07:35 PM 0
Share

Just guessing here, but I'd suggest removing those extra DIRECTIONAL_ALPHA* words you added to your Shader Variant Collection and just add a single DIRECTIONAL_ALPHA_ON. You could also just turn the active flag off on an object if you just want the roof to vanish.

avatar image
0

Answer by foxes · Nov 28, 2018 at 11:35 PM

In version 2017.4.16 it also does not work in the Editor.

Comment
Add comment · 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

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

113 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with transparent shader 0 Answers

Changing material color´s alpha in self iluminated shader 1 Answer

Alpha self illum. shader issue 0 Answers

Cutout Shader getting Opaque when turning alpha off and on again 1 Answer

Adding Transparency/Fading Functionality to a Shader 0 Answers


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