Example #1
0
void ssaoApp::setup()
{
    
    gl::disableVerticalSync();
    
    RENDER_MODE = DeferredRenderer::SHOW_FINAL_VIEW;
    
    //set up camera
    mCam.setPerspective( 45.0f, getWindowAspectRatio(), 0.1f, 10000.0f );
    Vec3f camPos( -14.0f, 7.0f, -14.0f );
    mCam.lookAt(camPos * 1.5f, Vec3f::zero(), Vec3f(0.0f, 1.0f, 0.0f) );
    mCam.setCenterOfInterestPoint(Vec3f::zero());
    mMayaCam.setCurrentCam(mCam);
    
    //create functions pointers to send to deferred renderer
    boost::function<void(gl::GlslProg*)> fRenderShadowCastersFunc = boost::bind( &ssaoApp::drawShadowCasters, this, boost::lambda::_1 );
    boost::function<void(gl::GlslProg*)> fRenderNotShadowCastersFunc = boost::bind( &ssaoApp::drawNonShadowCasters, this,  boost::lambda::_1 );
    boost::function<void(void)> fRenderOverlayFunc = boost::bind( &ssaoApp::drawOverlay, this );

    mDeferredRenderer.setup( fRenderShadowCastersFunc, fRenderNotShadowCastersFunc, NULL, NULL, &mCam, Vec2i(1024, 768), 1024, true, true ); //no overlay or "particles"
    
    //have these cast point light shadows
    mDeferredRenderer.addCubeLight(    Vec3f(-2.0f, 4.0f, 6.0f),      Color(0.10f, 0.69f, 0.93f) * LIGHT_BRIGHTNESS_DEFAULT, true);      //blue
    mDeferredRenderer.addCubeLight(    Vec3f(4.0f, 6.0f, -4.0f),      Color(0.94f, 0.15f, 0.23f) * LIGHT_BRIGHTNESS_DEFAULT, true);      //red
    
    //add a bunch of lights
    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
        
            int randColIndex = Rand::randInt(5);
            Color randCol;
            switch( randColIndex ) {
                case 0:
                    randCol = Color(0.99f, 0.67f, 0.23f); //orange
                    break;
                case 1:
                    randCol = Color(0.97f, 0.24f, 0.85f); //pink
                    break;
                case 2:
                    randCol = Color(0.00f, 0.93f, 0.30f); //green
                    break;
                case 3:
                    randCol = Color(0.98f, 0.96f, 0.32f); //yellow
                    break;
                case 4:
                    randCol = Color(0.10f, 0.69f, 0.93f); //blue
                    break;
                case 5:
                    randCol = Color(0.94f, 0.15f, 0.23f); //red
                    break;
            };
            
            mDeferredRenderer.addCubeLight( Vec3f( i * 20, 30, j * 20), randCol * LIGHT_BRIGHTNESS_DEFAULT, false, true);
        }
    }
    
    mCurrLightIndex = 0;
    
    float size = 3000;
    
    plane.appendVertex(Vec3f(size, -1,-size));
    plane.appendColorRgba(ColorA(255,255,255,255));
    plane.appendNormal(Vec3f(.0f, 1.0f, 0.0f));
    plane.appendVertex(Vec3f(-size, -1,-size));
    plane.appendColorRgba(ColorA(255,255,255,255));
    plane.appendNormal(Vec3f(.0f, 1.0f, 0.0f));
    plane.appendVertex(Vec3f(-size, -1, size));
    plane.appendColorRgba(ColorA(255,255,255,255));
    plane.appendNormal(Vec3f(.0f, 1.0f, 0.0f));
    plane.appendVertex(Vec3f(size, -1, size));
    plane.appendColorRgba(ColorA(255,255,255,255));
    plane.appendNormal(Vec3f(.0f, 1.0f, 0.0f));
    
    uint indices[6] = {0,1,2,2,3,0};
    plane.appendIndices(&indices[0], 6);
    
    gl::VboMesh::Layout layout;
    shadowPlane = gl::VboMesh::create(plane);
    
    TriMesh bunnyMesh;
    ObjLoader loader( loadResource(RES_BUNNY) );
	loader.load( &bunnyMesh );
    
    bunny = gl::VboMesh(bunnyMesh);
    
}
void DeferredRenderingApp::setup()
{
    //!!test texture for diffuse texture
    mEarthTex = gl::Texture( loadImage( loadResource( RES_TEX_EARTH ) ) );
    
	gl::disableVerticalSync(); //so I can get a true representation of FPS (if higher than 60 anyhow :/)
    
	RENDER_MODE = DeferredRenderer::SHOW_FINAL_VIEW;
    
	mParams = params::InterfaceGl( "3D_Scene_Base", Vec2i( 225, 125 ) );
	mParams.addParam( "Framerate", &mCurrFramerate, "", true );
    mParams.addParam( "Selected Light Index", &mCurrLightIndex);
	mParams.addParam( "Show/Hide Params", &mShowParams, "key=x");
	mParams.addSeparator();
    
	mCurrFramerate = 0.0f;
	mShowParams = true;
	
	//set up camera
	mCam.setPerspective( 45.0f, getWindowAspectRatio(), 0.1f, 10000.0f );
    mCam.lookAt(CAM_POSITION_INIT * 1.5f, Vec3f::zero(), Vec3f(0.0f, 1.0f, 0.0f) );
    mCam.setCenterOfInterestPoint(Vec3f::zero());
    mMayaCam.setCurrentCam(mCam);
    
    //create functions pointers to send to deferred renderer
    boost::function<void(gl::GlslProg*)> fRenderShadowCastersFunc = boost::bind( &DeferredRenderingApp::drawShadowCasters, this, boost::lambda::_1 );
    boost::function<void(gl::GlslProg*)> fRenderNotShadowCastersFunc = boost::bind( &DeferredRenderingApp::drawNonShadowCasters, this,  boost::lambda::_1 );
    boost::function<void(void)> fRenderOverlayFunc = boost::bind( &DeferredRenderingApp::drawOverlay, this );
    boost::function<void(void)> fRenderParticlesFunc = boost::bind( &DeferredRenderingApp::drawDepthParticles, this );
    
    //NULL value represents the opportunity to a function pointer to an "overlay" method. Basically only basic textures can be used and it is overlayed onto the final scene.
    //see example of such a function (from another project) commented out at the bottom of this class ...
    
    mDeferredRenderer.setup( fRenderShadowCastersFunc, fRenderNotShadowCastersFunc, NULL, NULL, &mCam, Vec2i(APP_RES_HORIZONTAL, APP_RES_VERTICAL), 1024, true, true ); //no overlay or "particles"
    //mDeferredRenderer.setup( fRenderShadowCastersFunc, fRenderNotShadowCastersFunc, fRenderOverlayFunc, NULL, &mMayaCam, Vec2i(APP_RES_HORIZONTAL, APP_RES_VERTICAL), 1024, true, true ); //overlay enabled
    //mDeferredRenderer.setup( fRenderShadowCastersFunc, fRenderNotShadowCastersFunc, fRenderOverlayFunc, fRenderParticlesFunc, &mMayaCam, Vec2i(APP_RES_HORIZONTAL, APP_RES_VERTICAL), 1024, true, true ); //overlay and "particles" enabled -- not working yet
    
    //have these cast point light shadows
    mDeferredRenderer.addCubeLight(    Vec3f(-2.0f, 4.0f, 6.0f),      Color(0.10f, 0.69f, 0.93f) * LIGHT_BRIGHTNESS_DEFAULT, true);      //blue
    mDeferredRenderer.addCubeLight(    Vec3f(4.0f, 6.0f, -4.0f),      Color(0.94f, 0.15f, 0.23f) * LIGHT_BRIGHTNESS_DEFAULT, true);      //red
    
    //add a bunch of lights
    for(int i = 0; i < NUM_LIGHTS; i++) {
        
        int randColIndex = Rand::randInt(5);
        Color randCol;
        switch( randColIndex ) {
            case 0:
                randCol = Color(0.99f, 0.67f, 0.23f); //orange
                break;
            case 1:
                randCol = Color(0.97f, 0.24f, 0.85f); //pink
                break;
            case 2:
                randCol = Color(0.00f, 0.93f, 0.30f); //green
                break;
            case 3:
                randCol = Color(0.98f, 0.96f, 0.32f); //yellow
                break;
            case 4:
                randCol = Color(0.10f, 0.69f, 0.93f); //blue
                break;
            case 5:
                randCol = Color(0.94f, 0.15f, 0.23f); //red
                break;
        };
        
        mDeferredRenderer.addCubeLight( Vec3f(Rand::randFloat(-1000.0f, 1000.0f),Rand::randFloat(0.0f, 50.0f),Rand::randFloat(-1000.0f, 1000.0f)),
                                       randCol * LIGHT_BRIGHTNESS_DEFAULT,
                                       false,
                                       true);
    }
    
    mCurrLightIndex = 0;
}
void CinderDeferredRenderingApp::setup()
{
    //!!test texture for diffuse texture
    mEarthTex = gl::Texture( loadImage( loadResource( RES_EARTH_TEX ) ) );
    
	gl::disableVerticalSync(); //so I can get a true representation of FPS (if higher than 60 anyhow :/)
    
    #if defined( CINDER_MAC )
    //setAlwaysOnTop(true); //the easy but inconvenient way to have fullscreen but not have app have complete control
    AppleUtilities::autohideMenuBar(); //a better but more complicated way to do the above
    #endif
    
	RENDER_MODE = DeferredRenderer::SHOW_FINAL_VIEW;
    
	mParams = params::InterfaceGl( "3D_Scene_Base", Vec2i( 225, 125 ) );
	mParams.addParam( "Framerate", &mCurrFramerate, "", true );
    mParams.addParam( "Selected Light Index", &mCurrLightIndex);
	mParams.addParam( "Show/Hide Params", &mShowParams, "key=x");
	mParams.addSeparator();
    
	mCurrFramerate = 0.0f;
	mShowParams = true;
	
	//set up camera
    CameraPersp initialCam;
	initialCam.setPerspective( 45.0f, getWindowAspectRatio(), 0.1, 10000 );
    initialCam.lookAt(CAM_POSITION_INIT * 1.5f, Vec3f::zero(), Vec3f(0.0f, 1.0f, 0.0f) );
    initialCam.setCenterOfInterestPoint(Vec3f::zero());
	mMayaCam.setCurrentCam( initialCam );

    //create functions pointers to send to deferred renderer
    boost::function<void(gl::GlslProg*)> fRenderShadowCastersFunc;
    boost::function<void(gl::GlslProg*)> fRenderNotShadowCastersFunc;
    fRenderShadowCastersFunc = boost::bind(&CinderDeferredRenderingApp::drawShadowCasters, this, boost::lambda::_1 );
    fRenderNotShadowCastersFunc = boost::bind(&CinderDeferredRenderingApp::drawNonShadowCasters, this,  boost::lambda::_1 );
    
    //setting up deferred renderer ...
    mDeferredRenderer.setup( fRenderShadowCastersFunc, fRenderNotShadowCastersFunc, &mMayaCam );
    
    //have these cast point light shadows
    mDeferredRenderer.addCubeLight(    Vec3f(-2.0f, 4.0f, 6.0f),      Vec3f(0.10f, 0.69f, 0.93f) * LIGHT_BRIGHTNESS, true);      //blue
    mDeferredRenderer.addCubeLight(    Vec3f(4.0f, 6.0f, -4.0f),      Vec3f(0.94f, 0.15f, 0.23f) * LIGHT_BRIGHTNESS, true);      //red
    
//    mDeferredRenderer.addCubeLight(    Vec3f(-10.0f, 8.0f, 12.0f),    Vec3f(0.99f, 0.67f, 0.23f) * LIGHT_BRIGHTNESS, true);           //orange
//    mDeferredRenderer.addCubeLight(    Vec3f(6.0f, 10.0f, -10.0f),    Vec3f(0.97f, 0.24f, 0.85f) * LIGHT_BRIGHTNESS, true);           //pink
//    mDeferredRenderer.addCubeLight(    Vec3f(-8.0f, 12.0f, -8.0f),    Vec3f(0.00f, 0.93f, 0.30f) * LIGHT_BRIGHTNESS, true);           //green
//    mDeferredRenderer.addCubeLight(    Vec3f(12.0f, 8.0f, 14.0f),     Vec3f(0.98f, 0.96f, 0.32f) * LIGHT_BRIGHTNESS, true);            //yellow
    
    //add a bunch of lights
    for(int i = 0; i < NUM_LIGHTS; i++) {
        
        int randColIndex = Rand::randInt(5);
        Vec3f randCol;
        switch( randColIndex ) {
            case 0:
                randCol = Vec3f(0.99f, 0.67f, 0.23f); //orange
                break;
            case 1:
                randCol = Vec3f(0.97f, 0.24f, 0.85f); //pink
                break;
            case 2:
                randCol = Vec3f(0.00f, 0.93f, 0.30f); //green
                break;
            case 3:
                randCol = Vec3f(0.98f, 0.96f, 0.32f); //yellow
                break;
            case 4:
                randCol = Vec3f(0.10f, 0.69f, 0.93f); //blue
                break;
            case 5:
                randCol = Vec3f(0.94f, 0.15f, 0.23f); //red
                break;
        };
        
        mDeferredRenderer.addCubeLight( Vec3f(Rand::randFloat(-1000.0f, 1000.0f), Rand::randFloat(0.0f, 50.0f), Rand::randFloat(-1000.0f, 1000.0f)),
                                        randCol * LIGHT_BRIGHTNESS);
    }
    
    mCurrLightIndex = 0;
}