[ Video ]
[ About ]
規則的な動きを持った出力結果を不規則にしたら面白い?という試行。openFrameworksでofFboに書き出した結果とノイズの値の配列をGLSLへ渡してテキスチャをズラす
Slice of result image.
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#pragma once #include "ofMain.h" class ofApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed(int key) {} void keyReleased(int key) {} void mouseMoved(int x, int y) {} void mouseDragged(int x, int y, int button) {} void mousePressed(int x, int y, int button) {} void mouseReleased(int x, int y, int button) {} void mouseEntered(int x, int y) {} void mouseExited(int x, int y) {} void windowResized(int w, int h) {} void dragEvent(ofDragInfo dragInfo) {} void gotMessage(ofMessage msg) {} ofFbo fbo; ofShader shader; vector<float> y_noise; }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetLineWidth(3); this->fbo.allocate(ofGetWidth(), ofGetHeight()); this->shader.load("shader/shader.vert", "shader/shader.frag"); for (int i = 0; i < ofGetHeight(); i++) { this->y_noise.push_back(0.f); } } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); this->fbo.begin(); ofClear(0); vector<glm::vec2> locations; for (int i = 0; i < 30; i++) { auto location = glm::vec2( ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.003), 0, 1, 0, ofGetWidth()), ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.003), 0, 1, 0, ofGetHeight())); locations.push_back(location); } auto radius = 20.f; for (int i = 0; i < locations.size(); i++) { auto min_distance = 100.f; for (int k = 0; k < locations.size(); k++) { if (i == k) { continue; } auto angle_i = std::atan2(locations[k].y - locations[i].y, locations[k].x - locations[i].x); auto satellite_point_i = locations[i] + glm::vec2(radius * cos(angle_i), radius * sin(angle_i)); auto angle_k = std::atan2(locations[i].y - locations[k].y, locations[i].x - locations[k].x); auto satellite_point_k = locations[k] + glm::vec2(radius * cos(angle_k), radius * sin(angle_k)); auto distance = glm::distance(satellite_point_i, satellite_point_k); if (distance < 100) { ofSetColor(39, ofMap(distance, 0, 100, 255, 0)); ofDrawLine(satellite_point_i, satellite_point_k); ofDrawCircle(satellite_point_i, radius * 0.3); if (distance < min_distance) { min_distance = distance; } } } ofSetColor(39); ofNoFill(); ofDrawCircle(locations[i], radius); ofFill(); ofDrawCircle(locations[i], ofMap(min_distance, 0, 100, radius * 0.7, 0)); } this->fbo.end(); float noise_value; for (int y = 0; y < this->y_noise.size(); y++) { if (y % 72 == 0) { noise_value = ofMap(ofNoise(y * 0.05, ofGetFrameNum() * 0.03), 0, 1, -1, 1); if (noise_value > 0.65) { noise_value -= 0.65; } else if (noise_value < -0.65) { noise_value += 0.65; } else { noise_value = 0.0; } } this->y_noise[y] = noise_value; } } //-------------------------------------------------------------- void ofApp::draw() { this->shader.begin(); this->shader.setUniform1f("time", ofGetElapsedTimef()); this->shader.setUniform2f("resolution", ofGetWidth(), ofGetHeight()); this->shader.setUniformTexture("tex", this->fbo.getTexture(), 1); this->shader.setUniform1fv("y_noise", &this->y_noise[0], ofGetHeight()); ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight()); this->shader.end(); } //-------------------------------------------------------------- int main() { ofGLWindowSettings settings; settings.setGLVersion(3, 2); settings.setSize(720, 720); ofCreateWindow(settings); ofRunApp(new ofApp()); } |
1 2 3 4 5 6 7 8 9 10 11 12 |
#version 150 uniform mat4 modelViewProjectionMatrix; in vec4 position; in vec2 texcoord; out vec2 texCoordVarying; void main(){ texCoordVarying = texcoord; gl_Position = modelViewProjectionMatrix * position; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#version 150 uniform float time; uniform vec2 resolution; uniform sampler2DRect tex; uniform float y_noise[720]; out vec4 outputColor; void main() { float drift = 360.0; vec4 t = texture(tex, vec2(gl_FragCoord.x + drift * y_noise[int(gl_FragCoord.y)], (resolution.y - gl_FragCoord.y))); outputColor = t; } |