Created
December 5, 2013 17:55
-
-
Save sugi-cho/7810138 to your computer and use it in GitHub Desktop.
テクスチャをばらまく系のイメージエフェクト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Custom/ImageParticleEffect" { | |
Properties { | |
_MainTex ("Base (RGB)", 2D) = "white" {} | |
_SampTex ("sampler tex", 2D) = "white" {} | |
_WebTex ("webcam tex", 2D) = "black" {} | |
_Scale ("sq scale", Float) = 10 | |
_Size ("sq size", Float) = 1 | |
} | |
CGINCLUDE | |
#include "UnityCG.cginc" | |
#include "Libs/Random.cginc" | |
#include "Libs/Transform.cginc" | |
#define Iteration 4 | |
#define Delta .1 | |
half _Scale,_Size; | |
sampler2D _MainTex,_SampTex,_WebTex; | |
half4 _MainTex_TexelSize; | |
half3 uva(half2 uv, half2 uv0, half h){ | |
half3 r3 = rand3(uv0 + h); | |
half2 center = uv0 + (r3.xy)/_Scale; | |
half3 wt = tex2D(_WebTex, center).rgb; | |
float size = _Size*wt; | |
uv = (uv - center)*_Scale*1/size+0.5; | |
uv = rotate2D(uv, _Time.z*dot(uv0,uv0), half2(0.5,0.5)); | |
uv = saturate(uv); | |
half a = fmod(uv.x,1)*fmod(uv.y,1)>0; | |
return half3(uv, a*0.5); | |
} | |
fixed4 frag(v2f_img i) : COLOR{ | |
half2 | |
uv0,uv1,uv2,uv3; | |
uv0=uv1=uv2=uv3 = floor(i.uv * _Scale) - 0.5; | |
uv1.x = uv2.x = uv0.x+1; | |
uv2.y = uv3.y = uv0.y+1; | |
uv0 /= _Scale; | |
uv1 /= _Scale; | |
uv2 /= _Scale; | |
uv3 /= _Scale; | |
half3 c = 0; | |
for(half h = 0; h < Iteration; h = h + Delta){ | |
half3 uvA; | |
uvA = uva(i.uv, uv0, h); | |
c += uvA.z * tex2D(_SampTex, uvA.xy); | |
uvA = uva(i.uv, uv1, h); | |
c += uvA.z * tex2D(_SampTex, uvA.xy); | |
uvA = uva(i.uv, uv2, h); | |
c += uvA.z * tex2D(_SampTex, uvA.xy); | |
uvA = uva(i.uv, uv3, h); | |
c += uvA.z * tex2D(_SampTex, uvA.xy); | |
} | |
return half4(c,1); | |
} | |
ENDCG | |
SubShader { | |
ZTest Always Cull Off ZWrite Off | |
Fog { Mode off } | |
ColorMask RGB | |
pass{ | |
CGPROGRAM | |
#pragma fragmentoption ARB_precision_hint_fastest | |
#pragma vertex vert_img | |
#pragma fragment frag | |
#pragma target 3.0 | |
#pragma glsl | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment