Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ofApp.h"
- //--------------------------------------------------------------
- void ofApp::setup(){
- ofSetWindowShape(1280,720);
- ofDisableArbTex();
- //ofEnableDepthTest();
- shader_heat.load("heatdistortion");
- shader_fbm.load("fbm");
- shader_clut.load("colormap");
- /*---------------------
- NOISE/CLUT SETUP
- ---------------------*/
- pix_clut.allocate(256,1,OF_IMAGE_COLOR);
- tex_clut.allocate(256,1,GL_RGB32F);
- noiseStep = ofVec2f(0,0);
- video.load("pace_rocket.mov");
- video.setVolume(0);
- video.play();
- plane.set(video.getWidth(),video.getHeight());
- plane.setPosition((video.getWidth()/2),(video.getHeight()/2),0);
- videoplane.set(video.getWidth(),video.getHeight());
- videoplane.setPosition(video.getWidth()/2,video.getHeight()/2,0);
- fbo_fbm.allocate(video.getWidth(),video.getHeight());
- fbo_clut.allocate(video.getWidth(),video.getHeight());
- noiseStep = ofVec2f(0,0);
- /*---------------------
- GUI SETUP
- ---------------------*/
- noise_gui.setup("FBM Noise","settings.xml",0,200);
- noise_gui.add(noiseScaleX.set("Scale X", 5.f, .0f, 10.f));
- noise_gui.add(noiseScaleY.set("Scale Y", 5.f, .0f, 10.f));
- noise_gui.add(noiseIncrement1.set("Increment 1", .01f, .0f, .1f));
- noise_gui.add(noiseIncrement2.set("Increment 2", .01f, .0f, .1f));
- noise_gui.add(map1.set("Map Min", .0f, .0f, 1.f));
- noise_gui.add(map2.set("Map Max", 1.f, .0f, 1.f));
- noise_gui.add(speed.set("Speed", 0.25, .0, 1.));
- noise_gui.add(octaves.set("# of Octaves", 5, 1, 10));
- noise_gui.add(bSmooth.set("Smooth", 1, 0, 1));
- noise_gui.add(noise_draw.set("Draw", true));
- clut_gui.setup("Color Lookup Table","settings.xml",0,410);
- clut_gui.add(lut_b1.set("B1",50,0,256));
- clut_gui.add(lut_b2.set("B2",100,0,256));
- clut_gui.add(lut_b3.set("B3",150,0,256));
- clut_gui.add(lut_b4.set("B4",200,0,256));
- clut_gui.add(lut_b5.set("B5",245,0,256));
- clut_gui.add(lut_v1.set("V1",47,0,256));
- clut_gui.add(lut_v2.set("V2",236,0,256));
- clut_gui.add(lut_v3.set("V3",177,0,256));
- clut_gui.add(lut_v4.set("V4",149,0,256));
- clut_gui.add(lut_v5.set("V5",28,0,256));
- clut_gui.add(r_scl.set("R",3.0,0.0,5.));
- clut_gui.add(g_scl.set("G",2.0,0.0,5.));
- clut_gui.add(b_scl.set("B",4.5,0.0,5.));
- clut_gui.add(b_alpha.set("Alpha",1,0,1));
- clut_gui.add(interp.set("Interp",1,0,5));
- clut_gui.add(mapdim.set("Mapdim",0.5,0.0,100.0));
- clut_gui.add(amt.set("Amount",0.775,0.0,5.0));
- heat_gui.setup("Heat Distortion","settings.xml",0,0);
- heat_gui.add(heat_strength.setup("strength",10,0,100));
- heat_gui.add(heat_speed.setup("speed",10,0,100));
- heat_gui.add(heat_range.setup("range",10,0,100));
- heat_gui.add(heat_offset.setup("offset",10,0,100));
- }
- //--------------------------------------------------------------
- void ofApp::update(){
- fbo_clut.begin();
- ofClear(0,0,0,0);
- fbo_clut.end();
- fbo_fbm.begin();
- ofClear(0,0,0,0);
- fbo_fbm.end();
- video.update();
- /* -----------------------
- Color Lookup Table
- ------------------------- */
- for(int i=0; i < 256; i++){
- if( i < lut_b1 ){
- float t_color = ofLerp(0,lut_v1,0.5);
- pix_clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
- }else if( i < lut_b2 ){
- float t_color = ofLerp(lut_v1,lut_v2,0.5);
- pix_clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
- }else if( i < lut_b3 ){
- float t_color = ofLerp(lut_v2,lut_v3,0.5);
- pix_clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
- }else if( i < lut_b4 ){
- float t_color = ofLerp(lut_v3,lut_v4,0.5);
- pix_clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
- }else if( i < lut_b5 ){
- float t_color = ofLerp(lut_v4,lut_v5,0.5);
- pix_clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
- }else{
- float t_color = ofLerp(lut_v5,256,0.5);
- pix_clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
- }
- }
- tex_clut.loadData(pix_clut);
- noiseStep.x += noiseIncrement1;
- noiseStep.y += noiseIncrement2;
- fbo_fbm.begin();
- shader_fbm.begin();
- float noise_speed = ofGetElapsedTimef()*speed;
- shader_fbm.setUniform1i("octaves", octaves);
- shader_fbm.setUniform1i("b2D3D", 0);
- shader_fbm.setUniform1f("time", noise_speed);
- shader_fbm.setUniform2f("scale", noiseScaleX, noiseScaleY);
- shader_fbm.setUniform2f("steps", noiseStep);
- shader_fbm.setUniform2f("map", map1, map2);
- shader_fbm.setUniform1i("bSmooth", bSmooth);
- plane.draw();
- shader_fbm.end();
- fbo_fbm.end();
- fbo_clut.begin();
- shader_clut.begin();
- shader_clut.setUniformTexture("tex0", fbo_fbm.getTexture(), 1);
- shader_clut.setUniformTexture("tex1", tex_clut, 2);
- shader_clut.setUniform1i("interp", interp);
- shader_clut.setUniform1f("mapdim",mapdim);
- shader_clut.setUniform1f("amt",amt);
- shader_clut.setUniform1i("b_alpha", b_alpha);
- fbo_fbm.draw(0,0);
- shader_clut.end();
- fbo_clut.end();
- }
- //--------------------------------------------------------------
- void ofApp::draw(){
- cam.begin();
- if(video.isFrameNew()){
- shader_heat.begin();
- shader_heat.setUniformTexture("displacementMap", fbo_clut.getTexture(), 1);
- video.draw(0,0);
- shader_heat.end();
- }
- if(showNoise)
- fbo_clut.draw(0,0);
- cam.end();
- if(!bHide){
- heat_gui.draw();
- noise_gui.draw();
- clut_gui.draw();
- }
- }
- //--------------------------------------------------------------
- void ofApp::keyPressed(int key){
- if(key == 'h'){
- bHide = !bHide;
- }
- if(key == 'f'){
- showNoise = !showNoise;
- }
- }
- //--------------------------------------------------------------
- void ofApp::keyReleased(int key){
- }
- //--------------------------------------------------------------
- void ofApp::mouseMoved(int x, int y ){
- }
- //--------------------------------------------------------------
- void ofApp::mouseDragged(int x, int y, int button){
- }
- //--------------------------------------------------------------
- void ofApp::mousePressed(int x, int y, int button){
- }
- //--------------------------------------------------------------
- void ofApp::mouseReleased(int x, int y, int button){
- }
- //--------------------------------------------------------------
- void ofApp::mouseEntered(int x, int y){
- }
- //--------------------------------------------------------------
- void ofApp::mouseExited(int x, int y){
- }
- //--------------------------------------------------------------
- void ofApp::windowResized(int w, int h){
- }
- //--------------------------------------------------------------
- void ofApp::gotMessage(ofMessage msg){
- }
- //--------------------------------------------------------------
- void ofApp::dragEvent(ofDragInfo dragInfo){
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement