Advertisement
Guest User

ofApp.cpp

a guest
Nov 3rd, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.31 KB | None | 0 0
  1. #include "ofApp.h"
  2.  
  3. //--------------------------------------------------------------
  4. void ofApp::setup(){
  5.     ofSetWindowShape(1280,720);
  6.     ofDisableArbTex();
  7.     //ofEnableDepthTest();
  8.    
  9.     shader_heat.load("heatdistortion");
  10.     shader_fbm.load("fbm");
  11.     shader_clut.load("colormap");
  12.    
  13.  
  14.    
  15.     /*---------------------
  16.      NOISE/CLUT SETUP
  17.      ---------------------*/
  18.     pix_clut.allocate(256,1,OF_IMAGE_COLOR);
  19.     tex_clut.allocate(256,1,GL_RGB32F);
  20.  
  21.     noiseStep = ofVec2f(0,0);
  22.    
  23.     video.load("pace_rocket.mov");
  24.     video.setVolume(0);
  25.     video.play();
  26.    
  27.     plane.set(video.getWidth(),video.getHeight());
  28.     plane.setPosition((video.getWidth()/2),(video.getHeight()/2),0);
  29.     videoplane.set(video.getWidth(),video.getHeight());
  30.     videoplane.setPosition(video.getWidth()/2,video.getHeight()/2,0);
  31.     fbo_fbm.allocate(video.getWidth(),video.getHeight());
  32.     fbo_clut.allocate(video.getWidth(),video.getHeight());
  33.    
  34.     noiseStep = ofVec2f(0,0);
  35.  
  36.     /*---------------------
  37.            GUI SETUP
  38.      ---------------------*/
  39.     noise_gui.setup("FBM Noise","settings.xml",0,200);
  40.     noise_gui.add(noiseScaleX.set("Scale X", 5.f, .0f, 10.f));
  41.     noise_gui.add(noiseScaleY.set("Scale Y", 5.f, .0f, 10.f));
  42.     noise_gui.add(noiseIncrement1.set("Increment 1", .01f, .0f, .1f));
  43.     noise_gui.add(noiseIncrement2.set("Increment 2", .01f, .0f, .1f));
  44.     noise_gui.add(map1.set("Map Min", .0f, .0f, 1.f));
  45.     noise_gui.add(map2.set("Map Max", 1.f, .0f, 1.f));
  46.     noise_gui.add(speed.set("Speed", 0.25, .0, 1.));
  47.     noise_gui.add(octaves.set("# of Octaves", 5, 1, 10));
  48.     noise_gui.add(bSmooth.set("Smooth", 1, 0, 1));
  49.     noise_gui.add(noise_draw.set("Draw", true));
  50.    
  51.     clut_gui.setup("Color Lookup Table","settings.xml",0,410);
  52.     clut_gui.add(lut_b1.set("B1",50,0,256));
  53.     clut_gui.add(lut_b2.set("B2",100,0,256));
  54.     clut_gui.add(lut_b3.set("B3",150,0,256));
  55.     clut_gui.add(lut_b4.set("B4",200,0,256));
  56.     clut_gui.add(lut_b5.set("B5",245,0,256));
  57.    
  58.     clut_gui.add(lut_v1.set("V1",47,0,256));
  59.     clut_gui.add(lut_v2.set("V2",236,0,256));
  60.     clut_gui.add(lut_v3.set("V3",177,0,256));
  61.     clut_gui.add(lut_v4.set("V4",149,0,256));
  62.     clut_gui.add(lut_v5.set("V5",28,0,256));
  63.    
  64.     clut_gui.add(r_scl.set("R",3.0,0.0,5.));
  65.     clut_gui.add(g_scl.set("G",2.0,0.0,5.));
  66.     clut_gui.add(b_scl.set("B",4.5,0.0,5.));
  67.     clut_gui.add(b_alpha.set("Alpha",1,0,1));
  68.     clut_gui.add(interp.set("Interp",1,0,5));
  69.     clut_gui.add(mapdim.set("Mapdim",0.5,0.0,100.0));
  70.     clut_gui.add(amt.set("Amount",0.775,0.0,5.0));
  71.    
  72.     heat_gui.setup("Heat Distortion","settings.xml",0,0);
  73.     heat_gui.add(heat_strength.setup("strength",10,0,100));
  74.     heat_gui.add(heat_speed.setup("speed",10,0,100));
  75.     heat_gui.add(heat_range.setup("range",10,0,100));
  76.     heat_gui.add(heat_offset.setup("offset",10,0,100));
  77. }
  78.  
  79. //--------------------------------------------------------------
  80. void ofApp::update(){
  81.     fbo_clut.begin();
  82.     ofClear(0,0,0,0);
  83.     fbo_clut.end();
  84.    
  85.     fbo_fbm.begin();
  86.     ofClear(0,0,0,0);
  87.     fbo_fbm.end();
  88.    
  89.     video.update();
  90.    
  91.     /* -----------------------
  92.      Color Lookup Table
  93.      ------------------------- */
  94.     for(int i=0; i < 256; i++){
  95.         if( i < lut_b1 ){
  96.             float t_color = ofLerp(0,lut_v1,0.5);
  97.             pix_clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
  98.         }else if( i < lut_b2 ){
  99.             float t_color = ofLerp(lut_v1,lut_v2,0.5);
  100.             pix_clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
  101.         }else if( i < lut_b3 ){
  102.             float t_color = ofLerp(lut_v2,lut_v3,0.5);
  103.             pix_clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
  104.         }else if( i < lut_b4 ){
  105.             float t_color = ofLerp(lut_v3,lut_v4,0.5);
  106.             pix_clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
  107.         }else if( i < lut_b5  ){
  108.             float t_color = ofLerp(lut_v4,lut_v5,0.5);
  109.             pix_clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
  110.         }else{
  111.             float t_color = ofLerp(lut_v5,256,0.5);
  112.             pix_clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
  113.         }
  114.     }
  115.    
  116.     tex_clut.loadData(pix_clut);
  117.    
  118.     noiseStep.x += noiseIncrement1;
  119.     noiseStep.y += noiseIncrement2;
  120.    
  121.     fbo_fbm.begin();
  122.         shader_fbm.begin();
  123.         float noise_speed = ofGetElapsedTimef()*speed;
  124.         shader_fbm.setUniform1i("octaves", octaves);
  125.         shader_fbm.setUniform1i("b2D3D", 0);
  126.         shader_fbm.setUniform1f("time", noise_speed);
  127.         shader_fbm.setUniform2f("scale", noiseScaleX, noiseScaleY);
  128.         shader_fbm.setUniform2f("steps", noiseStep);
  129.         shader_fbm.setUniform2f("map", map1, map2);
  130.         shader_fbm.setUniform1i("bSmooth", bSmooth);
  131.         plane.draw();
  132.         shader_fbm.end();
  133.     fbo_fbm.end();
  134.    
  135.     fbo_clut.begin();
  136.         shader_clut.begin();
  137.         shader_clut.setUniformTexture("tex0", fbo_fbm.getTexture(), 1);
  138.         shader_clut.setUniformTexture("tex1", tex_clut, 2);
  139.         shader_clut.setUniform1i("interp", interp);
  140.         shader_clut.setUniform1f("mapdim",mapdim);
  141.         shader_clut.setUniform1f("amt",amt);
  142.         shader_clut.setUniform1i("b_alpha", b_alpha);
  143.         fbo_fbm.draw(0,0);
  144.         shader_clut.end();
  145.     fbo_clut.end();
  146.    
  147. }
  148.  
  149. //--------------------------------------------------------------
  150. void ofApp::draw(){
  151.     cam.begin();
  152.    
  153.     if(video.isFrameNew()){
  154.     shader_heat.begin();
  155.         shader_heat.setUniformTexture("displacementMap", fbo_clut.getTexture(), 1);
  156.    
  157.         video.draw(0,0);
  158.    
  159.     shader_heat.end();
  160.     }
  161.     if(showNoise)
  162.         fbo_clut.draw(0,0);
  163.    
  164.     cam.end();
  165.    
  166.     if(!bHide){
  167.         heat_gui.draw();
  168.         noise_gui.draw();
  169.         clut_gui.draw();
  170.     }
  171. }
  172.  
  173. //--------------------------------------------------------------
  174. void ofApp::keyPressed(int key){
  175.     if(key == 'h'){
  176.         bHide = !bHide;
  177.     }
  178.     if(key == 'f'){
  179.         showNoise = !showNoise;
  180.     }
  181. }
  182.  
  183. //--------------------------------------------------------------
  184. void ofApp::keyReleased(int key){
  185.    
  186. }
  187.  
  188. //--------------------------------------------------------------
  189. void ofApp::mouseMoved(int x, int y ){
  190.    
  191. }
  192.  
  193. //--------------------------------------------------------------
  194. void ofApp::mouseDragged(int x, int y, int button){
  195.    
  196. }
  197.  
  198. //--------------------------------------------------------------
  199. void ofApp::mousePressed(int x, int y, int button){
  200.    
  201. }
  202.  
  203. //--------------------------------------------------------------
  204. void ofApp::mouseReleased(int x, int y, int button){
  205.    
  206. }
  207.  
  208. //--------------------------------------------------------------
  209. void ofApp::mouseEntered(int x, int y){
  210.    
  211. }
  212.  
  213. //--------------------------------------------------------------
  214. void ofApp::mouseExited(int x, int y){
  215.    
  216. }
  217.  
  218. //--------------------------------------------------------------
  219. void ofApp::windowResized(int w, int h){
  220.    
  221. }
  222.  
  223. //--------------------------------------------------------------
  224. void ofApp::gotMessage(ofMessage msg){
  225.    
  226. }
  227.  
  228. //--------------------------------------------------------------
  229. void ofApp::dragEvent(ofDragInfo dragInfo){
  230.    
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement