- 最后登录
- 2017-5-15
- 注册时间
- 2012-3-1
- 阅读权限
- 90
- 积分
- 32973
  
- 纳金币
- 32806
- 精华
- 12
|
using UnityEngine;
using System.Collections;
public class RotateTexture : MonoBehaviour {
public float rotateSpeed = 10f;
public Vector2 pivot = new Vector2(0.5f, 0.5f);
public Texture texture;
// Use this for initialization
void Start () {
Material m = new Material (
"Shader "Rotating Texture" {" +
"roperties { _MainTex ("Base", 2D) = "white" {} }" +
"SubShader {" +
" Pass {" +
" Material { Diffuse (1,1,1,0) Ambient (1,1,1,0) }" +
" Lighting On" +
" SetTexture [_MainTex] {" +
" matrix [_Rotation]" +
" combine texture * primary double, texture" +
" }" +
" }" +
"}" +
"}"
);
m.mainTexture = texture;
renderer.material = m;
}
// Update is called once per frame
void Update () {
// Construct a rotation matrix and set it for the shader
Quaternion rotation = Quaternion.Euler(0, 0, Time.time * rotateSpeed);
Matrix4x4 r = Matrix4x4.TRS(Vector3.zero, rotation, Vector3.one);
Matrix4x4 t = Matrix4x4.TRS(-pivot, Quaternion.identity, Vector3.one);
Matrix4x4 tInv = Matrix4x4.TRS(pivot, Quaternion.identity, Vector3.one);
renderer.material.SetMatrix("_Rotation", tInv*r*t);
}
} |
|