void ImageBasedLighting_05App::draw()
{
    gl::clear( Color( 0, 0, 0 ) );
    
    gl::setMatrices( mCam );
    
    // enable depth testing
    gl::ScopedDepth scopedDepth( true );
    
    // bind the cubemap textures
    gl::ScopedTextureBind scopedTexBind0( mTextureRadianceMap, 0 );
    gl::ScopedTextureBind scopedTexBind1( mTextureIrradianceMap, 1 );
    gl::ScopedTextureBind scopedTexBind2( mNormalMap, 2 );
    gl::ScopedTextureBind scopedTexBind3( mRoughnessMap, 3 );
    gl::ScopedTextureBind scopedTexBind4( mMetallicMap, 4 );
    gl::ScopedTextureBind scopedTexBind5( mColorMap, 5 );
    gl::ScopedTextureBind scopedTexBind6( mAOMap, 6 );
    gl::ScopedTextureBind scopedTexBind7( mSpecularMap, 7 );
    
    auto shader = mBatchModel->getGlslProg();
    shader->uniform( "uRadianceMap", 0 );
    shader->uniform( "uIrradianceMap", 1 );
    shader->uniform( "uNormalMap", 2 );
    shader->uniform( "uRoughnessMap", 3 );
    shader->uniform( "uMetallicMap", 4 );
    shader->uniform( "uColorMap", 5 );
    shader->uniform( "uAOMap", 6 );
    shader->uniform( "uSpecularMap", 7);
    
    // sends the base color, the specular opacity,
    // the light position, color and radius to the shader
//    shader->uniform( "uBaseColor", mBaseColor );
//    shader->uniform( "uSpecular", mSpecular );
//    shader->uniform( "uNormalMapScale",mNormalMapScale);
    
    // sends the tone-mapping uniforms
    shader->uniform( "uExposure", mExposure );
    shader->uniform( "uGamma", mGamma );
    
    // render a grid of sphere with different roughness/metallic values and colors
    {
        
//        shader->uniform( "uRoughness", mRoughness );
//        shader->uniform( "uRoughness4", pow( mRoughness, 4.0f ) );
//        shader->uniform( "uMetallic", mMetallic );
        
        mBatchModel->draw();
        
    }
    
    // render skybox
    shader = mBatchSkyBox->getGlslProg();
    shader->uniform( "uExposure", mExposure );
    shader->uniform( "uGamma", mGamma );
    mBatchSkyBox->draw();
    
    //  DRAW SETTINGS
    _params->draw();
}
예제 #2
0
void RandomSpawn::drawParticles()
{
    mBatch_P->getGlslProg()->uniform("ViewDirection", mCamera.getViewDirection());
    mBatch_P->getGlslProg()->uniform("LightPosition", vec3(0, 10, 0));
    mBatch_P->getGlslProg()->uniform("SpecPow", 4.0f);
    mBatch_P->getGlslProg()->uniform("SpecStr", 2.0f);

    mBatch_P->drawInstanced(mPointsParticles.size());
}
예제 #3
0
void Day72App::setup()
{
    mGlsl = gl::GlslProg::create(loadAsset("vertex.vert"), loadAsset("fragment.frag"));
    mCamPos = vec3(0,0,4);
    mCam.lookAt(mCamPos, vec3(0));
    mCam.setPerspective(60.f, getWindowAspectRatio(), 1.f, 1000.f);
    mCamUi = CameraUi(&mCam, getWindow());
    
    mSkyBoxTex = gl::TextureCubeMap::create(loadImage(loadAsset("boxy.jpg")));
    auto cube = geom::Cube();
    mSkyBoxBatch = gl::Batch::create(cube >> geom::Scale(SKY_BOX_SIZE,SKY_BOX_SIZE,SKY_BOX_SIZE), mGlsl);
    
    auto sphere = geom::Sphere().subdivisions(64);
    auto c = geom::Cube();
    auto torus = geom::Torus().subdivisionsAxis(64).subdivisionsHeight(32);
    auto icos = geom::Icosahedron();
    
    mSphere = gl::Batch::create(sphere, mGlsl);
    mTorus = gl::Batch::create(torus >> geom::Scale(1.3,1.3,1.3), mGlsl);
    mIcos = gl::Batch::create(icos >> geom::Scale(0.8,0.8,0.8), mGlsl);
    mCube = gl::Batch::create(c, mGlsl);
    
    //SET THE LOCATION OF THE TEXTURE
    mSkyBoxBatch->getGlslProg()->uniform("uCubeMapTex", 0);
    
    mSkyBoxTex->bind();
    
    gl::enableDepth();
    
}
예제 #4
0
void CubeMappingApp::setup()
{
	mCubeMap = gl::TextureCubeMap::createHorizontalCross( loadImage( loadAsset( "env_map.jpg" ) ), gl::TextureCubeMap::Format().mipmap() );

#if defined( CINDER_GL_ES )
	auto envMapGlsl = gl::GlslProg::create( loadAsset( "env_map_es2.vert" ), loadAsset( "env_map_es2.frag" ) );
	auto skyBoxGlsl = gl::GlslProg::create( loadAsset( "sky_box_es2.vert" ), loadAsset( "sky_box_es2.frag" ) );
#else
	auto envMapGlsl = gl::GlslProg::create( loadAsset( "env_map.vert" ), loadAsset( "env_map.frag" ) );
	auto skyBoxGlsl = gl::GlslProg::create( loadAsset( "sky_box.vert" ), loadAsset( "sky_box.frag" ) );
#endif

	mTeapotBatch = gl::Batch::create( geom::Teapot().subdivisions( 7 ), envMapGlsl );
	mTeapotBatch->getGlslProg()->uniform( "uCubeMapTex", 0 );

	mSkyBoxBatch = gl::Batch::create( geom::Cube(), skyBoxGlsl );
	mSkyBoxBatch->getGlslProg()->uniform( "uCubeMapTex", 0 );
	
	gl::enableDepthRead();
	gl::enableDepthWrite();	
}
예제 #5
0
void BayBridgeApp::setup()
{
	mGUI = params::InterfaceGl::create("Params", ivec2(300, 50));
	mParamInvert = false;
	mParamClear = true;
	mGUI->addParam<bool>("paramInvert", &mParamInvert).optionsStr("label='Inverted'");
	mGUI->addParam<bool>("paramClear", &mParamClear).optionsStr("label='Clear Frame'");

	getWindow()->setSize(1280, 720);
	getWindow()->setPos(ivec2(20));
	setFrameRate(60);
	mBridgeShader = gl::GlslProg::create(loadAsset("shaders/light_vert.glsl"), loadAsset("shaders/light_frag.glsl"));
	
	mBridge.Init(mBridgeShader);

	mCamera.setPerspective(45.0f, getWindowAspectRatio(), 10.0f, 10000.0f);
	mCamera.lookAt(vec3(0, 50, -525), vec3(0,50,0), vec3(0, 1, 0));
	mCamUi = CameraUi(&mCamera, getWindow());

	mDS = CinderDSAPI::create();
	mDS->init();
	mDS->initDepth(FrameSize::DEPTHSD, 60);
	mDS->start();

	ImageSourceRef skybox[6]
	{
		loadImage(loadAsset("textures/px04.png")), loadImage(loadAsset("textures/nx04.png")),
		loadImage(loadAsset("textures/py04.png")), loadImage(loadAsset("textures/ny04.png")),
		loadImage(loadAsset("textures/pz04.png")), loadImage(loadAsset("textures/nz04.png"))
	};

	mTexSkybox = gl::TextureCubeMap::create(skybox);
	mShaderSkybox = gl::GlslProg::create(loadAsset("shaders/skybox_vert.glsl"), loadAsset("shaders/skybox_frag.glsl"));
	mBatchSkybox = gl::Batch::create(geom::Cube(), mShaderSkybox);
	mBatchSkybox->getGlslProg()->uniform("uCubemapSampler", 0);

	mShaderDiffuse = gl::GlslProg::create(loadAsset("shaders/diffuse_vert.glsl"), loadAsset("shaders/diffuse_frag.glsl"));

	//Bloom
	mFboRaw = gl::Fbo::create(1280, 720, gl::Fbo::Format().colorTexture(gl::Texture2d::Format().dataType(GL_FLOAT).internalFormat(GL_RGBA32F)));
	mFboHiPass = gl::Fbo::create(1280, 720);
	mFboBlurU = gl::Fbo::create(1280, 720);
	mFboBlurV = gl::Fbo::create(1280, 720);

	mShaderHiPass = gl::GlslProg::create(loadAsset("shaders/passthru_vert.glsl"), loadAsset("shaders/highpass_frag.glsl"));
	mShaderHiPass->uniform("uTextureSampler", 0);

	mShaderBlur = gl::GlslProg::create(loadAsset("shaders/blur_vert.glsl"), loadAsset("shaders/blur_frag.glsl"));
	mShaderBlur->uniform("uTextureSampler", 0);
}
void ViewportArrayApp::update()
{
	// bind the fbo and enable depth testing
	gl::ScopedFramebuffer scopedFbo( mFbo );
	gl::ScopedDepth scopedDepthTest( true );
	
	// clear our fbo
	gl::clear( Color( 0, 0, 0 ) );
	
	// create an array with the different cameras matrices
	vector<mat4> matrices;
	for( auto cam : mCameras ) {
		matrices.push_back( cam.getProjectionMatrix() * cam.getViewMatrix() );
	}
	// and send it to the shader
	mTeapot->getGlslProg()->uniform( "uMatrices", &matrices[0], mCameras.size() );
	
	// render the teapot once (the geometry shader takes care of the rest)
	mTeapot->draw();
}