[ Video ]
[ About ]
PCD Tokyo 2020 のレオナさん・ワークショップより(アシスタント版)
From Reona396 workshop on PCD Tokyo 2020.
[ 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 27 |
#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) {}; glm::vec2 make_point(int len, int param); ofShader shader; ofFbo fbo; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(255); ofSetColor(0); this->shader.load("shader/shader.vert", "shader/shader.frag"); this->fbo.allocate(ofGetWidth(), ofGetHeight()); } //-------------------------------------------------------------- void ofApp::update() { this->fbo.begin(); ofClear(0); vector<glm::vec2> right, left; for (auto param = 0; param <= 50; param++) { auto noise_value = ofNoise(param * 0.08, ofGetFrameNum() * 0.005); if (noise_value < 0.65) { right.push_back(this->make_point(720, param) + glm::vec2(ofGetWidth() * 0.5, ofGetHeight() * 0.5)); left.push_back(this->make_point(720, 100 - param) + glm::vec2(ofGetWidth() * 0.5, ofGetHeight() * 0.5)); } else { if (right.size() > 0 && left.size() > 0) { reverse(left.begin(), left.end()); ofBeginShape(); ofVertices(right); ofVertices(left); ofEndShape(true); right.clear(); left.clear(); } } } if (right.size() > 0 && left.size() > 0) { reverse(left.begin(), left.end()); ofBeginShape(); ofVertices(right); ofVertices(left); ofEndShape(true); } this->fbo.end(); } //-------------------------------------------------------------- void ofApp::draw() { vector<glm::vec2> targets; for (int i = 0; i < 100; i++) { float R = 180 + 90 * abs(sin((i * 100 + ofGetFrameNum() + i) * DEG_TO_RAD)); float x = R * cos((360 * i / 100 + ofGetFrameNum() * 0.15) * DEG_TO_RAD); float y = R * sin((360 * i / 100 + ofGetFrameNum() * 0.15) * DEG_TO_RAD); targets.push_back(glm::vec2(x, y) + glm::vec2(ofGetWidth() * 0.5, ofGetHeight() * 0.5)); } this->shader.begin(); this->shader.setUniform1f("time", ofGetElapsedTimef()); this->shader.setUniform2f("resolution", ofGetWidth(), ofGetHeight()); this->shader.setUniform2fv("targets", &targets[0].x, targets.size()); this->shader.setUniformTexture("tex", this->fbo.getTexture(), 1); ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight()); this->shader.end(); } //-------------------------------------------------------------- glm::vec2 ofApp::make_point(int len, int param) { param = param % 100; if (param < 25) { return glm::vec2(ofMap(param, 0, 25, -len * 0.5, len * 0.5), -len * 0.5); } else if (param < 50) { return glm::vec2(len * 0.5, ofMap(param, 25, 50, -len * 0.5, len * 0.5)); } else if (param < 75) { return glm::vec2(ofMap(param, 50, 75, len * 0.5, -len * 0.5), len * 0.5); } else { return glm::vec2(-len * 0.5, ofMap(param, 75, 100, len * 0.5, -len * 0.5)); } } //-------------------------------------------------------------- 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 |
#version 150 uniform mat4 modelViewProjectionMatrix; in vec4 position; void main(){ gl_Position = modelViewProjectionMatrix * position; } |
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 |
#version 150 const int number_of_targets = 100; uniform float time; uniform vec2 resolution; uniform vec2 targets[number_of_targets]; uniform sampler2DRect tex; out vec4 outputColor; void main() { vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); vec4 tx = texture(tex, vec2(gl_FragCoord.x, resolution.y - gl_FragCoord.y)); vec3 color = vec3(1.0 - tx.a); for(int i = 0; i < number_of_targets; i++){ vec2 t = vec2(targets[i].x, -targets[i].y) / min(resolution.x, resolution.y) * 2.0; t.xy += vec2(-resolution.x, resolution.y) / min(resolution.x, resolution.y); vec3 v = vec3(smoothstep(0.05, 1.0, 0.0165 / length(p - t))); color += ((tx.a == 0) ? -v : v); } outputColor = vec4(color, 1.0); } |