[ Video ]
[ About ]
赤く光らせたかったけど、ただボヤけた感じになってしまった
Mirage.
[ 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 28 29 |
#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) {}; int number_of_targets; vector<glm::vec2> targets1; vector<glm::vec2> targets2; ofShader shader; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); this->number_of_targets = 60; for (int i = 0; i < this->number_of_targets; i++) { this->targets1.push_back(glm::vec2()); this->targets2.push_back(glm::vec2()); } this->shader.load("shader/shader.vert", "shader/shader.frag"); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); float radius = 250; for (int i = 0; i < this->number_of_targets; i++) { int deg = i * 3 + 90; ofPoint point = ofPoint(radius * cos(deg * DEG_TO_RAD), radius * sin(deg * DEG_TO_RAD)); float noise_value = ofNoise(deg * 0.03, ofGetFrameNum() * 0.008); float x_param = 0; if (noise_value > 0.75) { x_param = ofMap(noise_value, 0.75, 1.0, 0, 150); } else if (noise_value < 0.25) { x_param = ofMap(noise_value, 0.25, 0.0, 0, -150); } this->targets1[i] = glm::vec2(point.x + x_param + ofGetWidth() * 0.5, point.y + ofGetHeight() * 0.5); this->targets2[i] = glm::vec2(-point.x + x_param + ofGetWidth() * 0.5, point.y + ofGetHeight() * 0.5); } } //-------------------------------------------------------------- void ofApp::draw() { this->shader.begin(); this->shader.setUniform1f("time", ofGetElapsedTimef()); this->shader.setUniform2f("resolution", ofGetWidth(), ofGetHeight()); this->shader.setUniform2fv("targets1", &this->targets1[0].x, this->number_of_targets); this->shader.setUniform2fv("targets2", &this->targets2[0].x, this->number_of_targets); 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 |
#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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#version 150 const int number_of_targets = 60; uniform float time; uniform vec2 resolution; uniform vec2 targets1[number_of_targets]; uniform vec2 targets2[number_of_targets]; out vec4 outputColor; /// Reference /// https://trap.jp/post/142/ float crs(vec2 v1, vec2 v2) { return v1.x*v2.y - v1.y*v2.x; } // 2点v1, v2を端点に持つ線分との距離を返す float line(vec2 p, vec2 v1, vec2 v2) { p -= v1; vec2 v = v2-v1; float t = dot(p, normalize(v)); if (t<0.0) { return length(p); } else if (t>length(v)) { return length(p-v); } else { return abs(crs(p, normalize(v))); } } void main() { vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); vec3 color = vec3(0.0); for(int i = 0; i < 60; i++){ vec2 t1 = vec2(targets1[i].x, -targets1[i].y) / min(resolution.x, resolution.y) * 2.0; vec2 t2 = vec2(targets2[i].x, -targets2[i].y) / min(resolution.x, resolution.y) * 2.0; t1.xy += vec2(-resolution.x, resolution.y) / min(resolution.x, resolution.y); t2.xy += vec2(-resolution.x, resolution.y) / min(resolution.x, resolution.y); float v = 0.005 / line(p, t1, t2); vec3 c = vec3(smoothstep(0.0, 1.0, v), 0.0, 0.0); color += c; } outputColor = vec4(color, 1.0); } |