Play around with shaders
This commit is contained in:
parent
5d9d0ef716
commit
4953051965
2 changed files with 80 additions and 3 deletions
38
fire.glsl
Normal file
38
fire.glsl
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
45
src/main.cpp
45
src/main.cpp
|
|
@ -1,8 +1,47 @@
|
||||||
// sample code from http://www.glusoft.com/tuto/SFML-shader-example.php
|
|
||||||
|
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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() {
|
int main() {
|
||||||
const float winW = 800;
|
const float winW = 800;
|
||||||
const float winH = 600;
|
const float winH = 600;
|
||||||
|
|
@ -43,7 +82,7 @@ int main() {
|
||||||
shader.setParameter("time", clk.getElapsedTime().asSeconds());
|
shader.setParameter("time", clk.getElapsedTime().asSeconds());
|
||||||
|
|
||||||
sf::Vector2i mousePos = sf::Mouse::getPosition(window);
|
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
|
// Draw the sprite with the shader on it
|
||||||
window.clear();
|
window.clear();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue