Тут http://forum.unity3d.com/threads/rotation-of-texture-uvs-directly-from-a-shader.150482 обсуждался shader вращающий текстуру. Он работает везде ( Windows, Android 4.1 - 4.4., Android 5.1 ).
Вот его код:
- Код: Выделить всё
Shader "Custom/RotateUV" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_RotationSpeed ("Rotation Speed", Float) = 2.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert vertex:vert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
float _RotationSpeed;
void vert (inout appdata_full v) {
v.texcoord.xy -=0.5;
float s = sin ( _RotationSpeed * _Time );
float c = cos ( _RotationSpeed * _Time );
float2x2 rotationMatrix = float2x2( c, -s, s, c);
rotationMatrix *=0.5;
rotationMatrix +=0.5;
rotationMatrix = rotationMatrix * 2-1;
v.texcoord.xy = mul ( v.texcoord.xy, rotationMatrix );
v.texcoord.xy += 0.5;
}
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Я сделал небольшие изменения. Мне нужен поворот на 90 градусов. Без вращения.
Вот измененный код:
- Код: Выделить всё
Shader "Custom/Rotate90s" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_RotationSpeed ("Rotation Speed", Float) = 2.0
_RotationDegrees ("Rotation Degrees", Float) = 0.0
_isRotat ("isRotat", int) = 0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert vertex:vert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
float _RotationDegrees;
int _isRotat;
void vert (inout appdata_full v) {
v.texcoord.xy -=0.5;
if (_isRotat==1) { _RotationDegrees=4.712385; } // 90 degrees.
float s = sin ( _RotationDegrees);
float c = cos ( _RotationDegrees);
float2x2 rotationMatrix = float2x2( c, -s, s, c);
rotationMatrix *=0.5;
rotationMatrix +=0.5;
rotationMatrix = rotationMatrix * 2-1;
v.texcoord.xy = mul ( v.texcoord.xy, rotationMatrix );
v.texcoord.xy += 0.5;
}
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Он работает в Windows на Android 4.1 - 4.4.
Но не работает на Android 5.1 !!!!
Бьюсь уже вторую неделю.
Кто нибудь может подсказать, из за чего не работает?