From 49530519654629b2436a57ad2b57049286d16643 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 23 Apr 2017 19:48:25 +0000 Subject: [PATCH] Play around with shaders --- fire.glsl | 38 ++++++++++++++++++++++++++++++++++++++ src/main.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 fire.glsl diff --git a/fire.glsl b/fire.glsl new file mode 100644 index 0000000..9f73a96 --- /dev/null +++ b/fire.glsl @@ -0,0 +1,38 @@ +#ifdef GL_ES +precision mediump float; +#endif + +uniform float time; +uniform vec2 mouse; +uniform vec2 resolution; + +float smove(float value) +{ + return (value + 1.0)/2.0; +} + +float rand(vec2 co){ + return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); +} + +void main(void) +{ + vec2 pos = gl_FragCoord.xy; // rename for more meaty code + mouse.y = -mouse.y; +// vec2 uv = pos/resolution.xy; +// vec2 muv = mouse/resolution.xy; + + float scale = 100; + float modifier = sin(pos.x/scale + time)*sin(pos.y/scale - time); + modifier = smove(modifier); + + float dist = distance(gl_FragCoord.xy, mouse); + float radius = smove(sin(time))*50 + 100; + + float value = max(1 - dist/radius, 0); + value = value + modifier*0.3; + + value = value + (rand(pos.x*pos.y)-0.5)*0.03; + + gl_FragColor = vec4(value); +} diff --git a/src/main.cpp b/src/main.cpp index ade0610..ab8a65d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,47 @@ -// sample code from http://www.glusoft.com/tuto/SFML-shader-example.php - #include #include +/* + * UI Modes: + * + * 1) generation screen + * - show all chromosomes at once + * - show selection + * - reorder things + * - kill off things + * - ... and breeding + * - fill up things + * - show fitness for individuals? + * - show stats for generation? + * + * 2) fitness screen + * - show original image + * - show currently evaluated image + * - allows for pausing/singlestepping + * - show stats at the bottom + * + * 3) fast-forward screen + * - show original image + * - show best of previous generation + * - show stats at the bottom + * + * logical states: + * 1) selection + * 2) crossover + * 3) mutation + * + * program states: + * 1) evaluating + * - when going slow: fitness screen + * - when fast-forwarding: fast-forward screen + * 2) selecting + * 3) crossing over + * 4) mutating + * Step 2-4 + * - in generation screen + * - invisible? + */ + int main() { const float winW = 800; const float winH = 600; @@ -43,7 +82,7 @@ int main() { shader.setParameter("time", clk.getElapsedTime().asSeconds()); sf::Vector2i mousePos = sf::Mouse::getPosition(window); - shader.setParameter("mouse", sf::Vector2f(mousePos.x, mousePos.y - winH/2)); + shader.setParameter("mouse", sf::Vector2f(mousePos.x, mousePos.y - winH)); // Draw the sprite with the shader on it window.clear();