Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MAIN.CPP
- #include "ofMain.h"
- #include "ofApp.h"
- //========================================================================
- int main( ){
- ofGLWindowSettings settings;
- settings.setGLVersion(3,2);
- ofCreateWindow(settings);
- ofRunApp(new ofApp());
- }
- // OFAPP.H
- #pragma once
- #include "ofMain.h"
- #include "ofxGui.h"
- #include "ofxSyphon.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);
- ofTexture clutOut;
- ofPixels clut;
- ofShader fbm_shader, clut_shader;
- ofVec2f noiseStep;
- ofPlanePrimitive plane;
- ofxPanel noise_gui;
- ofParameter<float> noiseScaleX, noiseScaleY, noiseIncrement1, noiseIncrement2, map1, map2, speed;
- ofParameter<int> bSmooth, octaves;
- ofxPanel clut_gui;
- ofParameter<int> lut_b1, lut_b2, lut_b3, lut_b4, lut_b5;
- ofParameter<int> lut_v1, lut_v2, lut_v3, lut_v4, lut_v5;
- ofParameter<int> interp;
- ofParameter<float> mapdim, amt, r_scl, g_scl, b_scl;
- ofxSyphonServer syphon;
- ofFbo fbo;
- };
- // OFAPP.CPP
- #include "ofApp.h"
- //--------------------------------------------------------------
- void ofApp::setup(){
- ofDisableArbTex();
- ofSetVerticalSync(true);
- clut.allocate(256,1,OF_IMAGE_COLOR);
- clutOut.allocate(256,1,GL_RGB32F);
- fbm_shader.load("fbm");
- clut_shader.load("colormap");
- noiseStep = ofVec2f(0,0);
- plane.set(ofGetWidth(),ofGetHeight());
- plane.setPosition((ofGetWidth()/2),(ofGetHeight()/2),0);
- /* -----------------------
- GUI SETUP
- ------------------------- */
- noise_gui.setup("FBM Noise","settings.xml",0,0);
- noise_gui.add(noiseScaleX.set("Scale X", 1.f, .0f, 25.f));
- noise_gui.add(noiseScaleY.set("Scale Y", 1.f, .0f, 25.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, 2.));
- noise_gui.add(octaves.set("# of Octaves", 5, 1, 10));
- noise_gui.add(bSmooth.set("Smooth", 1, 0, 1));
- clut_gui.setup("Color Lookup Table","",200,100);
- 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",110,0,256));
- clut_gui.add(lut_v2.set("V2",110,0,256));
- clut_gui.add(lut_v3.set("V3",110,0,256));
- clut_gui.add(lut_v4.set("V4",110,0,256));
- clut_gui.add(lut_v5.set("V5",110,0,256));
- clut_gui.add(r_scl.set("R",1.0,0.0,5.));
- clut_gui.add(g_scl.set("G",0.5,0.0,5.));
- clut_gui.add(b_scl.set("B",0.5,0.0,5.));
- clut_gui.add(interp.set("Interp",1,0,5));
- clut_gui.add(mapdim.set("Mapdim",256.0,0.0,256.0));
- clut_gui.add(amt.set("Amount",0.5,0.0,5.0));
- syphon.setName("of");
- fbo.allocate(ofGetWidth(),ofGetHeight());
- }
- //--------------------------------------------------------------
- void ofApp::update(){
- fbo.begin();
- ofClear(0,0,0,255);
- fbo.end();
- /* -----------------------
- Color Lookup Table
- ------------------------- */
- for(int i=0; i < 256; i++){
- if( i < lut_b1 ){
- float t_color = ofLerp(0,lut_v1,0.5);
- 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);
- 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);
- 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);
- 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);
- 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);
- clut.setColor(i,0,ofColor(t_color*r_scl,t_color*g_scl,t_color*b_scl));
- }
- }
- clutOut.loadData(clut);
- noiseStep.x += noiseIncrement1;
- noiseStep.y += noiseIncrement2;
- }
- //--------------------------------------------------------------
- void ofApp::draw(){
- ofBackground(0,0,0);
- fbo.begin();
- fbm_shader.begin();
- float noise_speed = ofGetElapsedTimef()*speed;
- fbm_shader.setUniform1i("octaves", octaves);
- fbm_shader.setUniform1i("b2D3D", 0);
- fbm_shader.setUniform1f("time", noise_speed);
- fbm_shader.setUniform2f("scale", noiseScaleX, noiseScaleY);
- fbm_shader.setUniform2f("steps", noiseStep);
- fbm_shader.setUniform2f("map", map1, map2);
- fbm_shader.setUniform1i("bSmooth", bSmooth);
- plane.draw();
- fbm_shader.end();
- fbo.end();
- clut_shader.begin();
- clut_shader.setUniformTexture("tex0", fbo.getTexture(), 1);
- clut_shader.setUniformTexture("tex1", clutOut, 2);
- clut_shader.setUniform1i("interp", interp);
- clut_shader.setUniform1f("mapdim",mapdim);
- clut_shader.setUniform1f("amt",amt);
- // fbo.draw(0,0);
- clut_shader.end();
- //syphon.publishScreen();
- noise_gui.draw();
- clut_gui.draw();
- }
- //--------------------------------------------------------------
- void ofApp::keyPressed(int key){
- }
- //--------------------------------------------------------------
- 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