Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
bindFramebufferFace
void BasicIBL::prefilterCubeMap()
{
auto texFormat = gl::TextureCubeMap::Format();
texFormat.setInternalFormat( GL_RGB );
texFormat.enableMipmapping();
texFormat.setMinFilter( GL_LINEAR_MIPMAP_LINEAR );
texFormat.setMagFilter( GL_LINEAR );
texFormat.setWrap( GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE );
auto fboFormat = gl::FboCubeMap::Format().textureCubeMapFormat( texFormat );
auto fbo = gl::FboCubeMap::create( 512, 512, fboFormat );
auto shader = gl::GlslProg::create( loadAsset( "shaders/prefilter.vert" ), loadAsset( "shaders/prefilter.frag" ) );
shader->uniform( "uCubeMapTex", 0 );
shader->uniform( "uMaxLod", static_cast<float>( NUM_MIP_LEVELS ) );
auto cube = gl::Batch::create( geom::Cube().size( vec3( 2.0 ) ), shader );
gl::ScopedFramebuffer fboScp( fbo );
gl::ScopedTextureBind texScp( mCubeMapTex );
gl::ScopedMatrices mScp;
ivec2 size = fbo->getSize();
for( int level = 0; level < NUM_MIP_LEVELS; level++ ) {
gl::ScopedViewport vpScp( ivec2( 0, 0 ), size );
for( uint8_t dir = 0; dir < 6; ++dir ) {
gl::setProjectionMatrix( ci::CameraPersp( size.x, size.y, 90.0f, 0.01f, 1000.0f ).getProjectionMatrix() );
gl::setViewMatrix( fbo->calcViewMatrix( GL_TEXTURE_CUBE_MAP_POSITIVE_X + dir, vec3( 0 ) ) );
GLuint id = fbo->getTextureCubeMap()->getId();
glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + dir, id, level );
/*
The following does not work
fbo->bindFramebufferFace( GL_TEXTURE_CUBE_MAP_POSITIVE_X + dir, level );
*/
shader->uniform( "uLod", static_cast<float>( level ) );
gl::clear( Color::black() );
cube->draw();
}
CI_LOG_V( "Mipmap level " << level << " generated at " << size );
size /= 2;
}
mCubeMapFilteredTex = fbo->getTextureCubeMap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment