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
-1
Question by absameen · Sep 07, 2012 at 11:01 AM · shaderuvs

Manipulate Texture UVs with Shader

How can we manipulate a texture's UVs from a shader?

I've taken a look at the Shader Reference, but am still quite new to shaders and would like to be pointed in the right direction. Edit: Your help is greatly appreciated, sorry if the question was too vague.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by ScroodgeM · Sep 07, 2012 at 12:56 PM

which kind of shader are you asking about?

for example, for surface shaders, you can modify IN.uv_TexName parameter.

this is usual line to read rgb value from tex to model surface:

 o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;

this will swap X and Y of texture's UV:

 o.Albedo = tex2D(_MainTex, float2(IN.uv_MainTex.y, IN.uv_MainTex.x)).rgb;
Comment
Add comment · Show 5 · 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 absameen · Sep 07, 2012 at 02:02 PM 0
Share

What I'm trying to do is manipulate the UVs of a texture that will be drawn OnGUI with Graphics.DrawTexture and a material with a custom shader. Thanks for the information, I think I'll have to do some more reading on shaders to get a better grasp of how they work.

avatar image ScroodgeM · Sep 07, 2012 at 06:47 PM 0
Share

why don't you want to change texture mapping by changing it's offset and tiling in material? if you have only one object that draws with some material you can use these settings ins$$anonymous$$d of creating own shader

avatar image absameen · Sep 07, 2012 at 07:51 PM 0
Share

That's a good point, but the effect I want to achieve is more than just offsetting or tiling. Say for example you wanted to animate a texture's UVs to produce different distortion effects.

avatar image ScroodgeM · Sep 07, 2012 at 08:07 PM 0
Share

check this also:

http://answers.unity3d.com/questions/268236/surface-shader-with-material-matrix.html

avatar image Galactic_Muffin · Feb 18, 2020 at 04:01 AM 0
Share

Surface shaders are for pleebs. We want to know how to do this with a vert and frag shader setup. ;)

avatar image
0

Answer by Markus_T · Feb 18, 2020 at 11:26 AM

It might be easier than you think. You really just need to be creative with even simple vertex/fragment shaders. If you look at the link below, then whenever you see

o.uv =...

you're really just dealing with a vector2. Manipulate the values of that vector in creative ways (translate them, multiply them, swap them) and you'll see you get interesting results.

https://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html

For example

 // make your texture appear half as big
 o.uv = v.uv * 2;
 
 // use your object's vertices as UV data
 o.uv = mul(unity_ObjectToWorld, v.vertex).xz;
 
 // creates a weird tartan pattern
 float bentU = sin(v.uv.x + v.vertex.x * 2);
 float bentV = sin(v.uv.y + v.vertex.z * 3);
 o.uv = float2(bentU, bentV);

So, just be creative with your math!

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

11 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

Related Questions

Blending between two parts of a texture atlas, using another texture atlas as an Alpha Channel 0 Answers

Getting projector shader to conform to UVs 0 Answers

How to edit each texture of a cubemap in a shader? 0 Answers

How do I set up eye pupil specific UV animation in Unity? 2 Answers

What's the Unity shader equivalent of gl_FragCoord? 0 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