[ Video ]
[ About ]
Day 3 Carrot.
[ 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) {}; ofImage image; ofFbo fbo; ofTrueTypeFont font; vector<float> y_noise; 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 69 70 71 72 73 74 75 76 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(239); ofSetColor(39); this->image.loadImage("image/carrot.png"); this->fbo.allocate(ofGetWidth(), ofGetHeight()); this->fbo.begin(); ofClear(0); ofTranslate(ofGetWidth() * 0.5 - this->image.getWidth() * 0.5, ofGetHeight() * 0.5 - this->image.getHeight() * 0.5); this->image.draw(0, 0); this->fbo.end(); for (int i = 0; i < ofGetHeight(); i++) { this->y_noise.push_back(0.f); } this->shader.load("shader/shader.vert", "shader/shader.frag"); } //-------------------------------------------------------------- void ofApp::update() { float noise_value; for (int y = 0; y < this->y_noise.size(); y++) { if (y % 20 == 0) { noise_value = ofMap(ofNoise(y * 0.005, ofGetFrameNum() * 0.01), 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 |
#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 |
#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; } |
[ Link ]
https://github.com/junkiyoshi/Insta20181103