- Home /
Question by
$$anonymous$$ · May 20, 2011 at 06:51 PM ·
texture2d rotationmatrix4x4
2d Texture Rotation Problem
Hello. I have created this shader to rotate the texture, but the axis of rotation is not that I want (see the picture). How can I fix it?
Shader "Decal Rotation" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Spec Color", Color) = (1,1,1,1)
_Emission ("Emissive Color", Color) = (0,0,0,0)
_Shininess ("Shininess", Range (0.01, 1)) = 0.7
_MainTex ("Base (RGB)", 2D) = "white" {}
_DecalTex ("Decal (RGBA)", 2D) = "black" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 150
Material {
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
Pass {
Lighting On
SeparateSpecular On
SetTexture [_MainTex] {matrix [_Rotation] combine texture * primary double, texture}
SetTexture [_DecalTex] {combine texture lerp (texture) previous}
}
}
Fallback "VertexLit", 1
}
The script attached is:
public bool RotateMainTexture = true;
void Update()
{
if(RotateMainTexture)
{
rot = Quaternion.Euler (0, 0, Time.time * rotateSpeed);
m = Matrix4x4.TRS (new Vector2(0,0), rot,new Vector3(1,1,1));
renderer.material.SetMatrix ("_Rotation", m);
}
}
Comment
Best Answer
Answer by Jessy · May 20, 2011 at 07:33 PM
When I do this, I center my UVs around 0, instead of .5. Otherwise, the math gets complex, or you need to multiply three matrices.
http://forum.unity3d.com/threads/32354-matrix-rotation-for-uvs?p=212096&viewfull=1#post212096
Thanks, I just offset the uv and worked for me, thanks again.
hey
How do you center your uvs around 0 ins$$anonymous$$d of 0.5? I'm having the same problem about the rotation axis.