查看: 1314|回复: 5
打印 上一主题 下一主题

以贴图中心旋转

[复制链接]

2508

主题

2

听众

3万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
32806
精华
12

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2012-4-12 15:29:03 |只看该作者 |倒序浏览
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);



        }



}
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

2508

主题

2

听众

3万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
32806
精华
12

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

沙发
发表于 2012-11-7 09:15:44 |只看该作者
发现看的人还是蛮多的,但是没有人顶个
回复

使用道具 举报

955

主题

164

听众

7万

积分

版主

Rank: 7Rank: 7Rank: 7

纳金币
59338
精华
28

活跃会员 荣誉管理 突出贡献 优秀版主 论坛元老

板凳
发表于 2012-11-7 11:58:55 |只看该作者
呵呵,用力顶起感谢分享
回复

使用道具 举报

may    

8830

主题

81

听众

7万

积分

首席设计师

Rank: 8Rank: 8

纳金币
52344
精华
343

最佳新人 热心会员 灌水之王 活跃会员 突出贡献 荣誉管理 论坛元老

地板
发表于 2012-11-19 01:42:40 |只看该作者
顶下,支持楼主的分享!
回复

使用道具 举报

700

主题

1

听众

1万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
16564
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

5#
发表于 2012-11-28 17:24:17 |只看该作者
www.narkii.com这里好东西很多。
回复

使用道具 举报

2508

主题

2

听众

3万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
32806
精华
12

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

6#
发表于 2012-11-28 17:28:02 |只看该作者
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-7-21 09:20 , Processed in 0.079179 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部