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
0
Question by Rush3fan · Jul 26, 2012 at 05:50 AM · animationtexturematerialrotatespin

Spin a texture in just any material -is it possible?

I was just looking for more ways to UV animate textures, but with limited success. All I want to do is access the matrix and spin it. I don't know if most shaders support modifying the matrix, but I just wanted to check and make sure I wasn't missing something. I would really just like to be able to modify any material in general.

Here is the code I've been messing with:

var mtrx:Matrix4x4; private var okString:String; var spinme:Material;

function Start() { mtrx=spinme.GetMatrix("_Rotation");

}

function Update() {

var rot=Quaternion.Euler(Time.time*30,Time.time*30,Time.time*30);

mtrx=Matrix4x4.TRS(Vector3.zero,rot,Vector3(1,1,1) ); spinme.SetMatrix("_Rotation",mtrx);

}

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

Answer by ScroodgeM · Jul 27, 2012 at 09:26 AM

Materials are supports matrix deformations, but shader should support it too. by default, shaders are doesn't. so you need a little shader modifications to do it.

example shader that supports texture matrix deformations

Shader "Unity Answers/Diffuse with material matrix" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } LOD 200

     CGPROGRAM
     #pragma surface surf Lambert
 
     sampler2D _MainTex;
     float4x4 _Matrix0;

     struct Input
     {
         float2 uv_MainTex;
     };

     void surf (Input IN, inout SurfaceOutput o)
     {
         fixed4 c = tex2D(_MainTex, mul(_Matrix0, float4(IN.uv_MainTex, 0, 0)).xy);
         o.Albedo = c.rgb;
         o.Alpha = c.a;
     }
     ENDCG
 }
 Fallback "VertexLit"

}

example script that deformates texture using matrix

using UnityEngine;
using System.Collections;
public class Matrix2Material : MonoBehaviour
{
    public Material Material2SetMatrix;
    void Update()
    {
        Matrix4x4 m = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, 0f, Time.time * 10f), Vector3.one);
        Material2SetMatrix.SetMatrix("_Matrix0", m);
    }
}
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 Rush3fan · Aug 02, 2012 at 08:51 AM 0
Share

Alright.. so I have to mod every shader that I want to spin. This should be useful. Thanks!

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Gameobject Texture Distortion -1 Answers

Material Not Reverting Back 2 Answers

Rotate Texture 1 Answer

What is wrong with my shader? 1 Answer

Sprite animation from 2D to 3D 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