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
2
Question by Gremory · May 25, 2013 at 12:59 AM · shadertexturerotatetranslate

Translate or Rotate a texture of a cube

Hello, I've seen an example and tried to apply it to a cube where I selected a texture/shader.

This doesn't seem to do anything to my cube, and I would like to see the texture translate or rotate on my cube.

 var rotateSpeed = 30;
 var texture : Texture;
 
 function Start () {
         var m : Material = new Material (
             "Shader \"Rotating Texture\" {" +
             "Properties { _MainTex (\"Base\", 2D) = \"white\" {} }" +
             "SubShader {" +
             "    Pass {" +
             "        Material { Diffuse (1,1,1,0) Ambient (1,1,1,0) }" +
             "        Lighting On" +
             "        SetTexture [_MainTex] {" +
             "            matrix [_Rotation]" +
             "            combine texture * primary double, texture" +
             "        }" +
             "    }" +
             "}" +
             "}"
         );
         m.mainTexture = texture;
         this.renderer.material = m;
 }
 
 function Update () {
     // Construct a rotation matrix and set it for the shader
         var rot = Quaternion.Euler (0, 0, Time.time * rotateSpeed);
         var m = Matrix4x4.TRS (Vector3.zero, rot, Vector3(1,1,1) );
         this.renderer.material.SetMatrix ("_Rotation", m);
 }

Thank you

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

Answer by clunk47 · May 25, 2013 at 02:17 AM

Well I've done a simple script to make a texture move, the settings are public in the inspector. This is in C#, but should be easy for you to figure out how to put in JS. If you can't figure out how just let me know and I'll help. I use this for things like water, lava, whatever.. This allows movement of texture and normal map, just use the checkboxes in the inspector.

 public class TexOffset : MonoBehaviour 
 {
     public float scrollSpeedX = 0.1f;
     public float scrollSpeedY = 0.1f;
     public bool main = true;
     public bool bump = true;
     
     void Update () 
     {
         float offsetX = scrollSpeedX * Time.time;
         float offsetY = scrollSpeedY * Time.time;
         if(main)
         {
             renderer.material.SetTextureOffset("_MainTex", new Vector2(offsetX, offsetY));
         }
         if(bump)
         {
             renderer.material.SetTextureOffset("_BumpMap", new Vector2(offsetX, offsetY));
         }
     }
 }
 

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 illustir · Apr 21, 2015 at 05:28 PM 0
Share

This doesn't make it rotate though.

avatar image
0

Answer by Gremory · May 25, 2013 at 02:43 PM

Thankyou very much, here is the code I used.

 public var scrollSpeedX:float = 0.0;
 public var scrollSpeedY:float = 0.1;
 
 public var main = true;
 public var bump = true;
 
 function Update() {
     var offsetX:float = scrollSpeedX * Time.time;
     var offsetY:float = scrollSpeedY * Time.time;
     if(main) {
         this.renderer.material.SetTextureOffset("_MainTex", new Vector2(offsetX,offsetY));
     }
     if(bump) {
         this.renderer.material.SetTextureOffset("_BumpMap", new Vector2(offsetX,offsetY));
     }
 }

Unfortunatly the material doesnt seem to support BumpMap, so it gives an error on that property. But beside that, it works like a charm.

The only problem now, is that while the "skybox" scrolls, I can see the divisions between them, is there a way to solve that?

Comment
Add comment · Show 2 · 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 clunk47 · May 25, 2013 at 04:07 PM 1
Share

Just uncheck the "Bump" box in the inspector to resolve that first issue. If(bump) is checking if that statement is true or not. If you uncheck that box, it won't try to move a bumpmap that doesn't exist. In order to fix the second issues, you need a seamless texture. This probably isn't appropriate for a skybox, I use it for something with a seamless texture where you can't tell it's a texture repeating. I'd use a sky DO$$anonymous$$$$anonymous$$ Simply model a sphere in Blender or something, flip the normals where they are facing in, unwrap the sphere and apply a uv map to it. Then you wouldn't even need this script. You would just rotate the sphere itself.

avatar image illustir · Apr 21, 2015 at 05:28 PM 0
Share

This also does not make it rotate.

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

15 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

Related Questions

Hatching shader (Two o.Albedo ?) 1 Answer

Question about a good textures / terrain shader 1 Answer

A node in a childnode? 1 Answer

Dynamic Shader to Outline Adjacent Textures? 0 Answers

Creating a shader that shows a texture through a decal 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