Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.41 KB | None | 0 0
  1. // MAIN.CPP
  2.  
  3. #include "ofMain.h"
  4. #include "ofApp.h"
  5.  
  6. //========================================================================
  7. int main( ){
  8.     ofGLWindowSettings settings;
  9.     settings.setGLVersion(3,2);
  10.     ofCreateWindow(settings);
  11.    
  12.     ofRunApp(new ofApp());
  13. }
  14.  
  15.  
  16.  
  17.  
  18. // OFAPP.H
  19.  
  20. #pragma once
  21.  
  22. #include "ofMain.h"
  23. #include "ofxGui.h"
  24. #include "ofxSyphon.h"
  25.  
  26. class ofApp : public ofBaseApp{
  27.    
  28. public:
  29.     void setup();
  30.     void update();
  31.     void draw();
  32.    
  33.     void keyPressed(int key);
  34.     void keyReleased(int key);
  35.     void mouseMoved(int x, int y );
  36.     void mouseDragged(int x, int y, int button);
  37.     void mousePressed(int x, int y, int button);
  38.     void mouseReleased(int x, int y, int button);
  39.     void mouseEntered(int x, int y);
  40.     void mouseExited(int x, int y);
  41.     void windowResized(int w, int h);
  42.     void dragEvent(ofDragInfo dragInfo);
  43.     void gotMessage(ofMessage msg);
  44.    
  45.     ofTexture clutOut;
  46.     ofPixels clut;
  47.    
  48.     ofShader fbm_shader, clut_shader;
  49.    
  50.     ofVec2f noiseStep;
  51.     ofPlanePrimitive plane;
  52.    
  53.     ofxPanel noise_gui;
  54.     ofParameter<float> noiseScaleX, noiseScaleY, noiseIncrement1, noiseIncrement2, map1, map2, speed;
  55.     ofParameter<int> bSmooth, octaves;
  56.    
  57.     ofxPanel clut_gui;
  58.     ofParameter<int> lut_b1, lut_b2, lut_b3, lut_b4, lut_b5;
  59.     ofParameter<int> lut_v1, lut_v2, lut_v3, lut_v4, lut_v5;
  60.     ofParameter<int> interp;
  61.     ofParameter<float> mapdim, amt, r_scl, g_scl, b_scl;
  62.    
  63.     ofxSyphonServer syphon;
  64.     ofFbo fbo;
  65. };
  66.  
  67.  
  68. // OFAPP.CPP
  69.  
  70.  
  71. #include "ofApp.h"
  72.  
  73. //--------------------------------------------------------------
  74. void ofApp::setup(){
  75.     ofDisableArbTex();
  76.     ofSetVerticalSync(true);
  77.    
  78.     clut.allocate(256,1,OF_IMAGE_COLOR);
  79.     clutOut.allocate(256,1,GL_RGB32F);
  80.    
  81.     fbm_shader.load("fbm");
  82.     clut_shader.load("colormap");
  83.    
  84.     noiseStep = ofVec2f(0,0);
  85.    
  86.     plane.set(ofGetWidth(),ofGetHeight());
  87.     plane.setPosition((ofGetWidth()/2),(ofGetHeight()/2),0);
  88.  
  89.     /* -----------------------
  90.             GUI SETUP
  91.      ------------------------- */
  92.    
  93.     noise_gui.setup("FBM Noise","settings.xml",0,0);
  94.     noise_gui.add(noiseScaleX.set("Scale X", 1.f, .0f, 25.f));
  95.     noise_gui.add(noiseScaleY.set("Scale Y", 1.f, .0f, 25.f));
  96.     noise_gui.add(noiseIncrement1.set("Increment 1", .01f, .0f, .1f));
  97.     noise_gui.add(noiseIncrement2.set("Increment 2", .01f, .0f, .1f));
  98.     noise_gui.add(map1.set("Map Min", .0f, .0f, 1.f));
  99.     noise_gui.add(map2.set("Map Max", 1.f, .0f, 1.f));
  100.     noise_gui.add(speed.set("Speed", 0.25, .0, 2.));
  101.     noise_gui.add(octaves.set("# of Octaves", 5, 1, 10));
  102.     noise_gui.add(bSmooth.set("Smooth", 1, 0, 1));
  103.    
  104.     clut_gui.setup("Color Lookup Table","",200,100);
  105.     clut_gui.add(lut_b1.set("B1",50,0,256));
  106.     clut_gui.add(lut_b2.set("B2",100,0,256));
  107.     clut_gui.add(lut_b3.set("B3",150,0,256));
  108.     clut_gui.add(lut_b4.set("B4",200,0,256));
  109.     clut_gui.add(lut_b5.set("B5",245,0,256));
  110.     clut_gui.add(lut_v1.set("V1",110,0,256));
  111.     clut_gui.add(lut_v2.set("V2",110,0,256));
  112.     clut_gui.add(lut_v3.set("V3",110,0,256));
  113.     clut_gui.add(lut_v4.set("V4",110,0,256));
  114.     clut_gui.add(lut_v5.set("V5",110,0,256));
  115.     clut_gui.add(r_scl.set("R",1.0,0.0,5.));
  116.     clut_gui.add(g_scl.set("G",0.5,0.0,5.));
  117.     clut_gui.add(b_scl.set("B",0.5,0.0,5.));
  118.    
  119.     clut_gui.add(interp.set("Interp",1,0,5));
  120.     clut_gui.add(mapdim.set("Mapdim",256.0,0.0,256.0));
  121.     clut_gui.add(amt.set("Amount",0.5,0.0,5.0));
  122.    
  123.     syphon.setName("of");
  124.     fbo.allocate(ofGetWidth(),ofGetHeight());
  125. }
  126.  
  127. //--------------------------------------------------------------
  128. void ofApp::update(){
  129.    
  130.     fbo.begin();
  131.     ofClear(0,0,0,255);
  132.     fbo.end();
  133.    
  134.     /* -----------------------
  135.         Color Lookup Table
  136.      ------------------------- */
  137.     for(int i=0; i < 256; i++){
  138.         if( i < lut_b1 ){
  139.             float t_color = ofLerp(0,lut_v1,0.5);
  140.             clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
  141.         }else if( i < lut_b2 ){
  142.             float t_color = ofLerp(lut_v1,lut_v2,0.5);
  143.             clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
  144.         }else if( i < lut_b3 ){
  145.             float t_color = ofLerp(lut_v2,lut_v3,0.5);
  146.             clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
  147.         }else if( i < lut_b4 ){
  148.             float t_color = ofLerp(lut_v3,lut_v4,0.5);
  149.             clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
  150.         }else if( i < lut_b5  ){
  151.             float t_color = ofLerp(lut_v4,lut_v5,0.5);
  152.             clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
  153.         }else{
  154.             float t_color = ofLerp(lut_v5,256,0.5);
  155.             clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
  156.         }
  157.     }
  158.    
  159.     clutOut.loadData(clut);
  160.    
  161.     noiseStep.x += noiseIncrement1;
  162.     noiseStep.y += noiseIncrement2;
  163. }
  164.  
  165. //--------------------------------------------------------------
  166. void ofApp::draw(){
  167.     ofBackground(0,0,0);
  168.  
  169.     fbo.begin();
  170.         fbm_shader.begin();
  171.             float noise_speed = ofGetElapsedTimef()*speed;
  172.             fbm_shader.setUniform1i("octaves", octaves);
  173.             fbm_shader.setUniform1i("b2D3D", 0);
  174.             fbm_shader.setUniform1f("time", noise_speed);
  175.             fbm_shader.setUniform2f("scale", noiseScaleX, noiseScaleY);
  176.             fbm_shader.setUniform2f("steps", noiseStep);
  177.             fbm_shader.setUniform2f("map", map1, map2);
  178.             fbm_shader.setUniform1i("bSmooth", bSmooth);
  179.             plane.draw();
  180.         fbm_shader.end();
  181.     fbo.end();
  182.  
  183.     clut_shader.begin();
  184.         clut_shader.setUniformTexture("tex0", fbo.getTexture(), 1);
  185.         clut_shader.setUniformTexture("tex1", clutOut, 2);
  186.         clut_shader.setUniform1i("interp", interp);
  187.         clut_shader.setUniform1f("mapdim",mapdim);
  188.         clut_shader.setUniform1f("amt",amt);
  189. //        fbo.draw(0,0);
  190.     clut_shader.end();
  191.    
  192.     //syphon.publishScreen();
  193.    
  194.     noise_gui.draw();
  195.     clut_gui.draw();
  196. }
  197.  
  198. //--------------------------------------------------------------
  199. void ofApp::keyPressed(int key){
  200.    
  201. }
  202.  
  203. //--------------------------------------------------------------
  204. void ofApp::keyReleased(int key){
  205.    
  206. }
  207.  
  208. //--------------------------------------------------------------
  209. void ofApp::mouseMoved(int x, int y ){
  210.    
  211. }
  212.  
  213. //--------------------------------------------------------------
  214. void ofApp::mouseDragged(int x, int y, int button){
  215.    
  216. }
  217.  
  218. //--------------------------------------------------------------
  219. void ofApp::mousePressed(int x, int y, int button){
  220.    
  221. }
  222.  
  223. //--------------------------------------------------------------
  224. void ofApp::mouseReleased(int x, int y, int button){
  225.    
  226. }
  227.  
  228. //--------------------------------------------------------------
  229. void ofApp::mouseEntered(int x, int y){
  230.    
  231. }
  232.  
  233. //--------------------------------------------------------------
  234. void ofApp::mouseExited(int x, int y){
  235.    
  236. }
  237.  
  238. //--------------------------------------------------------------
  239. void ofApp::windowResized(int w, int h){
  240.    
  241. }
  242.  
  243. //--------------------------------------------------------------
  244. void ofApp::gotMessage(ofMessage msg){
  245.    
  246. }
  247.  
  248. //--------------------------------------------------------------
  249. void ofApp::dragEvent(ofDragInfo dragInfo){
  250.    
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement