日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Shader --- 法阵

發(fā)布時(shí)間:2023/12/15 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Shader --- 法阵 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

? ? ? 發(fā)現(xiàn)去百度拉圖的時(shí)候竟然無意的拉了一張魔法陣的圖,所以就想看看能不能瞎做一個(gè)東西出來

(Shader?學(xué)習(xí)中ing)

其中模擬雨點(diǎn)鏈接? ?----? ?https://gameinstitute.qq.com/community/detail/125291

貼圖鏈接? ? ? ? ? ? ? ? ?----? ??http://www.cnblogs.com/yfish/p/6842406.html

效果圖如下,

Shader 代碼:

Shader "ShaderTest/_Magic" {properties{[HDR]_MainColor("Main Color",color) = (1,1,1,1)_MainTex("Main Texcoord",2D) = "while" {}_StarTex("Star Texcoord",2D) = "while" {}_Discard("Discard Value",range(0,9)) = 0_NormalScale("Noraml Scale",range(1,2)) = 0.1}SubShader{Tags{"RenderType"="Opaque" "Queue"="Transparent"}LOD 200pass{blend SrcAlpha oneZWrite offCGPROGRAM#include "UnityCG.cginc"#pragma vertex vert#pragma fragment fragstruct v2f{float4 pos : POSITION;fixed4 uv : TEXCOORD0;};sampler2D _MainTex,_StarTex;float4 _MainTex_ST,_StarTex_ST;float4 _MainColor;float _Discard;float _NormalScale;v2f vert(appdata_full v){v2f o;v.vertex += v.vertex * _NormalScale;float timer = _Time.y;v.vertex *= float4(_NormalScale,_NormalScale,_NormalScale,1);float4x4 rotate = float4x4(cos(timer),0,sin(timer),0,0,1,0,0,-sin(timer),0,cos(timer),0,0,0,0,1);//float4x4 scale = float4x4//(// _NormalScale,0,0,0,// 0,_NormalScale,0,0,// 0,0,_NormalScale,0,// 0,0,0,1//);float4x4 MVP = UNITY_MATRIX_MVP;//v.vertex = mul(scale,v.vertex);rotate = mul(MVP,rotate);o.pos = mul(rotate,v.vertex);o.uv.xy = v.texcoord.xy * _MainTex_ST.xy + _MainTex_ST.zw;o.uv.zw = v.texcoord.xy * _StarTex_ST.xy - _Time.x ;return o;}fixed4 frag(v2f v) : COLOR{fixed4 color = tex2D(_MainTex,v.uv.xy);fixed4 star = tex2D(_StarTex,v.uv.zw);// 這里是因?yàn)槲艺业降膱D片沒有Alpha通道,前兩天刷電腦,也沒有裝PS - - float star_c = (star.r + star.g + star.b);color += star;color *= _MainColor;float c = color.r + color.g + color.b;float2 uv = v.uv;// 這里是因?yàn)檫吘売幸粭l白線 不用PS的原因如上if(uv.x > 0.8 || uv.x < 0.2 || uv.y > 0.8 || uv.y < 0.2 || c < _Discard){discard;}return color;}ENDCG}pass{blend SrcAlpha SrcAlphaZWrite offCGPROGRAM#include "UnityCG.cginc"#pragma vertex vert#pragma fragment fragstruct v2f{float4 pos : POSITION;fixed2 uv : TEXCOORD0;};sampler2D _MainTex;float4 _MainTex_ST;float4 _MainColor;float _Discard;v2f vert(appdata_full v){v2f o;float timer = -_Time.y;float4x4 rotate = float4x4(cos(timer),0,sin(timer),0,0,1,0,0,-sin(timer),0,cos(timer),0,0,0,0,1);float4x4 MVP = UNITY_MATRIX_MVP;rotate = mul(MVP,rotate);o.pos = mul(rotate,v.vertex);o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);return o;}fixed4 frag(v2f v) : COLOR{fixed4 color = tex2D(_MainTex,v.uv);color *= _MainColor;float c = color.r + color.g + color.b;float2 uv = v.uv;if(uv.x > 0.8 || uv.x < 0.2 || uv.y > 0.8 || uv.y < 0.2 || c < _Discard){discard;}color.a = _MainColor.a;return color;}ENDCG}}}

C#改變顏色代碼如下

using System.Collections; using System.Collections.Generic; using UnityEngine;public class UpdateMagicColor : MonoBehaviour {[Range(-1000,1000)]public float m_ColorUpdateSpeed;private Color mainColor;private Material magicMaterial;private float tempColor, startColorValue = 0.6025f, endColorValue = 1.7982f;private float[] color;private int colorIndex = 1;void Start(){color = new float[3];magicMaterial = GetComponent<Renderer>().material;mainColor = magicMaterial.GetColor("_MainColor");color[0] = mainColor.r;color[1] = mainColor.g;color[2] = mainColor.b;}void Update(){tempColor += m_ColorUpdateSpeed * Time.deltaTime / 1000;if (tempColor > endColorValue){tempColor = endColorValue;m_ColorUpdateSpeed *= -1;}if (tempColor < startColorValue){tempColor = startColorValue;m_ColorUpdateSpeed *= -1;colorIndex++;colorIndex = colorIndex % 3;}color[colorIndex] = tempColor;mainColor.r = color[0];mainColor.g = color[1];mainColor.b = color[2];magicMaterial.SetColor("_MainColor",mainColor);} }

?

總結(jié)

以上是生活随笔為你收集整理的Shader --- 法阵的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。