Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
1.1.0:postfx [2024/01/07 11:56] – admin | 1.1.0:postfx [2024/01/07 12:26] (current) – [Raindrop Post Effect] admin | ||
---|---|---|---|
Line 149: | Line 149: | ||
Written by jilski for the strangeness project (http:// | Written by jilski for the strangeness project (http:// | ||
June 2018 | June 2018 | ||
+ | |||
+ | {{: | ||
<file GLSL> | <file GLSL> | ||
Line 206: | Line 208: | ||
float iTime = mod(_TimeInfo.y, | float iTime = mod(_TimeInfo.y, | ||
mainImage(l_Color, | mainImage(l_Color, | ||
+ | return l_Color.rgb; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | === TV Post Effect === | ||
+ | |||
+ | A slighly modified version of the shader code at [[https:// | ||
+ | Source: Array and textureless GLSL 2D simplex noise function. | ||
+ | Author : Ian McEwan, Ashima Arts. | ||
+ | |||
+ | <file glsl> | ||
+ | vec3 mod289(vec3 x) { | ||
+ | return x - floor(x * (1.0 / 289.0)) * 289.0; | ||
+ | } | ||
+ | |||
+ | vec2 mod289(vec2 x) { | ||
+ | return x - floor(x * (1.0 / 289.0)) * 289.0; | ||
+ | } | ||
+ | |||
+ | vec3 permute(vec3 x) { | ||
+ | return mod289(((x*34.0)+1.0)*x); | ||
+ | } | ||
+ | |||
+ | float snoise(vec2 v){ | ||
+ | const vec4 C = vec4(0.211324865405187, | ||
+ | vec2 i = floor(v + dot(v, C.yy) ); | ||
+ | vec2 x0 = v - i + dot(i, C.xx); | ||
+ | |||
+ | vec2 i1; | ||
+ | i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0); | ||
+ | vec4 x12 = x0.xyxy + C.xxzz; | ||
+ | x12.xy -= i1; | ||
+ | |||
+ | i = mod289(i); | ||
+ | vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 )) + i.x + vec3(0.0, i1.x, 1.0 )); | ||
+ | |||
+ | vec3 m = max(0.5 - vec3(dot(x0, | ||
+ | m = m*m ; | ||
+ | m = m*m ; | ||
+ | |||
+ | vec3 x = 2.0 * fract(p * C.www) - 1.0; | ||
+ | vec3 h = abs(x) - 0.5; | ||
+ | vec3 ox = floor(x + 0.5); | ||
+ | vec3 a0 = x - ox; | ||
+ | |||
+ | m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h ); | ||
+ | |||
+ | vec3 g; | ||
+ | g.x = a0.x * x0.x + h.x * x0.y; | ||
+ | g.yz = a0.yz * x12.xz + h.yz * x12.yw; | ||
+ | return 130.0 * dot(m, g); | ||
+ | } | ||
+ | |||
+ | float rand(vec2 co){ | ||
+ | | ||
+ | } | ||
+ | |||
+ | vec3 SurfaceShader(inout TLocals DATA){ | ||
+ | vec2 uv = DATA.TexCoord0.xy; | ||
+ | float iTime = mod(_TimeInfo.y, | ||
+ | float time = iTime * 2.0; | ||
+ | | ||
+ | float noise = max(0.0, snoise(vec2(time, | ||
+ | | ||
+ | noise = noise + (snoise(vec2(time*10.0, | ||
+ | | ||
+ | vec4 fragColor; | ||
+ | float xpos = uv.x - noise * noise * 0.25; | ||
+ | fragColor = tex2D(_RenderedTexture, | ||
+ | | ||
+ | fragColor.rgb = mix(fragColor.rgb, | ||
+ | | ||
+ | if (floor(mod(gl_FragCoord.y * 0.25, 2.0)) == 0.0){ | ||
+ | fragColor.rgb *= 1.0 - (0.15 * noise); | ||
+ | } | ||
+ | | ||
+ | fragColor.g = mix(fragColor.r, | ||
+ | fragColor.b = mix(fragColor.r, | ||
+ | |||
+ | return fragColor.rgb; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | === Raindrop Post Effect === | ||
+ | |||
+ | A modified version of the Heartfelt shader from [[https:// | ||
+ | |||
+ | Heartfelt - by Martijn Steinrucken aka BigWings - 2017 | ||
+ | Email: | ||
+ | License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. | ||
+ | |||
+ | {{: | ||
+ | |||
+ | <file glsl> | ||
+ | #define S(a, b, t) smoothstep(a, | ||
+ | //#define HAS_HEART | ||
+ | //#define HAS_ZOOM | ||
+ | #define USE_POST_PROCESSING | ||
+ | |||
+ | vec3 N13(float p) { | ||
+ | vec3 p3 = fract(vec3(p) * vec3(.1031, | ||
+ | p3 += dot(p3, p3.yzx + 19.19); | ||
+ | | ||
+ | } | ||
+ | |||
+ | vec4 N14(float t) { | ||
+ | return fract(sin(t*vec4(123., | ||
+ | } | ||
+ | |||
+ | float N(float t) { | ||
+ | return fract(sin(t*12345.564)*7658.76); | ||
+ | } | ||
+ | |||
+ | float Saw(float b, float t) { | ||
+ | return S(0., b, t)*S(1., b, t); | ||
+ | } | ||
+ | |||
+ | |||
+ | vec2 DropLayer2(vec2 uv, float t) { | ||
+ | vec2 UV = uv; | ||
+ | |||
+ | uv.y += t*0.75; | ||
+ | vec2 a = vec2(6., 1.); | ||
+ | vec2 grid = a*2.; | ||
+ | vec2 id = floor(uv*grid); | ||
+ | |||
+ | float colShift = N(id.x); | ||
+ | uv.y += colShift; | ||
+ | |||
+ | id = floor(uv*grid); | ||
+ | vec3 n = N13(id.x*35.2+id.y*2376.1); | ||
+ | vec2 st = fract(uv*grid)-vec2(.5, | ||
+ | |||
+ | float x = n.x-.5; | ||
+ | |||
+ | float y = UV.y*20.; | ||
+ | float wiggle = sin(y+sin(y)); | ||
+ | x += wiggle*(.5-abs(x))*(n.z-.5); | ||
+ | x *= .7; | ||
+ | float ti = fract(t+n.z); | ||
+ | y = (Saw(.85, ti)-.5)*.9+.5; | ||
+ | vec2 p = vec2(x, y); | ||
+ | |||
+ | float d = length((st-p)*a.yx); | ||
+ | |||
+ | float mainDrop = S(.4, .0, d); | ||
+ | |||
+ | float r = sqrt(S(1., y, st.y)); | ||
+ | float cd = abs(st.x-x); | ||
+ | float trail = S(.23*r, .15*r*r, cd); | ||
+ | float trailFront = S(-.02, .02, st.y-y); | ||
+ | trail *= trailFront*r*r; | ||
+ | |||
+ | y = UV.y; | ||
+ | float trail2 = S(.2*r, .0, cd); | ||
+ | float droplets = max(0., (sin(y*(1.-y)*120.)-st.y))*trail2*trailFront*n.z; | ||
+ | y = fract(y*10.)+(st.y-.5); | ||
+ | float dd = length(st-vec2(x, | ||
+ | droplets = S(.3, 0., dd); | ||
+ | float m = mainDrop+droplets*r*trailFront; | ||
+ | |||
+ | return vec2(m, trail); | ||
+ | } | ||
+ | |||
+ | float StaticDrops(vec2 uv, float t) { | ||
+ | uv *= 40.; | ||
+ | |||
+ | vec2 id = floor(uv); | ||
+ | uv = fract(uv)-.5; | ||
+ | vec3 n = N13(id.x*107.45+id.y*3543.654); | ||
+ | vec2 p = (n.xy-.5)*.7; | ||
+ | float d = length(uv-p); | ||
+ | |||
+ | float fade = Saw(.025, fract(t+n.z)); | ||
+ | float c = S(.3, 0., d)*fract(n.z*10.)*fade; | ||
+ | return c; | ||
+ | } | ||
+ | |||
+ | vec2 Drops(vec2 uv, float t, float l0, float l1, float l2) { | ||
+ | float s = StaticDrops(uv, | ||
+ | vec2 m1 = DropLayer2(uv, | ||
+ | vec2 m2 = DropLayer2(uv*1.85, | ||
+ | |||
+ | float c = s+m1.x+m2.x; | ||
+ | c = S(.3, 1., c); | ||
+ | |||
+ | return vec2(c, max(m1.y*l0, | ||
+ | } | ||
+ | |||
+ | void mainImage( out vec4 fragColor, in vec2 fragCoord, ivec3 iResolution, | ||
+ | { | ||
+ | // Mouse x = scrub time y = rain amount (only without heart) | ||
+ | vec4 iMouse = vec4(scrubTime, | ||
+ | |||
+ | vec2 uv = (fragCoord.xy - .5 * iResolution.xy) / iResolution.y; | ||
+ | vec2 UV = fragCoord.xy / iResolution.xy; | ||
+ | vec3 M = iMouse.xyz / iResolution.xyz; | ||
+ | float T = iTime + M.x * 2.; | ||
+ | |||
+ | #ifdef HAS_HEART | ||
+ | T = mod(iTime, 102.); | ||
+ | T = mix(T, M.x * 102., M.z > 0.?1.:0.); | ||
+ | #endif | ||
+ | |||
+ | float t = T*.2; | ||
+ | |||
+ | float rainAmount = iMouse.z > 0. ? M.y : sin(T*.05)*.3+.7; | ||
+ | |||
+ | float maxBlur = mix(3., 6., rainAmount); | ||
+ | float minBlur = 2.; | ||
+ | |||
+ | float story = 0.; | ||
+ | float heart = 0.; | ||
+ | |||
+ | float zoom = 0.; | ||
+ | |||
+ | #ifdef HAS_HEART | ||
+ | story = S(0., 70., T); | ||
+ | |||
+ | t = min(1., T/70.); | ||
+ | t = 1.-t; | ||
+ | t = (1.-t*t)*70.; | ||
+ | |||
+ | #ifdef HAS_ZOOM | ||
+ | zoom= mix(.3, 1.2, story); | ||
+ | uv *=zoom; | ||
+ | #endif | ||
+ | minBlur = 4.+S(.5, 1., story)*3.; | ||
+ | maxBlur = 6.+S(.5, 1., story)*1.5; | ||
+ | |||
+ | vec2 hv = uv-vec2(.0, -.1); | ||
+ | hv.x *= .5; | ||
+ | float s = S(110., 70., T); | ||
+ | hv.y-=sqrt(abs(hv.x))*.5*s; | ||
+ | heart = length(hv); | ||
+ | heart = S(.4*s, .2*s, heart)*s; | ||
+ | rainAmount = heart; | ||
+ | |||
+ | maxBlur-=heart; | ||
+ | uv *= 1.5; | ||
+ | t *= .25; | ||
+ | #else | ||
+ | #ifdef HAS_ZOOM | ||
+ | zoom = -cos(T*.2); | ||
+ | uv *= .7+zoom*.3; | ||
+ | #endif | ||
+ | #endif | ||
+ | UV = (UV-.5)*(.9+zoom*.1)+.5; | ||
+ | |||
+ | float staticDrops = S(-.5, 1., rainAmount)*2.; | ||
+ | float layer1 = S(.25, .75, rainAmount); | ||
+ | float layer2 = S(.0, .5, rainAmount); | ||
+ | |||
+ | vec2 c = Drops(uv, t, staticDrops, | ||
+ | |||
+ | #ifdef CHEAP_NORMALS | ||
+ | vec2 n = vec2(dFdx(c.x), | ||
+ | #else | ||
+ | vec2 e = vec2(.001, 0.); | ||
+ | float cx = Drops(uv+e, t, staticDrops, | ||
+ | float cy = Drops(uv+e.yx, | ||
+ | vec2 n = vec2(cx-c.x, | ||
+ | #endif | ||
+ | |||
+ | #ifdef HAS_HEART | ||
+ | n *= 1.-S(60., 85., T); | ||
+ | c.y *= 1.-S(80., 100., T)*.8; | ||
+ | #endif | ||
+ | |||
+ | float focus = mix(maxBlur-c.y, | ||
+ | vec3 col = textureLod(_RenderedTexture, | ||
+ | |||
+ | #ifdef USE_POST_PROCESSING | ||
+ | t = (T+3.)*.5; | ||
+ | float colFade = sin(t*.2)*.5+.5+story; | ||
+ | col *= mix(vec3(1.), | ||
+ | float fade = S(0., 10., T); | ||
+ | float lightning = sin(t*sin(t*10.)); | ||
+ | lightning *= pow(max(0., sin(t+sin(t))), | ||
+ | col *= 1.+lightning*fade*mix(1., | ||
+ | col *= 1.-dot(UV-=.5, | ||
+ | |||
+ | #ifdef HAS_HEART | ||
+ | col = mix(pow(col, | ||
+ | fade *= S(102., 97., T); | ||
+ | #endif | ||
+ | |||
+ | col *= fade; | ||
+ | #endif | ||
+ | |||
+ | fragColor = vec4(col, 1.); | ||
+ | } | ||
+ | |||
+ | vec3 SurfaceShader(inout TLocals DATA){ | ||
+ | vec4 l_Color = vec4(0.0); | ||
+ | ivec3 l_Resolution = ivec3(textureSize(_RenderedTexture, | ||
+ | float iTime = mod(_TimeInfo.y, | ||
+ | mainImage(l_Color, | ||
return l_Color.rgb; | return l_Color.rgb; | ||
} | } |