- Home /
A shader that rotate the texture on an object
I was trying to rotate the texture by setting the matrix, the shader that I used was the diffuse shader with a pass that sets the matrix.
I'm not familiar with shader at all so the I just edited as less as I could
Shader "Diffuse" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
fixed4 _Color;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
Pass{
SetTexture[_MainTex]
{
Matrix[_Matrix]
}
}
Fallback "VertexLit"
}
and I used the below code for rotation
AccumulatedTime += Time.deltaTime * Speed;
Matrix4x4 matrix = Matrix4x4.TRS(Vector2.zero, Quaternion.Euler(0, 0,AccumulatedTime), tiling);
renderer.material.SetTextureOffset("_MainTex", Offset);
renderer.material.SetMatrix("_Matrix1", matrix);
But the problem is that first: the shader then kills all lighting. Second problem is it only rotates the texture based on a corner probably (0,0), I wanted to rotate the texture from the center, so I thought maybe changing the UV would work..
Any ideas? Sorry for being such a noob about shaders.
Answer by $$anonymous$$ · Feb 15, 2013 at 12:43 AM
check out this forum: Forum
Thanks, although the lighting is still weird, but it did rotate on the center now :D
Im having some issues doing something similar but with multiple textures in the same shader rotating at different speeds.
Just out of curiosity, did you find a way to center pivot using the method in this thread? or did you convert to a fully shader based rotation from the linked thread?
Thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220613092721im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
How to hide a part of a GUITexture that rotate ? 1 Answer
rotate normal map 1 Answer