pixi-filters
PixiJSのGLSLエフェクトリポジトリ。
ここから各エフェクトごとにあるsrcの下からフラグメントシェーダーを参照。
RPGツクール向けのエフェクトコード。godrayなど。いいかんじのエフェクトGLSLコードがまとまっている。PixiJSのフィルタからフォークしたもの。
Advanced Bloom
https://gyazo.com/779a5709474967b726b337576eb84ea2
code:AdvancedBloom.HLSL
Shader "Unlit/advanced-bloom"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_BloomTex("Bloom Texture", 2D) = "white" {}
_Brightness("Brightness", float) = 1.0
_BloomScale("Bloom Scale", float) = 1.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _BloomTex;
float4 _BloomTex_ST;
float _Brightness;
float _BloomScale;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
float4 bloom = tex2D(_BloomTex, i.uv);
col.rgb *= _Brightness;
float lum = dot(bloom, float3(0.299, 0.587, 0.114)); // ITU-R BT.601
col.rgb += lum * _BloomScale;
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
Color Replace
https://gyazo.com/94e992503e4c7413cb629eb9aa44bc4a
code:ColorReplace.HLSL
Shader "Unlit/color-replace"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_OriginalColor ("Original Color", Color) = (0.0, 1.0, 0.0)
_NewColor ("New Color", Color) = (1.0, 0.0, 1.0)
_Threshold ("Threshold", float) = 1.732
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float3 _OriginalColor;
float3 _NewColor;
float _Threshold;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
float3 colDiff = _OriginalColor - col.rgb / max(col.a, 0.0000000001);
float colDistance = length(colDiff);
float replace = step(colDistance, _Threshold);
col.rgb = lerp(col.rgb, (_NewColor) * col.a, replace);
// col.rgb = lerp(col.rgb, (_NewColor + colDiff) * col.a, replace);
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
Glitch
https://gyazo.com/566a19831bc77dcc8824fd19278e7511
https://gyazo.com/445d37c6c07ca7eb31d3f265c991b090
code:Glitch.HLSL
Shader "Unlit/glitch"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Dimensions ("Dimentions XY", Vector) = (1.0, 1.0, 0.0, 0.0)
_FilterArea ("Filter Area", Vector) = (1.0, 1.0, 1.0, 1.0)
_SinDir ("Sin Dir", float) = 1.0
_CosDir ("Cos Dir", float) = 1.0
_Offset("Offset", float) = 0.0
_FillMode ("Fill Mode", int) = 1
_FilterClamp("Filter Clamp", Vector) = (0.0, 0.0, 1.0, 1.0)
_Seed("Seed", float) = 1.0
_Red("Red shift", Vector) = (-0.1, 0.0, 0.0, 0.0)
_Green("Green shift", Vector) = (0.0, -0.1, 0.0, 0.0)
_Blue("Blue shift", Vector) = (0.1, 0.0, 0.0, 0.0)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
static int TRANSPARENT = 0;
static int ORIGINAL = 1;
static int LOOP = 2;
static int CLAMP = 3;
static int MIRROR = 4;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _Dimensions;
float4 _FilterArea;
float _SinDir;
float _CosDir;
float _Offset;
int _FillMode;
float4 _FilterClamp;
float _Seed;
float4 _Red;
float4 _Green;
float4 _Blue;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float2 coord = (i.uv * _FilterArea.xy) / _Dimensions.xy;
float4 col = tex2D(_MainTex, i.uv);
if (coord.x > 1.0 || coord.y > 1.0) return col;
float aspect = _ScreenParams.x / _ScreenParams.y;
float cx = coord.x - 0.5;
float cy = (coord.y - 0.5) * aspect;
float ny = (-_SinDir * cx + _CosDir * cy) / aspect + 0.5;
// displacementMap: repeat
// ny = ny > 1.0 ? ny - 1.0 : (ny < 0.0 ? 1.0 + ny : ny);
// displacementMap: mirror
ny = ny > 1.0 ? 2.0 - ny : (ny < 0.0 ? -ny : ny);
//float4 dc = tex2D(_DisplacementMap, float2(0.5, ny));
float4 dc = tex2D(_MainTex, float2(0.5, ny));
float displacement = (dc.r - dc.g) * (_Offset / _FilterArea.x);
coord = i.uv + float2(_CosDir * displacement, _SinDir * displacement * aspect);
if (_FillMode == CLAMP) {
coord = clamp(coord, _FilterClamp.xy, _FilterClamp.zw);
} else {
if( coord.x > _FilterClamp.z ) {
if (_FillMode == TRANSPARENT) {
clip(-1);
} else if (_FillMode == LOOP) {
coord.x -= _FilterClamp.z;
} else if (_FillMode == MIRROR) {
coord.x = _FilterClamp.z * 2.0 - coord.x;
}
} else if( coord.x < _FilterClamp.x ) {
if (_FillMode == TRANSPARENT) {
clip(-1);
} else if (_FillMode == LOOP) {
coord.x += _FilterClamp.z;
} else if (_FillMode == MIRROR) {
coord.x *= -_FilterClamp.z;
}
}
if( coord.y > _FilterClamp.w ) {
if (_FillMode == TRANSPARENT) {
clip(-1);
} else if (_FillMode == LOOP) {
coord.y -= _FilterClamp.w;
} else if (_FillMode == MIRROR) {
coord.y = _FilterClamp.w * 2.0 - coord.y;
}
}
else if (coord.y < _FilterClamp.y) {
if (_FillMode == TRANSPARENT) {
clip(-1);
}
else if (_FillMode == LOOP) {
coord.y += _FilterClamp.w;
}
else if (_FillMode == MIRROR) {
coord.y *= -_FilterClamp.w;
}
}
}
col.r = tex2D(_MainTex, coord + _Red * (1.0 - _Seed * 0.4) / _FilterArea.xy).r;
col.g = tex2D(_MainTex, coord + _Green * (1.0 - _Seed * 0.4) / _FilterArea.xy).r;
col.b = tex2D(_MainTex, coord + _Blue * (1.0 - _Seed * 0.4) / _FilterArea.xy).r;
col.a = tex2D(_MainTex, coord).a;
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
Godray
https://gyazo.com/9d0b0cab11c31b741907889ecdd04cfd
code:Godray.HLSL
Shader "Unlit/godray"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_FilterArea("Filter Area", Vector) = (0.0, 0.0, 1.0, 1.0)
_Dimensions("Dimension XY", Vector) = (1.0, 1.0, 0.0, 0.0)
_Light("Light XY", Vector) = (1.0, 1.0, 0.0, 0.0)
_Parallel ("Parallel", float) = 1.0
_Gain ("Gain", float) = 1.0
_Lacunarity ("Lacunarity", float) = 1.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _FilterArea;
float2 _Dimensions;
float2 _Light;
float _Gain;
float _Lacunarity;
float3 mod(float3 x, float3 y)
{
return x - floor(x * (1.0 / y)) * y;
}
float3 mod289(float3 x)
{
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
float4 mod289(float4 x)
{
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
float4 permute(float4 x)
{
return mod289(((x * 34.0) + 1.0) * x);
}
float4 taylorInvSqrt(float4 r)
{
return 1.79284291400159 - 0.85373472095314 * r;
}
float3 fade(float3 t)
{
return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
}
// Classic Perlin noise, periodic variant
float pnoise(float3 P, float3 rep)
{
float3 Pi0 = mod(floor(P), rep); // Integer part, modulo period
float3 Pi1 = mod(Pi0 + (1.0).xxx, rep); // Integer part + 1, mod period
Pi0 = mod289(Pi0);
Pi1 = mod289(Pi1);
float3 Pf0 = frac(P); // fracional part for interpolation
float3 Pf1 = Pf0 - (1.0).xxx; // fracional part - 1.0
float4 ix = float4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
float4 iy = float4(Pi0.yy, Pi1.yy);
float4 iz0 = Pi0.zzzz;
float4 iz1 = Pi1.zzzz;
float4 ixy = permute(permute(ix) + iy);
float4 ixy0 = permute(ixy + iz0);
float4 ixy1 = permute(ixy + iz1);
float4 gx0 = ixy0 * (1.0 / 7.0);
float4 gy0 = frac(floor(gx0) * (1.0 / 7.0)) - 0.5;
gx0 = frac(gx0);
float4 gz0 = (0.5).xxxx - abs(gx0) - abs(gy0);
float4 sz0 = step(gz0, (0.0).xxxx);
gx0 -= sz0 * (step(0.0, gx0) - 0.5);
gy0 -= sz0 * (step(0.0, gy0) - 0.5);
float4 gx1 = ixy1 * (1.0 / 7.0);
float4 gy1 = frac(floor(gx1) * (1.0 / 7.0)) - 0.5;
gx1 = frac(gx1);
float4 gz1 = (0.5).xxxx - abs(gx1) - abs(gy1);
float4 sz1 = step(gz1, (0.0).xxxx);
gx1 -= sz1 * (step(0.0, gx1) - 0.5);
gy1 -= sz1 * (step(0.0, gy1) - 0.5);
float3 g000 = float3(gx0.x, gy0.x, gz0.x);
float3 g100 = float3(gx0.y, gy0.y, gz0.y);
float3 g010 = float3(gx0.z, gy0.z, gz0.z);
float3 g110 = float3(gx0.w, gy0.w, gz0.w);
float3 g001 = float3(gx1.x, gy1.x, gz1.x);
float3 g101 = float3(gx1.y, gy1.y, gz1.y);
float3 g011 = float3(gx1.z, gy1.z, gz1.z);
float3 g111 = float3(gx1.w, gy1.w, gz1.w);
float4 norm0 = taylorInvSqrt(float4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
g000 *= norm0.x;
g010 *= norm0.y;
g100 *= norm0.z;
g110 *= norm0.w;
float4 norm1 = taylorInvSqrt(float4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
g001 *= norm1.x;
g011 *= norm1.y;
g101 *= norm1.z;
g111 *= norm1.w;
float n000 = dot(g000, Pf0);
float n100 = dot(g100, float3(Pf1.x, Pf0.yz));
float n010 = dot(g010, float3(Pf0.x, Pf1.y, Pf0.z));
float n110 = dot(g110, float3(Pf1.xy, Pf0.z));
float n001 = dot(g001, float3(Pf0.xy, Pf1.z));
float n101 = dot(g101, float3(Pf1.x, Pf0.y, Pf1.z));
float n011 = dot(g011, float3(Pf0.x, Pf1.yz));
float n111 = dot(g111, Pf1);
float3 fade_xyz = fade(Pf0);
float4 n_z = lerp(float4(n000, n100, n010, n110), float4(n001, n101, n011, n111), fade_xyz.z);
float2 n_yz = lerp(n_z.xy, n_z.zw, fade_xyz.y);
float n_xyz = lerp(n_yz.x, n_yz.y, fade_xyz.x);
return 2.2 * n_xyz;
}
float turb(float3 P, float3 rep, float lacunarity, float gain)
{
float sum = 0.0;
float sc = 1.0;
float totalgain = 1.0;
for (float i = 0.0; i < 6.0; i++)
{
sum += totalgain * pnoise(P * sc, rep);
sc *= lacunarity;
totalgain *= gain;
}
return abs(sum);
}
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float d;
float aspect = _ScreenParams.x / _ScreenParams.y;
float2 coord = i.uv * _FilterArea.xy / _Dimensions.xy;
float _cos = _Light.x;
float _sin = _Light.y;
d = (_cos * coord.x) + (_sin * coord.y * aspect);
float dx = coord.x - _Light.x / _Dimensions.x;
float dy = (coord.y - _Light.y / _Dimensions.y) * aspect;
float dis = sqrt(dx * dx + dy * dy) + 0.00001;
d = dy / dis;
float3 dir = float3(d, d, 0.0);
float noise = turb(dir + float3(time, 0.0, 62.1 + time) * 0.05, float3(480.0, 320.0, 480.0), _Lacunarity, _Gain);
noise = lerp(noise, 0.0, 0.3);
//fade vertically.
float mist = noise * (1.0 - coord.y);
float4 col = tex2D(_MainTex, i.uv);
col.rgb += mist;
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
Kawase Blur
https://gyazo.com/247d8e2e28950c8a15685e0afb79b80c
code:KawaseBlur.HLSL
Shader "Unlit/kawase-blur"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Offset ("Offset XY", Vector) = (0.002, 0.005, 0.0, 0.0)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _Offset;
fixed4 frag (v2f_img i) : SV_Target
{
float3 color = (0.0).xxx;
// Sample top left pixel
color += tex2D(_MainTex, float2(i.uv.x - _Offset.x, i.uv.y + _Offset.y)).rgb;
// Sample top right pixel
color += tex2D(_MainTex, float2(i.uv.x + _Offset.x, i.uv.y + _Offset.y)).rgb;
// Sample bottom right pixel
color += tex2D(_MainTex, float2(i.uv.x + _Offset.x, i.uv.y - _Offset.y)).rgb;
// Sample bottom left pixel
color += tex2D(_MainTex, float2(i.uv.x - _Offset.x, i.uv.y - _Offset.y)).rgb;
// Average
color *= 0.25;
float4 col = float4(color, 1);
return col;
}
ENDCG
}
}
}
CRT
https://gyazo.com/bf3dd27ef715fa02660f9ef99eb88902
https://gyazo.com/f1c573be7d16c002ca90481252ddcfc6
code:crt.HLSL
Shader "Unlit/crt"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_FilterArea("Filter Area", Vector) = (0.0, 0.0, 1.0, 1.0)
_Dimensions("Dimension XY", Vector) = (1.0, 1.0, 0.0, 0.0)
_Curvature("Curvature", float) = 1.0
_LineWidth("LineWidth", float) = 1.0
_LineContrast("LineContrast", float) = 1.0
_VerticalLine("VerticalLine", float) = 1.0
_Noise("Noise", float) = 1.0
_NoiseSize("NoiseSize", float) = 1.0
_Vignetting("Vignetting", float) = 1.0
_VignettingAlpha("VignettingAlpha", float) = 1.0
_VignettingBlur("VignettingBlur", float) = 1.0
_Seed("Seed", float) = 1.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma shader_feature VERTICAL_LINE struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _FilterArea;
float2 _Dimensions;
float _Curvature;
float _LineWidth;
float _LineContrast;
float _Noise;
float _NoiseSize;
float _Vignetting;
float _VignettingAlpha;
float _VignettingBlur;
float _Seed;
static float SQRT_2 = 1.414213;
static float light = 1.0;
float rand(float2 co) {
return frac(sin(dot(co.xy, float2(12.9898, 78.233))) * 43758.5453);
}
float mod(float x, float y) {
return x - floor(x / y)*y;
}
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float2 pixelCoord = i.uv * _FilterArea.xy;
float2 coord = pixelCoord / _Dimensions;
float2 dir = float2(coord - float2(0.5, 0.5));
float _c = _Curvature > 0. ? _Curvature : 1.;
float k = _Curvature > 0. ? (length(dir * dir) * 0.25 * _c * _c + 0.935 * _c) : 1.;
float2 uv = dir * k;
float4 col = tex2D(_MainTex, i.uv);
float3 rgb = col.rgb;
if (_Noise > 0.0 && _NoiseSize > 0.0)
{
pixelCoord.x = floor(pixelCoord.x / _NoiseSize);
pixelCoord.y = floor(pixelCoord.y / _NoiseSize);
float _noise = rand(pixelCoord * _NoiseSize * _Seed) - 0.5;
rgb += _noise * _Noise;
}
if (_LineWidth > 0.0) {
float v = (uv.x * _Dimensions.x) * min(1.0, 2.0 / _LineWidth) / _c;
float v = (uv.y * _Dimensions.y) * min(1.0, 2.0 / _LineWidth) / _c;
float j = 1. + cos(v * 1.2 - time) * 0.5 * _LineContrast;
rgb *= j;
float segment = mod((dir.x + .5) * _Dimensions.x, 4.);
float segment = mod((dir.y + .5) * _Dimensions.y, 4.);
rgb *= 0.99 + ceil(segment) * 0.015;
}
if (_Vignetting > 0.0)
{
float outter = SQRT_2 - _Vignetting * SQRT_2;
float darker = clamp((outter - length(dir) * SQRT_2) / (0.00001 + _VignettingBlur * SQRT_2), 0.0, 1.0);
rgb *= darker + (1.0 - darker) * (1.0 - _VignettingAlpha);
}
UNITY_APPLY_FOG(i.fogCoord, col);
return fixed4(rgb,1);
}
ENDCG
}
}
}