UnityShader中怎么实现一个百叶窗效果

UnityShader中怎么实现一个百叶窗效果,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

成都创新互联,专注为中小企业提供官网建设、营销型网站制作、自适应网站建设、展示型网站设计、做网站等服务,帮助中小企业通过网站体现价值、有效益。帮助企业快速建站、解决网站建设与网站营销推广问题。

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);  } } }  }

关于UnityShader中怎么实现一个百叶窗效果问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。

分享标题:UnityShader中怎么实现一个百叶窗效果
标题网址:https://www.cdcxhl.com/article24/gecece.html

成都网站建设公司_创新互联,为您提供网站设计软件开发网站收录网页设计公司全网营销推广品牌网站设计

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都seo排名网站优化