[ Video ]
[ About ]
光の輪っか
Light rings.
[ 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::vec4> targets; 	float size_start, size_max; 	vector<float> sizes; 	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 | #include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { 	ofSetFrameRate(60); 	ofSetWindowTitle("openframeworks"); 	this->size_start = 0.001; 	this->size_max = 0.5; 	this->number_of_targets = 15; 	for (int i = 0; i < this->number_of_targets; i++) { 		glm::vec4 target = glm::vec4(ofRandom(ofGetWidth()), ofRandom(ofGetHeight()), 0.f, 0.f); 		this->targets.push_back(target); 		this->sizes.push_back(ofRandom(this->size_start, this->size_max)); 	} 	this->shader.load("shader/shader.vert", "shader/shader.frag"); } //-------------------------------------------------------------- void ofApp::update() { 	for (int i = 0; i < this->sizes.size(); i++) { 		if (this->sizes[i] >= this->size_max) { 			this->targets[i] = glm::vec4(ofRandom(ofGetWidth()), ofRandom(ofGetHeight()), 0.f, 0.f); 			this->sizes[i] = this->size_start; 		} 		else { 			this->sizes[i] += 0.01; 		} 	} } //-------------------------------------------------------------- void ofApp::draw() { 	this->shader.begin(); 	this->shader.setUniform1f("time", ofGetElapsedTimef()); 	this->shader.setUniform2f("resolution", ofGetWidth(), ofGetHeight()); 	this->shader.setUniform4fv("targets", &this->targets[0].x, this->number_of_targets); 	this->shader.setUniform1fv("sizes", &this->sizes[0], this->number_of_targets); 	this->shader.setUniform1f("size_max", this->size_max); 	ofRect(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 | #version 150 const int number_of_targets = 15; out vec4 outputColor; uniform float time; uniform vec2 resolution; uniform vec4 targets[number_of_targets]; uniform float sizes[number_of_targets]; uniform float size_max; 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 < 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);     float v = 0.02 * (size_max - sizes[i]) / abs(length(p - t) - sizes[i]);     vec3 c = vec3(v);     color += c;   }   outputColor = vec4(color, 1.0); } |