Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Dolgsthrasir · Jun 06, 2012 at 04:30 PM · c#rotationshadertextureoffset

Offset textures individually into specific world directions

I am new to Unity and experimenting a bit with shaders, but now I'm stuck. So I hope you nice people can help me out.

My Scene has a simple cube with a texture assigned to it. So what I am doing is changing the offset of the texture over time, so the texture is moving down (easy, I know). But in that situation I do NOT want the top and bottom texture of the cube to move, only those on the side which are affected by lets say "world gravity", that drags them down. Is it possible to make some textures at the sides move and some (at top and bottom) not?

This even gets more complicated, when the cube is being rotated. The "gravity" effect would need to change for the textures, so they are being dragged into the right (world) direction (that means still down). (On the other hand, I don't want the textures to rotate with the object, but that's far less important to me at the moment. But any hint is also appreciated.) I thought it would be better to illustrate what I mean.

alt text

So I have no idea how to make the texture behave different for each side of the cube. Any help is appreciated!

illustration.jpg (107.7 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

2 Replies

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

Answer by Dolgsthrasir · Jun 08, 2012 at 03:53 PM

OK I think I've got it, at least it looks correct. Was even easier than I thought.

 float3 dir = normalize(mul( _World2Object, float4(0, 1, 0, 0) ).xyz);
 temp.xyzw = v.vertex.xyzw + Offset * float4(dir,0);
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
avatar image
0

Answer by Paulius-Liekis · Jun 06, 2012 at 05:58 PM

It is posible to do it in several ways:

First: simply keep a single "offset" vector and then project that offset on each plane in the vertex shader. Simply taking normal of each vertex into account will give you an offset of UV on the vertex. It is easy to implement, but it might be nor exactly what you want, because each plane will be unable to keep it's ofset once the object rotates.

Second: put different materials on each side and calculate texture offset in the script. Offset of each side is calcualted in the same way. This will allow you to keep offset on each side.

Comment
Add comment · Show 1 · 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 Dolgsthrasir · Jun 06, 2012 at 06:25 PM 0
Share

I think, at the moment, the first solution would be sufficient, since the object won't rotate over time, but the rotation is only performed by hand in the editor. I also thought about taking normals into account, but it still sounds difficult to a beginner like me :). Is there some tutorial on how to get the normals of each vertex in unity's shaders? I was searching for something like that, but couldn't find anything that was any helpful for my problem.

A material for each side would work for cubes, but later I want to transfer the shader to other structures as well. So I think it's better for me to try the first suggestion.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Flip over an object (smooth transition) 3 Answers

Location in relation to other objects rotation 1 Answer

How to texture an irregular (hexagon) shape (mesh) ? 1 Answer

How to fill texture that would be avaliable to ither shaders? 1 Answer

Unity crashes on play when generating texture. 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