// 2D plasma in C64 graphics style // // Version 1.0 (2013-03-31) // Simon Stelling-de San Antonio // #version 130 uniform float iTime; void main() { float camtime = 1.23*iTime; vec2 iResolution = vec2(1280, 720); vec4 fragCoord = gl_FragCoord; vec2 p = fragCoord.xy / iResolution.xy; p.y = 1.0 - p.y; p *= 200.0; p.x *= (iResolution.x / iResolution.y); p.x /= 2.0; p = floor(p); p.x *= 2.0; float a = p.x+30.0*sin(p.x/21.0 + 0.3*sin(0.4*camtime))+20.0*cos(p.y/19.0 + 0.2*cos(0.6*camtime))-160.0; float b = p.y+30.0*cos(p.y/18.0 + 0.4*sin(0.7*camtime))+20.0*sin(p.x/16.0 + 0.5*cos(0.7*camtime))- 97.0; float e = floor((length(vec2(a,b)) +4.0*mod(floor((p.x+p.y+p.y)/2.0),2.0))/13.0); float c; if (e == 0.0) { c = 9.0; } else if (e == 1.0) { c = 2.0; } else if (e == 2.0) { c = 8.0; } else if (e == 3.0) { c = 10.0; } else if (e == 4.0) { c = 15.0; } else if (e == 5.0) { c = 7.0; } else if (e == 6.0) { c = 1.0; } else if (e == 7.0) { c = 13.0; } else if (e == 8.0) { c = 3.0; } else if (e == 9.0) { c = 14.0; } else if (e == 10.0) { c = 4.0; } else if (e == 11.0) { c = 6.0; } else if (e == 12.0) { c = 0.0; } else if (e == 13.0) { c = 11.0; } else if (e == 14.0) { c = 5.0; } else { c = 12.0; } vec3 col; if (c == 0.0) { col = vec3(0.0); } else if (c == 1.0) { col = vec3(0.0); } else if (c == 2.0) { col = vec3(137.0, 64.0, 54.0)/256.0; } else if (c == 3.0) { col = vec3(122.0, 191.0, 199.0)/256.0; } else if (c == 4.0) { col = vec3(138.0, 70.0, 174.0)/256.0; } else if (c == 5.0) { col = vec3(104.0, 169.0, 65.0)/256.0; } else if (c == 6.0) { col = vec3( 62.0, 49.0, 162.0)/256.0; } else if (c == 7.0) { col = vec3(208.0, 220.0, 113.0)/256.0; } else if (c == 8.0) { col = vec3(144.0, 95.0, 37.0)/256.0; } else if (c == 9.0) { col = vec3( 92.0, 71.0, 0.0)/256.0; } else if (c == 10.0) { col = vec3(187.0, 119.0, 109.0)/256.0; } else if (c == 11.0) { col = vec3( 85.0, 85.0, 85.0)/256.0; } else if (c == 12.0) { col = vec3(128.0, 128.0, 128.0)/256.0; } else if (c == 13.0) { col = vec3(172.0, 234.0, 136.0)/256.0; } else if (c == 14.0) { col = vec3(124.0, 112.0, 218.0)/256.0; } else { col = vec3(171.0, 171.0, 171.0)/256.0; } gl_FragColor = vec4(col,1.0); } // #version 130 uniform float iTime; uniform float iSize; // Variables vec4 final_col = vec4(0.0); // <-- Fixed according to the suggestion by user inferno // Color palette arrays // Not sure how accurate they are but whatever, looks enough C64'ish to me vec4 PALETTE_RED[4]; vec4 PALETTE_GREEN[4]; vec4 PALETTE_BLUE[4]; void buildPalette() { // Red color palette PALETTE_RED[0] = vec4( 0.533, 0.223, 0.196, 1.0); PALETTE_RED[1] = vec4( 0.721, 0.411, 0.384, 1.0); PALETTE_RED[2] = vec4( 0.749, 0.807, 0.447, 1.0); PALETTE_RED[3] = vec4( 1.000, 1.000, 1.000, 1.0); // Green color palette PALETTE_GREEN[0] = vec4( 0.333, 0.627, 0.286, 1.0); PALETTE_GREEN[1] = vec4( 0.580, 0.878, 0.537, 1.0); PALETTE_GREEN[2] = vec4( 0.749, 0.807, 0.447, 1.0); PALETTE_GREEN[3] = vec4( 1.000, 1.000, 1.000, 1.0); // Blue color palette PALETTE_BLUE[0] = vec4( 0.250, 0.192, 0.552, 1.0); PALETTE_BLUE[1] = vec4( 0.470, 0.411, 0.768, 1.0); PALETTE_BLUE[2] = vec4( 0.403, 0.713, 0.741, 1.0); PALETTE_BLUE[3] = vec4( 0.000, 0.000, 0.000, 1.0); } vec4 rasterline(in vec2 xy, in int axis, in vec4 line_color, in float raster_size, in float line_pos, in float line_offset) { float line_pos_final = line_pos + (line_offset); float line_pos_max = line_pos_final + raster_size; float line_pos_min = line_pos_final - raster_size; if (axis == 0 && xy.x < line_pos_max && xy.x > line_pos_min) { return line_color; } if (axis == 1 && xy.y < line_pos_max && xy.y > line_pos_min) { return line_color; } return vec4(0.0); } void rasterbar(in vec2 xy, in int axis, in vec4 palette_0[4], in vec4 palette_1[4], in float bar_pos, in float size_0) { // Lol, I'm new to GLSL so I just dealt with my lack of knowledge and hardcoded this... // This kinda loses it's point if I do it this way though. :( Maybe I'll figure this out later... final_col += rasterline(xy, axis, palette_0[0], 0.015 * size_0, bar_pos, 0.2300 * size_0); final_col += rasterline(xy, axis, palette_0[1], 0.005 * size_0, bar_pos, 0.2100 * size_0); final_col += rasterline(xy, axis, palette_0[0], 0.005 * size_0, bar_pos, 0.2000 * size_0); final_col += rasterline(xy, axis, palette_0[1], 0.015 * size_0, bar_pos, 0.1800 * size_0); final_col += rasterline(xy, axis, palette_0[0], 0.005 * size_0, bar_pos, 0.1600 * size_0); final_col += rasterline(xy, axis, palette_0[1], 0.015 * size_0, bar_pos, 0.1400 * size_0); final_col += rasterline(xy, axis, palette_0[2], 0.005 * size_0, bar_pos, 0.1200 * size_0); final_col += rasterline(xy, axis, palette_0[1], 0.005 * size_0, bar_pos, 0.1100 * size_0); final_col += rasterline(xy, axis, palette_0[2], 0.015 * size_0, bar_pos, 0.0900 * size_0); final_col += rasterline(xy, axis, palette_0[3], 0.005 * size_0, bar_pos, 0.0700 * size_0); final_col += rasterline(xy, axis, palette_0[2], 0.005 * size_0, bar_pos, 0.0600 * size_0); final_col += rasterline(xy, axis, palette_0[3], 0.005 * size_0, bar_pos, 0.0500 * size_0); final_col += rasterline(xy, axis, palette_0[2], 0.005 * size_0, bar_pos, 0.0400 * size_0); final_col += rasterline(xy, axis, palette_0[3], 0.020 * size_0, bar_pos, 0.0200 * size_0); final_col += rasterline(xy, axis, palette_1[0], 0.015 * size_0, bar_pos, -0.2300 * size_0); final_col += rasterline(xy, axis, palette_1[1], 0.005 * size_0, bar_pos, -0.2100 * size_0); final_col += rasterline(xy, axis, palette_1[0], 0.005 * size_0, bar_pos, -0.2000 * size_0); final_col += rasterline(xy, axis, palette_1[1], 0.015 * size_0, bar_pos, -0.1800 * size_0); final_col += rasterline(xy, axis, palette_1[0], 0.005 * size_0, bar_pos, -0.1600 * size_0); final_col += rasterline(xy, axis, palette_1[1], 0.015 * size_0, bar_pos, -0.1400 * size_0); final_col += rasterline(xy, axis, palette_1[2], 0.005 * size_0, bar_pos, -0.1200 * size_0); final_col += rasterline(xy, axis, palette_1[1], 0.005 * size_0, bar_pos, -0.1100 * size_0); final_col += rasterline(xy, axis, palette_1[2], 0.015 * size_0, bar_pos, -0.0900 * size_0); final_col += rasterline(xy, axis, palette_1[3], 0.005 * size_0, bar_pos, -0.0700 * size_0); final_col += rasterline(xy, axis, palette_1[2], 0.005 * size_0, bar_pos, -0.0600 * size_0); final_col += rasterline(xy, axis, palette_1[3], 0.005 * size_0, bar_pos, -0.0500 * size_0); final_col += rasterline(xy, axis, palette_1[2], 0.005 * size_0, bar_pos, -0.0400 * size_0); final_col += rasterline(xy, axis, palette_1[3], 0.020 * size_0, bar_pos, -0.0200 * size_0); } void main() { vec2 iResolution = vec2(1280, 720); vec4 fragCoord = gl_FragCoord; buildPalette(); float aspectRatio = iResolution.x / iResolution.y; vec2 xy_norm; xy_norm.x = (fragCoord.x / iResolution.x) * aspectRatio; xy_norm.y = fragCoord.y / iResolution.y; vec2 xy_final = -1.0 + 2.0 * xy_norm; float mid = -0.15; float bar_1_pos = 0.1 * cos(xy_final.x + iTime * 5.0); float bar_2_pos = 0.1 * sin(xy_final.y + iTime * 2.5) - 0.625; float bar_3_pos = 0.1 * cos((xy_final.y * 2.5) + iTime * 5.0) + 2.25; float bar_4_pos = 0.1 * cos(iTime * 5.0) + 1.75; float bar_5_pos = 0.25 * cos((xy_final.x * 2.0) + iTime * 2.5) + 1.125; rasterbar(xy_final, 1, PALETTE_RED, PALETTE_BLUE, bar_1_pos, iSize); gl_FragColor = final_col; } // #version 140 void main() { gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex; gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; gl_FrontColor = gl_Color; }/* * MIT License * Copyright © Etienne 'Eethe' Orlhac * 07/08/2015 * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the “Software”), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software * is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * The Software is provided “as is”, without warranty of any kind, * express or implied, including but not limited to the warranties of merchantability, * fitness for a particular purpose and noninfringement. In no event shall the authors * or copyright holders be liable for any claim, damages or other liability, whether in an * action of contract, tort or otherwise, arising from, out of or in connection with * the software or the use or other dealings in the Software. */ #define AMPLITUDE 0.0085 #define SPEED 0.01 uniform float iTime; uniform sampler2D iChannel0; uniform sampler2D iChannel1; vec4 rgbShift( in vec2 p , in vec4 shift) { shift *= 2.0*shift.w - 1.0; vec2 rs = vec2(shift.x,-shift.y); vec2 gs = vec2(shift.y,-shift.z); vec2 bs = vec2(shift.z,-shift.x); float r = texture2D(iChannel0, p+rs, 0.0).x; float g = texture2D(iChannel0, p+gs, 0.0).y; float b = texture2D(iChannel0, p+bs, 0.0).z; return vec4(r,g,b,1.0); } vec4 noise( in vec2 p ) { return texture2D(iChannel1, p, 0.0); } vec4 vec4pow( in vec4 v, in float p ) { // Don't touch alpha (w), we use it to choose the direction of the shift // and we don't want it to go in one direction more often than the other return vec4(pow(v.x,p),pow(v.y,p),pow(v.z,p),v.w); } void main() { vec2 iResolution = vec2(1280.0, 720.0); vec4 fragCoord = gl_FragCoord; vec2 p = fragCoord.xy / iResolution.xy; vec4 c = vec4(0.0,0.0,0.0,1.0); // Elevating shift values to some high power (between 8 and 16 looks good) // helps make the stuttering look more sudden vec4 shift = vec4pow(noise(vec2(SPEED*iTime,2.0*SPEED*iTime/25.0 )),8.0) *vec4(AMPLITUDE,AMPLITUDE,AMPLITUDE,1.0);; c += rgbShift(p, shift); gl_FragColor = c; }// change these values to 0.0 to turn off individual effects float vertJerkOpt = 1.0; float vertMovementOpt = 2.0; float bottomStaticOpt = 5.0; float scalinesOpt = 1.0; float rgbOffsetOpt = 1.0; float horzFuzzOpt = 1.0; uniform float iTime; uniform sampler2D iChannel0; // uniform float bottomStaticOpt; // Noise generation functions borrowed from: // https://github.com/ashima/webgl-noise/blob/master/src/noise2D.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, // (3.0-sqrt(3.0))/6.0 0.366025403784439, // 0.5*(sqrt(3.0)-1.0) -0.577350269189626, // -1.0 + 2.0 * C.x 0.024390243902439); // 1.0 / 41.0 // First corner vec2 i = floor(v + dot(v, C.yy) ); vec2 x0 = v - i + dot(i, C.xx); // Other corners vec2 i1; //i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0 //i1.y = 1.0 - i1.x; i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0); // x0 = x0 - 0.0 + 0.0 * C.xx ; // x1 = x0 - i1 + 1.0 * C.xx ; // x2 = x0 - 1.0 + 2.0 * C.xx ; vec4 x12 = x0.xyxy + C.xxzz; x12.xy -= i1; // Permutations i = mod289(i); // Avoid truncation effects in permutation 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,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0); m = m*m ; m = m*m ; // Gradients: 41 points uniformly over a line, mapped onto a diamond. // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287) 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; // Normalise gradients implicitly by scaling m // Approximation of: m *= inversesqrt( a0*a0 + h*h ); m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h ); // Compute final noise value at P 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 staticV(vec2 uv) { float staticHeight = snoise(vec2(9.0,iTime*1.2+3.0))*0.3+5.0; float staticAmount = snoise(vec2(1.0,iTime*1.2-6.0))*0.1+0.3; float staticStrength = snoise(vec2(-9.75,iTime*0.6-3.0))*2.0+2.0; return (1.0-step(snoise(vec2(5.0*pow(iTime,2.0)+pow(uv.x*7.0,1.2),pow((mod(iTime,100.0)+100.0)*uv.y*0.3+3.0,staticHeight))),staticAmount))*staticStrength; } void main() { vec2 iResolution = vec2(1280, 720); vec2 uv = gl_FragCoord.xy/iResolution.xy; float jerkOffset = (1.0-step(snoise(vec2(iTime*1.3,5.0)),0.8))*0.05; float fuzzOffset = snoise(vec2(iTime*15.0,uv.y*80.0))*0.003; float largeFuzzOffset = snoise(vec2(iTime*1.0,uv.y*25.0))*0.004; float vertMovementOn = (1.0-step(snoise(vec2(iTime*0.2,8.0)),0.4))*vertMovementOpt; float vertJerk = (1.0-step(snoise(vec2(iTime*1.5,5.0)),0.6))*vertJerkOpt; float vertJerk2 = (1.0-step(snoise(vec2(iTime*5.5,5.0)),0.2))*vertJerkOpt; float yOffset = abs(sin(iTime)*4.0)*vertMovementOn+vertJerk*vertJerk2*0.3; float y = mod(uv.y+yOffset,1.0); float xOffset = (fuzzOffset + largeFuzzOffset) * horzFuzzOpt; float staticVal = 0.0; for (float y = -1.0; y <= 1.0; y += 1.0) { float maxDist = 5.0/200.0; float dist = y/200.0; staticVal += staticV(vec2(uv.x,uv.y+dist))*(maxDist-abs(dist))*1.5; } staticVal *= bottomStaticOpt; float red = texture2D( iChannel0, vec2(uv.x + xOffset -0.01*rgbOffsetOpt,y)).r+staticVal; float green = texture2D( iChannel0, vec2(uv.x + xOffset, y)).g+staticVal; float blue = texture2D( iChannel0, vec2(uv.x + xOffset +0.01*rgbOffsetOpt,y)).b+staticVal; vec3 color = vec3(red,green,blue); float scanline = sin(uv.y*800.0)*0.04*scalinesOpt; color -= scanline; gl_FragColor = vec4(color,1.0); }