Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Mr-JWolf809 · Feb 17, 2016 at 05:18 PM · shadermeshtransparency

Standard shader - fade mode renders texture in wrong order

I have a nice looking tree cartoonish tree.

The camera is a 3. person topdown view (think diablo-ish). The character should be able to walk under trees, and the trees should become transparent.

My tree looks like this (Opaque)alt text Where the black parts should be transparent. When I change the mode to fade it looks like this alt text

The tree is one big mesh, but the texture order is wrong, it draws the texture in the back, ontop of the texture in the front.

How can I fix this?

I have been looking into setting the _ZWrite to 1 and tried this shader

Which gives me this result: http://i.imgur.com/pZletcf.png which is not acceptable either.

fade-with-mesh.png (63.8 kB)
opaque.png (58.1 kB)
Comment
Add comment · Show 2
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 Mr-JWolf809 · Feb 17, 2016 at 11:56 PM 0
Share

Anyone got an idea for this problem?

avatar image Mr-JWolf809 · Feb 18, 2016 at 07:56 AM 0
Share

Or is this not possible?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Mr-JWolf809 · Feb 18, 2016 at 12:41 PM

I found a possible solution to the problems.

Giving this result! Result

It is not perfect, but it works well enough for the fade effect.

The shader is based on the Unity Shader: Legacy Shaders/Transparent/Cutout/VertexLit which I have modified to fit my needs. I have removed a lot effects which I didn't need (Shininess, Spec Color, Emissive Color) and made it possible to make the tree transparent even if the texture is baked.

 Shader "Custom/Transparent and Cutout Shader" 
 {
     Properties 
     {
         _Color ("Main Color", Color) = (1,1,1,1)
         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
         _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
     }
 
     SubShader {
     
         Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
         LOD 200
     
         // Non-lightmapped
         Pass 
         {
             Tags { "LightMode" = "Vertex" }
             Alphatest Greater [_Cutoff]
             AlphaToMask True
             ColorMask RGB
             Material {
                 Diffuse [_Color]
                 Ambient [_Color]
             }
             Lighting On
             SetTexture [_MainTex] {
                 Combine texture * primary DOUBLE, texture * primary 
             } 
         }
     
         // Lightmapped, encoded as dLDR
         Pass {
             Tags { "LightMode" = "VertexLM" }
             Alphatest Greater [_Cutoff]
             AlphaToMask True
             ColorMask RGB
             Material {
                 Diffuse [_Color]
                 Ambient [_Color]
             }
             Lighting On
             SetTexture [unity_Lightmap] {
                 matrix [unity_LightmapMatrix]
                 combine texture * texture alpha DOUBLE
             }
     
             SetTexture [_MainTex] {
                 combine texture * previous DOUBLE, texture * primary
             }
         }
 
         // Lightmapped, encoded as RGBM
         Pass 
         {
             Tags { "LightMode" = "VertexLMRGBM" }
             Alphatest Greater [_Cutoff]
             AlphaToMask True
             ColorMask RGB
             Material {
                 Diffuse [_Color]
                 Ambient [_Color]
             }
             Lighting On
             SetTexture [unity_Lightmap] {
                 matrix [unity_LightmapMatrix]
                 combine texture * texture alpha DOUBLE
             }
     
             SetTexture [_MainTex] {
                 combine texture * previous DOUBLE, texture * primary
             }
         }
     
         // Pass to render object as a shadow caster
         Pass 
         {
             Name "Caster"
             Tags { "LightMode" = "ShadowCaster" }
         }
     }
 }
 

solution.png (170.1 kB)
Comment
Add comment · Show 3 · 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 Cherno · Feb 18, 2016 at 12:44 PM 0
Share

The original problem can't be fixed, even AAA games have this problem. You could use the standard shader but set it's rendering mode to cutout ins$$anonymous$$d of transparent or fade. You could also make the inner and outer meshes seperate gameObjects which would also eli$$anonymous$$ate the error since they are both convex.

avatar image Mr-JWolf809 Cherno · Feb 18, 2016 at 12:51 PM 0
Share

The problem is I need to make it fade. The other solution you talk about seems more likely, that I make it different gameobjects.

avatar image carloslator · Sep 08, 2016 at 12:54 PM 0
Share

$$anonymous$$r-JWolf809

Is there a way to become this shader into just transparent?

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

54 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

Related Questions

Transparency / depth problem 0 Answers

Make transparency ignore meshes inside? 1 Answer

[ problem ] transparent shader !!! 1 Answer

make object to appear from bottom up 2 Answers

shader Transparency 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