• 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 StephanK · Mar 08, 2011 at 11:44 AM · 2dshadershaderlab

shaderlab offset parameter explanation?

I was wondering if someone could explain to me how the Offset parameter in Shaderlab works. I read the documentation but my brain refuses to make sense out of it. What I want to do: I have several (transparent) sprites that should be drawn in correct order. The problem is that if two of the sprite are in the same x,y position but on different z positions I assume that the one closer to the camera (which looks in z-direction) will be drawn over the other one. However this seems to be only true if they are at ~1 unit apart. If the distance in z-direction is smaller (e.g 0.5) the behaviour seems to be random (meaning that the order seems to be affected by some other parameter as the distance to camera alone). I think that has something to do with depth and z-buffer (maybe the precision of the latter?) and thought i could solve that with Shaderlab's Offset parameter, but I have no clue how it is supposed to work. Any idea or documentation to read?

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

1 Reply

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

Answer by Jessy · Mar 08, 2011 at 02:12 PM

http://www.youtube.com/watch?v=f7zDKlsyu6s

http://www.youtube.com/watch?v=MlLvQxZv3h4

But in your case, it sounds like your problems could be solved simply by pushing the near clip plane farther away, and the far clip plane closer. The closer those two are to each other, the better. The depth buffer isn't linear, either. You'll get better results if the objects are closer to the near clip plane, all else being equal.

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 StephanK · Mar 08, 2011 at 03:33 PM 0
Share

Ah cool will try that. I remembered somewhere in the back of my head that the depth buffer precision isn't linear, but thought as my objects are close to the camera this wouldn't be a problem. Getting more precision by reducing the depth of the frustum is the clever bit I completely overlooked... ;)

avatar image StephanK · Mar 08, 2011 at 04:18 PM 0
Share

Hm, I already tried to reduce the depth of the frustum. Didn't remember it. But that didn't help. Even with the frustum being only 20 units long and the sprites 5units in front of the camera I have to separate them by 1 unit to get the correct order. Could the orthographic camera cause that problem?

avatar image Jessy · Mar 08, 2011 at 04:52 PM 0
Share

No. It sounds like your problem is based on rendering order. http://www.youtube.com/watch?v=N9IbcGpOcIg

I recommend moving them to different queues.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Getting horizontal gradient in unlit sprite shader even sprite is rotated 0 Answers

Adding normal map to Sprite shader 1 Answer

Sprite Shader not working in 5.6 0 Answers

clipping shader for OpenGL quad 0 Answers

Multiply Mode uses strange Alpha 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