- 最后登录
- 2018-11-8
- 注册时间
- 2013-4-26
- 阅读权限
- 50
- 积分
- 1545
- 纳金币
- 79
- 精华
- 0
|
herry7x 发表于 2013-9-29 16:48
大神,求一个好用的shader和脚本,我试了半天也没写出来。没有用过matrix在shader里。 ...
Shader "RotateUV" {
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" "Queue"="Transparent+1"}
ZWrite Off
Blend One One
Pass {
Lighting Off
SetTexture [_MainTex]
{
constantColor [_Color]
matrix [_Rotation]
combine texture * constant
}
}
}
FallBack "Diffuse"
}
rotateuv.cs
using UnityEngine;
using System.Collections;
public class RotateUV : MonoBehaviour {
public float mfSpeed = 10.0f;
public Vector2 mRotationCenter = new Vector2(0.5f, 0.5f);
void OnUpdate()
{
Quaternion rot = Quaternion.Euler (0.0f, 0.0f, Time.time * mfSpeed);
Matrix4x4 m = Matrix4x4.TRS ( Vector3.zero, rot, Vector3.one );
Matrix4x4 t = Matrix4x4.TRS (-mRotationCenter, Quaternion.identity, Vector3.one);
Matrix4x4 t_inverse = Matrix4x4.TRS (mRotationCenter, Quaternion.identity, Vector3.one);
renderer.sharedMaterial.SetMatrix ("_Rotation", t_inverse*m*t);
}
} |
|