Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 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
1
Question by Eimhin · Apr 08 at 10:05 AM · shadersgraphicspacking

Packing multiple UInts into Mesh Data (UVs) with Shader Graph?

I am currently sending small valued unsigned integers to a shader graph. The values are used as indices for the Sample Texture 2D Array node, so they select which texture to use and hence could be small integer values as there aren't many textures in the 2D array. I send 9 values which I am currently sending as vertex colors and UVs on a runtime generated mesh. So for instance one index value is sent as the red channel of the vertex color, etc. My shader currently works, but I was hoping to optimize it by packing in multiple values into single float so that for instance all 9 values could be sent in just the vertex color r, g, b channels (Using UVs is also an option). I currently pack the values into the floats and use a custom node such as

void UnpackVector_float(float In, out float X, out float Y, out float Z) { uint uIn = asuint(In); Z = (uIn << 24) >> 24; Y = (uIn << 16) >> 24; X = (uIn << 8) >> 24; }

to unpack them in the shader. I also set some of the exponent bits in case the float would be set to 0 because of denormalization. If I hardcode an input float into this unpack function in the shader graph it works fine, but when the data comes from the vertex color node or the UV nodes it doesn't work and produces a glitchy effect seen in the image, which I presume happens because fractional indicies are passed to the Sample Texture 2D Array node. alt text From my research it seems like the vertex color data or UV data is not passed to the GPU as full 32 bit floats and is compressed or is imprecise for non 0..1 range floats. Is there any way around this? I would want to be able to pass binary/uint data to the shader if possible to get around these issues, but I don't believe this is possible in shader graph? Is there a way to pack these indicies in the vertex color or UVs that will maintain its precision?

capture.png (15.9 kB)
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 Eimhin · Apr 10 at 05:50 AM

I've ended up using a different approach of storing the data by shifting it in decimal. For instance, one value can be packed as the one, ten and hundred digits, and another packed in the thousand, ten thousand, and hundred thousand digits (e.g. putting 123 and 987 as 123987) etc. This should work in a UV channel since the UV values shouldn't be clamped and 32 bit floats can exactly represent integers up to 2^24. Not ideal, but solves the problem for now.

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

168 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Wierd shading in UV seams 0 Answers

Send vertice shader changes to surface shader 0 Answers

World Space Diffuse Shader with Normal Map 0 Answers

Rendering Particle Systems to Command Buffer 1 Answer

Custom shader remove shine 2 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