Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 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
Add comment · 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

I$$anonymous$$HO, 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 $$anonymous$$e 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

· Add your reply
  • Sort: 
avatar image
0

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
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 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" }

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

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

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

Billboard shader works in scene view but not game view 3 Answers

Unity5 CG Shader get model position. 1 Answer

Unity 5 toon shaders don't work in Windows standalone build 3 Answers

Cant get Alpha Channel to Work with Custom Shader 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