Dark Bit Factory & Gravity
PROGRAMMING => General coding questions => Topic started by: emook on April 29, 2015
-
Hi guys,
Don't if you've seen this before but it got me quite excited. It's a live demo coding tool written for Revision2014.
I've attached the compiled exe that you can run and code, while seeing the effects in the background.
F5 to compile changes, F11 to hide the source, ALT+F4 quit
Example in use :
https://youtu.be/j4baExLqNoI?t=424
-
Nice Find emook:)
That was really enjoyable :)
Is there lists of commands to do somethings different?
-
Yeah the live competition is in two parts, here's part 2 : https://www.youtube.com/watch?v=O2XG846oKAY
I watched the whole thing it was brilliant.
The language is hlsl / glsl used for shader coding. I didn't understand it either at first but doing some digging I've found this site :
http://glslsandbox.com/ and was
I was able to convert this : http://glslsandbox.com/e#24832.0 one :
#version 430 core
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
uniform sampler2D texChecker;
uniform sampler2D texNoise;
uniform sampler2D texTex1;
uniform sampler2D texTex2;
uniform sampler2D texTex3;
uniform sampler2D texTex4;
#define TWO_PI 6.283185
#define NUMBALLS 50.0
float d = -TWO_PI/36.0;
layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
vec4 plas( vec2 v, float time )
{
float c = 0.5 + sin( v.x * 10.0 ) + cos( sin( time + v.y ) * 20.0 );
return vec4( sin(c * 0.2 + cos(time)), c * 0.15, cos( c * 0.1 + time / .4 ) * .25, 1.0 );
}
void main( void ) {
vec2 p = (2.0*gl_FragCoord.xy - v2Resolution)/min(v2Resolution.x, v2Resolution.y);
p *= mat2(cos(fGlobalTime), -sin(fGlobalTime), sin(fGlobalTime), cos(fGlobalTime));
vec3 c = vec3(0); //ftfy
for(float i = 0.0; i < NUMBALLS; i++) {
float t = TWO_PI * i/NUMBALLS * fGlobalTime;
float x = cos(t) ;
float y = sin(2.0 * p + d);
vec2 q = 0.8*vec2(x, y);
c += 0.01/distance(p, q) * vec3(0.5 * abs(x), 0, abs(y));
}
out_color = vec4(c, 2.0);
}
save the above as shader.hlsl in the same folder as Bonzomatic and launch the sdl version.
If you have your system set to record your stereo output, you can get the (in my case) SDL version to react to music.
-
Conversion of this Worley http://glslsandbox.com/e#23237.0
and a explanation of what is going on here : http://ibreakdownshaders.blogspot.co.uk/?view=sidebar
#version 430 core
// CUBES
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
uniform sampler2D texChecker;
uniform sampler2D texNoise;
uniform sampler2D texTex1;
uniform sampler2D texTex2;
uniform sampler2D texTex3;
uniform sampler2D texTex4;
layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
#ifdef GL_ES
precision mediump float;
#endif
//uniform float time;
uniform vec2 mouse;
//uniform vec2 resolution;
float time = fGlobalTime;
float length2(vec2 p) { return dot(p, p); }
float noise(vec2 p){
return fract(sin(fract(sin(p.x) * (43.13311)) + p.y) * 31.0011);
}
float worley(vec2 p) {
float d = 1e30;
for (int xo = -1; xo <= 1; ++xo) {
for (int yo = -1; yo <= 1; ++yo) {
vec2 tp = floor(p) + vec2(xo, yo);
d = min(d, length2(p - tp - vec2(noise(tp))));
}
}
return 3.0*exp(-4.0*abs(2.0*d - 1.0));
}
float fworley(vec2 p) {
return sqrt(sqrt(sqrt(
1.1 * // light
worley(p*5. + .3 + time*.05) *
sqrt(worley(p * 50. + 0.3 + time * -0.15)) *
sqrt(sqrt(worley(p * -10. + 9.3))))));
}
void main() {
vec2 uv = gl_FragCoord.xy / v2Resolution.xy;
float t = fworley(uv * v2Resolution.xy / 1500.0);
t *= exp(-length2(abs(0.7*uv - 1.0)));
//gl_FragColor = vec4(t * vec3(0.1, 1.1*t, 1.2*t + pow(t, 0.5-t)), 1.0);
out_color = vec4(t * vec3(0.1, 1.1*t, 1.2*t + pow(t, 0.5-t)), 1.0);
}
-
OOoh, check out this one :
#version 430 core
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
uniform sampler2D texChecker;
uniform sampler2D texNoise;
uniform sampler2D texTex1;
uniform sampler2D texTex2;
uniform sampler2D texTex3;
uniform sampler2D texTex4;
layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
// CableAndhollowCylinders
#ifdef GL_ES
precision mediump float;
#endif
// T21: Can anyone fix the fringe around the cylinders ???
//
// fernlightning says: Lets try adding a ring/disk at the end of the cylinder, and ensuring the color returned is stable
// - retrofitted glowing cable from http://glsl.heroku.com/e#6129.0
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
float rand(vec3 n)
{
n = floor(n);
return fract(sin((n.x+n.y*1e2+n.z*1e4)*1e-4)*1e5);
}
// .x is distance, .y = colour
vec2 map( vec3 p )
{
const float RADIUS = 0.2;
// cylinder
vec3 f = fract( p ) - 0.5;
float d = length( f.xy );
float cr = rand( p );
// float cd = d - cr*RADIUS; // closed cylinder
float cd = abs(d - cr*RADIUS); // abs for hollow
// inner cable
if(d-0.02 < cd)
{
cd = d-0.02;
cr = 4.0; // glow!
}
// end - calc (rand) radius at more stable pos
p.z -= 0.5;
float rr = rand( p );
float rn = d - rr*RADIUS;
float rm = abs( fract( p.z ) - 0.5 ); // offset so at end of cylinder
// float rd = max( rn , rm ); // end with disk
float rd = sqrt( rn*rn + rm*rm ); // end with ring
return (cd < rd) ? vec2( cd, cr ) : vec2( rd, rr ); // min
}
void main( void )
{
vec2 pos = (gl_FragCoord.xy*2.0 - v2Resolution.xy) / v2Resolution.y;
vec3 camPos = vec3(cos(fGlobalTime*0.3), sin(fGlobalTime*0.3), 3.5);
vec3 camTarget = vec3(0.0, 0.0, .0);
vec3 camDir = normalize(camTarget-camPos);
vec3 camUp = normalize(vec3(0.0, 1.0, 0.0));
vec3 camSide = cross(camDir, camUp);
float focus = 1.8;
vec3 rayDir = normalize(camSide*pos.x + camUp*pos.y + camDir*focus);
vec3 ray = camPos;
float m = 0.32;
vec2 d;
float total_d = 0.;
const int MAX_MARCH = 100;
const float MAX_DISTANCE = 100.0;
for(int i=0; i<MAX_MARCH; ++i) {
d = map(ray-vec3(0.,0.,fGlobalTime/2.));
total_d += d.x;
ray += rayDir * d.x;
m += 1.0;
if(abs(d.x)<0.01) { break; }
if(total_d>MAX_DISTANCE) { total_d=MAX_DISTANCE; break; }
}
float c = (total_d)*0.0001;
vec4 result = vec4( 1.0-vec3((d.y>2.0)?1.0:c, c, c) - vec3(0.025, 0.025, 0.02)*m*0.8, 1.0 );
gl_FragColor = result*d.y;
}
-
Ok this one is bonkers :
http://glslsandbox.com/e#24655.6
I've edited the C++ source so I can simply copy and paste the effects.
attached, you can just press F11, then paste (almost) any from glssandbox into the editor and press F5
These are brilliant.
-
It's very useful tool, great for testing shaders.