Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 ungalyant2 · Mar 26, 2014 at 07:53 PM · shaderuv

Shaders and relative UVs

So I'm trying my hand at writing shaders at the moment. And I appreciate that what I want may not even be possible, but I have 2 questions:

Firstly - Can a shader in any way find out what section of the object it is currently drawing? For example, could I find out in a normalised fashion, if I'm currently operating on a pixel half way down the object's texture? UVs would normally help here, but in the scenario that I am using texture atlases, that flies out the window. I need to know in relation to the sub section of the larger texture, what I'm drawing, if that makes sense? Like if I could find out what the min and max UVs are of the object I'm currently rendering.

Example: I want pixels half way across a texture to become inverted in colour, and this shader is on an object that is part of a sprite sheet, and this particular frame has UVs of min(0.4, 0.6) max (0.5, 0.7), how can I find out from within the shader what those min and max UVs for this frame are?

Secondly - From my understanding, GrabPasses are only meant to grab the screen space behind the object you are trying to render, but all my attempts appear to be grabbing the entire screen, is this functionality correct? And if so, (and this kind of relates to the previous question) how can I find out what sub section of the screen my object occupies (I suspect this may be achieved via the use of matrices, but I'm really not highly educated in the area.)

Any help anyone could provide would be awesome, shaders seem like quite an introverted subject, the lack of intellisense makes them even harder to penetrate.

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
1
Best Answer

Answer by ungalyant2 · Apr 10, 2014 at 09:10 AM

I'm not sure if there's a more sublime solution that this, but I simply added a property for min and max UVs, and had an attached script provide each objects material with the relevant UV data.

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

20 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

Related Questions

Material offset relative to other game object 0 Answers

How do I get mesh data into post-processing shader (or render a mesh shader to a texture)? 0 Answers

Sprites consisting of two packed textures 0 Answers

U3: Beast Lightmapping + Nature / Soft Occlusion Shader 1 Answer

UV offset in surface 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