I have been looking through the forums and google for ages to find a way of rotating a texture from within the shader. Is there some sort of built in texture handling for this or some operation that can be used on the UVs? Panning is quite simple as just adding to the UVs essentially but for rotation i cannot even begin to figure out a way to do it.
I have read through many posts with no answers so i figured i would try a post on it myself, any help at all would be welcome but know that i fully understand how to rotate it from script but that is definitely not what i want for specific reasons.
So to summarize: I want to rotate a texture/uvs in a CG shader and NOT through script (though i realize and acknowledge it is fully possible to do so and it has many merits.)
I need to move my texture rotation and I try so use your shader mixed with my CG shader
But I have a problem.
I use this C# script to calculate my rotationMatrix
using UnityEngine;
using System.Collections;
public class RotateUVs : MonoBehaviour {
public float rotateSpeed = 10f;
public Vector2 pivot = new Vector2(0.5f, 0.5f);
protected void Update() {
// Construct a rotation matrix and set it for the shader
Matrix4x4 t = Matrix4x4.TRS(-pivot, Quaternion.identity, Vector3.one);
Quaternion rotation = Quaternion.Euler(0, 0, Time.time * rotateSpeed);
Matrix4x4 r = Matrix4x4.TRS(Vector3.zero, rotation, Vector3.one);
Matrix4x4 tInv = Matrix4x4.TRS(pivot, Quaternion.identity, Vector3.one);
renderer.material.SetMatrix("_Rotation", tInv*r*t);
}
}
Rea thank you soo much!!! I want know where you can find this solution because I try to implement this by wikipedia Rotation matrix - Wikipedia and after a lot of time I coldnot found any solution!!!
This Shader works great, however I would like for this same exact thing except for the texture to go around the xaxis rather then the Y axis, how would I go about doing that?
This thread has the closest solution to what I’m looking for and I thank everyone for their contributions!
I’m stuck trying to incorporate MULTIPLE textures in this shader that all rotate at speeds independent from each other.
I’m realizing my problem lies with in the vert function, I would need to somehow modify two sets of uv’s one for each texture since it’s not the texture that’s rotating but the uv’s correct? I’ve tried creating a new uvset in struct Input but I wasn’t able to get that to work.
This thread was very useful for me. I used a shader to rotate a texture to show it on my GUI with Graphics.DrawTexture.
However I don’t want the texture to rotate forever, but just a certain amount of degrees on demand. I know I can access the shader properties to modify, for example, a variable let’s say “RotateDegrees”. But, which code should I write on the Shader? Anyone?
Thanks a lot
Those are forum tags for bold. So those are just to make the “-sin” bold.
To not make it time dependent in the shader, just replace _RotationSpeed * _Time with _RotateDegrees for example and make _RotateDegrees your input property.