Last active
January 23, 2020 15:19
-
-
Save jimmyjonezz/d8328441743d659342f5c77bb9cda662 to your computer and use it in GitHub Desktop.
noise + anaglyph
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_type canvas_item; | |
uniform bool apply = true; | |
uniform float amount = 1.0; | |
uniform sampler2D offset_texture : hint_white; | |
vec4 hash42(vec2 p){ | |
vec4 p4 = fract(vec4(p.xyxy) * vec4(443.8975,397.2973, 491.1871, 470.7827)); | |
p4 += dot(p4.wzxy, p4 + 19.19); | |
return fract(vec4(p4.x * p4.y, p4.x * p4.z, p4.y * p4.w, p4.x * p4.w)); | |
} | |
float hash( float n ){ | |
return fract(sin(n) * 43758.5453123); | |
} | |
// 3d noise function (iq's) | |
float n( in vec3 x ){ | |
vec3 p = floor(x); | |
vec3 f = fract(x); | |
f = f * f * (3.0-2.0 * f); | |
float n = p.x + p.y*57.0 + 113.0*p.z; | |
float res = mix(mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x), | |
mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y), | |
mix(mix( hash(n+113.0), hash(n+114.0),f.x), | |
mix( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z); | |
return res; | |
} | |
float nn(vec2 p, float t) { | |
float y = p.y; | |
float s = t*2.0; | |
float v = (n(vec3(y *.01 + s, 1., 1.0)) + .0) | |
*(n(vec3(y *.011 + 1000.0 + s, 1., 1.0)) + .0) | |
*(n(vec3(y *.51 + 421.0 + s, 1., 1.0)) + .0); | |
v *= hash42(vec2(p.x + t * 0.01, p.y)).x + .3 ; | |
v = pow(v+.3, 1.); | |
if (v<.7) v = 0.; //threshold | |
return v; | |
} | |
void fragment() { | |
vec2 uv = FRAGCOORD.xy / SCREEN_PIXEL_SIZE.xy; | |
float linesN = 240.; //fields per seconds | |
float one_y = SCREEN_PIXEL_SIZE.y / linesN; //field line | |
uv = floor(uv * SCREEN_PIXEL_SIZE.xy / one_y) * one_y; | |
float col = nn(uv, TIME); | |
vec4 texture_color = texture(TEXTURE, SCREEN_UV); | |
vec4 color = texture_color; | |
if (apply == true) { | |
float adjusted_amount = amount * texture(offset_texture, SCREEN_UV).r / 100.0; | |
color.r = texture(SCREEN_TEXTURE, vec2(SCREEN_UV.x + adjusted_amount, SCREEN_UV.y)).r; | |
color.g = texture(SCREEN_TEXTURE, SCREEN_UV).g; | |
color.b = texture(SCREEN_TEXTURE, vec2(SCREEN_UV.x - adjusted_amount, SCREEN_UV.y)).b; | |
} | |
COLOR = color + vec4(vec3(col), 0.5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment