using UnityEngine;
public static class MaterialExtensions {
public static void SetVector(this Material material,
string propertyName, float angle, Vector2 center = default(Vector2))
{
material.SetVector( propertyName, new Vector4(
Mathf.Cos(angle), Mathf.Sin(angle), center.x, center.y)
);
}
}
Although I do understand that I don’t need to pass in the entire matrix to achieve what I need, but the problem is that the effect I wanted is combining the rotation with the diffuse shader.
I tried using your shader and added the diffuse part, but it just gave errors
Shader "TextureRotateShader" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_2DRotationMatrix ("2D Rotation Matrix", Vector) = (1, 0, 0, 0)
}
Subshader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs.
#pragma exclude_renderers gles
#pragma vertex vert
#pragma fragment frag
struct v2f {
float4 position : SV_POSITION;
float2 uv_mainTex : TEXCOORD;
};
uniform float4 _MainTex_ST, _2DRotationMatrix;
v2f vert(float4 position : POSITION, float2 uv : TEXCOORD0) {
v2f o;
o.position = mul(UNITY_MATRIX_MVP, position);
float2x2 rotation = float2x2(
_2DRotationMatrix.x, -_2DRotationMatrix.y,
_2DRotationMatrix.y, _2DRotationMatrix.x
);
o.uv_mainTex = mul(rotation, uv * _MainTex_ST.xy) + _2DRotationMatrix.zw + _MainTex_ST.zw;
return o;
}
uniform sampler2D _MainTex;
fixed4 frag(float2 uv_mainTex : TEXCOORD) : COLOR {
return tex2D(_MainTex, uv_mainTex);
}
ENDCG
pass
{
combine texture + previous
CGPROGRAM
#pragma surface surf Lambert
fixed4 _Color;
uniform sampler2D _MainTex;
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
}
}
Fallback "VertexLit"
}