テクスチャバグシェーダMK-2 pic.twitter.com/RQrpXIHOEh
— 光属性のアルモジナ(VRChat勢) (@arumogina) June 29, 2019
//Box内に入ったものにZureを発生させる //ステンシルを使ってるため横にずれたぶんのステンシルからはみ出た部分は消えてしまう Shader "Custom/TexBug2" { Properties{ _DownSPD("DownSPD",Range(1,10)) = 1 _UpSPD("UpSPD",Range(1,10)) = 1 _MaxZure("MaxZure",Range(0,0.5)) = 0.1 _MaxZureWidth("MaxZureWidth",Range(0,0.5)) = 0.5 _Height("Heigth",float) = 2 _Width("Width",float) = 2 } SubShader{ //透明部分のあるテクスチャを使う場合 Tags{"Queue" = "Transparent+999999" "RenderType" = "Transparent"} Pass{ Cull Front ColorMask 0 Stencil{ Ref 1 Comp always ZFail replace Pass zero } } Pass{ ColorMask 0 Cull Back ZTest Greater Stencil { Ref 0 Comp always Pass replace } } GrabPass { "_GrabTexture" } Pass{ Blend SrcAlpha OneMinusSrcAlpha Cull Front ZTest Greater Stencil { Ref 1 Comp Equal Pass zero } CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex:POSITION; float4 uv:TEXCOORD0; }; struct v2f { float4 pos:SV_POSITION; float4 uv:TEXCOORD0; float4 gpos:TEXCOORD1; float4 lpos:TEXCOORD2; }; float _DownSPD; float _UpSPD; float _MaxZure; float _MaxZureWidth; float _Height; float _Width; float Pow(float val,int times){ float res = 1; for(int k=0;k<times;k++){ res *= val; } return res; } float rand(float2 co){ return frac(sin(dot(co.xy ,float2(12.9898,78.233))) * 43758.5453); } float GetNumByTime(){ float change_frec = _UpSPD / _DownSPD; float tm = _Time.y*change_frec*Pow(10,1);//小数部を1桁分、整数部に移動 float mx = trunc(tm);//小数部切り捨て return frac(mx/10000);//整数部5桁を小数部に移動,整数部切り捨て } //0~1の範囲に変換する float NormalizeHeight(float ypos){ return (ypos + _Height/2)/_Height; } //0~1の範囲に変換する float NormalizeWidth(float xpos){ return (xpos + _Width/2)/_Width; } v2f vert(appdata v){ v2f o; o.pos = UnityObjectToClipPos(v.vertex); o.lpos = v.vertex; o.gpos = ComputeGrabScreenPos(o.pos); o.uv = v.uv; return o; } sampler2D _MainTex; sampler2D _GrabTexture; float4 frag(v2f i) :SV_Target { float ny = NormalizeHeight(i.lpos.y); float gnbt = GetNumByTime(); [unroll(3)]//ずらす場所の数 for(int k=0;k<3;k++){ float t1 = rand(float2(gnbt,0.1+k)); float t2 = (rand(float2(gnbt,0.2+k))-0.5)*2*_MaxZureWidth; float t3 = t1+t2;//t1からt2分の距離をずらす float ty1 = min(t1,t3); float ty2 = max(t1,t3); if(ny >= ty1 && ny <= ty2){ float zure = rand(float2(gnbt,0.3+k))*_MaxZure; return tex2Dproj(_GrabTexture,float4(i.gpos.x+zure,i.gpos.yzw)); } } return tex2Dproj(_GrabTexture,i.gpos); } ENDCG }//Pass }//SubShader FallBack "Diffuse" }