Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by smuseus · Dec 01, 2015 at 03:55 PM · c#shadertextureuv coordinates

How to get precise pixel values form a Texture2D using uv coordinates.

I'm having a piece of geometry where several polygons share the same uv coordinate. Each of vertices of the polygons have coordinates that are mapped to a single pixel in the Texture2D (128x128).

This is the result: alt text Note that the Texture2D i'm using only contains fully red or blue pixels. The left image is filterMode set to Point, and the right is filterMode set to Billinear.

It seems to start interpolating, which I would believe is a result of inpresice uv-coordinates, but I don't understand why, mipmap is disabled and the UVs map to the exact pixel coordinate. What is strange is that if I "manually" define a float2( u, v ) inside the shader, the precise mapping seems to work.

Any ideas what causing this?

glitchs.png (36.9 kB)
Comment
Add comment · Show 3
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 Bunny83 · Dec 01, 2015 at 05:20 PM 0
Share

From your two screenshots it's not clear how your texture actually looks like and how your geometry of your sphere looks like. Am i right that the hexagons are actual geometry? You can't really map to exact "pixel coordinates" since uv coordinates are not bound to any kind of grid. Pixels / texels have a size. It makes a difference if you talk about the lower corner, the center or the upper corner of a texel. Pointfiltering usually corresponds to GL_Nearest.

Can you add your actual used texture and add more details on how you mapped it to the geometry? Is the sphere procedurally generated or in a modelling appllication?

avatar image smuseus Bunny83 · Dec 01, 2015 at 05:55 PM 1
Share

the hexagons consist of groups of 4 triangles, all sharing the same UV coordinate. They do not share vertexes with neighbors hexagons. For the red vertex group (see illustration), each vertex would have the coordinate of { 3 / 128, 0 }, given that the image is 128 pixels wide.

The exact texture is arbitrary, its every second pixel red or blue, if the uv-coords where exact non of the hexagon would be purple.

The geometry is procedural modeled in an modelling application. this tho shouldn't matter.

alt text

illustration.png (106.9 kB)
avatar image smuseus smuseus · Dec 01, 2015 at 06:01 PM 0
Share

If GL_Nearest worked the way I would have expected, at least vertices sharing the same uv coordinate would be rendered in the same color, ins$$anonymous$$d it seams to flicker between two values, depending on the camera angle.

1 Reply

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

Answer by smuseus · Dec 02, 2015 at 10:00 AM

Figured this out, I wasn't sampling the center of the pixel. The texel coordinate for a specific pixel at { x, y } would be :

 u = x / width + 0.5 / width;
 v = y / height + 0.5 / height;

Thanks Bunny83 for the reference.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing material in code doesn't update shader 3 Answers

Offset textures individually into specific world directions 2 Answers

Awesome Bump shader in Unty? 0 Answers

How to change a unique shaders property 1 Answer

Unity 1080p Video player 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