国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

UnityShader實現百葉窗效果

2020-01-23 20:45:56
字體:
來源:轉載
供稿:網友

本文實例為大家分享了UnityShader百葉窗展示的具體代碼,供大家參考,具體內容如下

shader實現以上百葉窗效果,主要通過shader實現C#只是做開關控制

看到一篇文章弄的比較復雜,覺得可以都通過shader來實現,就動手了。

shader定義了2張texture,自己隨便找2張圖片拖進去就行。

Shader "Unlit/NewUnlitShader"{ Properties { _MainTex ("Texture", 2D) = "white" {} _MainTex2 ("Texture2", 2D) = "white" {} _StartFlag("開始標記", float) = 0 _SpeedFactor("速度",Range(0.01,10)) = 0.1 _StartTime("時間初始標記,不要手動設置",float) = 1 _Column("百葉窗的列數",float ) = 5 } SubShader { Tags { "RenderType"="Opaque" } LOD 100  Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag // make fog work #pragma multi_compile_fog  #include "UnityCG.cginc"  struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; };  struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; };  sampler2D _MainTex; float4 _MainTex_ST;  sampler2D _MainTex2; float4 _MainTex2_ST;  float _StartFlag; float _Column; float _SpeedFactor; float _StartTime;  v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); return o; }  fixed4 frag (v2f i) : SV_Target { fixed4 col = 0; //_StartFlag 通過C#監聽鍵盤事件,設置為1,作為開始動畫的標記 //step(a,b) => if(b>=a) return 1 else return 0 //i.uv.x % (1/_Column) i.uv.x范圍是0-1,分成_Column份 每份(1/_Column) fixed result = _StartFlag * step( i.uv.x % (1/_Column) ,(_Time.y - _StartTime) * _SpeedFactor );  if( result == 0 ) { col = tex2D(_MainTex, i.uv); } else { col = tex2D(_MainTex2, i.uv); }  return col; } ENDCG } }}

C#控制開關,點擊鍵盤任意按鍵。掛到panel上

using System.Collections;using System.Collections.Generic;using UnityEngine; public class baiyechuang : MonoBehaviour {  // Use this for initialization Material mat; MeshRenderer meshRen; void Start () { meshRen = this.GetComponent<MeshRenderer> (); print (meshRen); mat = meshRen.material; print (mat); }  void OnGUI() { if (Input.anyKeyDown) {  Event e = Event.current;  if (e.isMouse) {  Debug.Log(e.button);  }  if (e.isKey)  {  if (e.keyCode == KeyCode.None)   return;  Debug.Log(e.keyCode); mat.SetFloat ("_StartTime", Time.timeSinceLevelLoad); mat.SetFloat ("_StartFlag", 1);  } } }  }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 德庆县| 余姚市| 西昌市| 文成县| 原阳县| 会泽县| 黄陵县| 绿春县| 安乡县| 大理市| 赤水市| 壶关县| 高密市| 新宁县| 滦平县| 温宿县| 武宣县| 浦县| 古丈县| 杂多县| 衡阳市| 前郭尔| 儋州市| 合川市| 平乡县| 新郑市| 留坝县| 乌兰县| 广元市| 惠水县| 娄烦县| 邮箱| 河津市| 紫阳县| 武陟县| 秦安县| 塔河县| 邹平县| 镇原县| 镇原县| 湄潭县|