• 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
Question by vision810 · Apr 22, 2015 at 08:02 PM · unity 5shadertransparencycgbillboard

Transparent shader disappears with multiple objects

I'm trying to write a transparent billboard shader that mimics a plane always aiming at the camera. The shader works on one object, but when two objects with the same shader are both in view they disappear at most angles.

 VertexOutput vert(VertexInput i)
 {
     VertexOutput o;
 
     float3 center = mul(_Object2World, float4(0,0,0,1));
 
     float3 eye = _WorldSpaceCameraPos - center;
     float3 right = normalize(cross(eye, float3(0, 1, 0)));
     float3 up = normalize(cross(right, eye));
 
     o.pos = float4(center, 1);
     o.pos += i.pos.x + float4(right, 0);
     o.pos += i.pos.y + float4(up, 0);
     o.pos = mul(UNITY_MATRIX_VP, o.pos);
 
     o.col = i.col;
     o.tex = i.tex;
 
     return o;
 }

After trying to debug for a while I think the part that's causing this issue is the part that updates the world position with the right and up vectors:

 o.pos += i.pos.x + float4(right, 0);
 o.pos += i.pos.y + float4(up, 0);

I would appreciate any help with this.

Comment

People who like this

0 Show 4
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 Owen-Reynolds · Apr 22, 2015 at 08:12 PM 0
Share

IMHO, shaders don't talk between each other. There's no way a line of shader code can "carry over" to the next object using that shader, and mess it up.

Are you hand-setting _Object2World, or some other uniform shader var in Unity? I'd guess with two objects, the order is messed-up. For fun, try moving the objects near and apart.

avatar image screenname_taken · Apr 22, 2015 at 08:26 PM 0
Share

I had this on a scene of mine where two transparent objects were really close and one was a bit higher. They would glitch out. I fixed that by making a small script that changed the material's render Queue.

avatar image vision810 · Apr 23, 2015 at 04:01 PM 0
Share

I'm not setting any uniform variables for this shader.

The proximity of the objects doesn't seem to be causing the issues, its when they're both on the screen at the same time that they disappear under certain angles.

I've tried changing the render queue and indeed this solves the problem. But correct me if I'm wrong, but this requires a different shader for every object. This is unfortunately not possible in my case as I have many objects with this shader in my scene.

Thanks for the input!

avatar image Sema_Sen · Jun 30, 2021 at 07:30 PM 0
Share

Hey did you find an answer? If so, I would appreciate if you can explain. I have exactly the same problem with billboard shader on transparent textures. Although I am not sure if it is related to their being transparent or not. My shader doesn't work if I use the same material for multiple objects with the same texture.

Any help greatly appreciated.

1 Reply

  • Sort: 
avatar image

Answer by Glenn-Korver · Jul 04, 2021 at 10:11 PM

You might be running into issues due to "Dynamic Batching" being enabled (which is the default). Try disabling it. https://docs.unity3d.com/Manual/SL-SubShaderTags.html

 Shader "ExampleShader" {
     SubShader {
         Tags { "DisableBatching" = "false" }
         Pass {
             …
         }
     }
 }
Comment

People who like this

0 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 Eno-Khaon · Jul 04, 2021 at 10:56 PM 0
Share

For reference, your example is backwards. "DisableBatching" *IS* false by default, so you would want to make it true instead.

 Tags { /* etc. */ "DisableBatching" = "false" }

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

24 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

Related Questions

How to compare colors in Shaders? 2 Answers

Add transparency to mask shader 1 Answer

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

Difference between pos.z and pos.w? 0 Answers

Billboard shader works in scene view but not game view 3 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