void NormalGetterApp::normalize(gl::TextureRef _tex){ { gl::ScopedMatrices push; gl::ScopedFramebuffer fbo(mOutputFbo); gl::clear(); ci::gl::setMatricesWindow( mOutputFbo->getSize() ); ci::gl::ScopedViewport view( ci::vec2(0), mOutputFbo->getSize() ); gl::ScopedGlslProg mGlsl(mNormalGlsl); gl::ScopedTextureBind tex0(_tex); mNormalGlsl->uniform("uSampler", 0); mNormalGlsl->uniform("u_textureSize", vec2(_tex->getWidth(), _tex->getHeight())); mNormalGlsl->uniform("bias", bias); mNormalGlsl->uniform("invertR", float(invertR ? -1.0 : 1.0) ); mNormalGlsl->uniform("invertG", float(invertG ? -1.0 : 1.0)); gl::drawSolidRect(Rectf(vec2(0), _tex->getSize())); } if( pushFramesToBuffer){ mPreprocessedImages->pushFront(std::make_pair(mOutputFbo->getColorTexture()->createSource(), currentFrame)); if(currentFrame == mMovie->getNumFrames()){ pushFramesToBuffer = false; mMovie->setLoop(true); mMovie->seekToStart(); } currentFrame++; } }
void srvlib::renderer::DrawTexture(ci::gl::Texture2dRef image, const glm::ivec2 &eye_size, const glm::ivec2 &draw_size, ci::gl::GlslProgRef shader){ ci::gl::disableDepthRead(); ci::gl::disableDepthWrite(); ci::gl::pushMatrices(); auto vp = ci::gl::getViewport(); ci::CameraOrtho o; o.setOrtho(0.0f, (float)eye_size[0], 0.0f, (float)eye_size[1], (float)0, (float)1); ci::gl::setProjectionMatrix(o.getProjectionMatrix()); ci::gl::setModelMatrix(glm::mat4()); ci::gl::setViewMatrix(glm::mat4()); image->bind(); if (shader){ shader->bind(); shader->uniform("tex0", 0); } else{ auto default_shader = ci::gl::getStockShader(ci::gl::ShaderDef().color().lambert()); default_shader->bind(); } ci::Rectf bounds(0, 0, draw_size[0], draw_size[1]); ci::gl::viewport(draw_size); ci::gl::drawSolidRect(bounds);// , glm::vec2(0, 0), glm::vec2(1, 1)); ci::gl::viewport(vp); image->unbind(); ci::gl::popMatrices(); ci::gl::enableDepthRead(); ci::gl::enableDepthWrite(); }
void srvlib::renderer::DrawModel(std::shared_ptr<Model> model, std::shared_ptr<StereoCamera> camera, const bool is_left, const glm::mat4 &camera_pose, ci::gl::GlslProgRef shader){ ci::gl::enableDepthWrite(); ci::gl::enableDepthRead(); ci::gl::pushMatrices(); shader->bind(); if (is_left) camera->setupLeftCamera(shader, camera_pose); else camera->setupRightCamera(shader, camera_pose); model->Draw(); camera->unsetCameras(); ci::gl::popMatrices(); }
void srvlib::renderer::DrawModel(ci::gl::VboMeshRef model, const glm::mat4 &model_transform, std::shared_ptr<StereoCamera> camera, const bool is_left, const glm::mat4 &camera_pose, ci::gl::GlslProgRef shader){ ci::gl::enableDepthWrite(); ci::gl::enableDepthRead(); ci::gl::pushMatrices(); shader->bind(); if (is_left) camera->setupLeftCamera(shader, camera_pose); else camera->setupRightCamera(shader, camera_pose); ci::gl::multModelMatrix(model_transform); ci::gl::draw(model); camera->unsetCameras(); ci::gl::popMatrices(); }
void GlslParams::applyUniforms( const ci::gl::GlslProgRef &glslRef ) { for( auto &it : mBoolParams ) { glslRef->uniform( it.first, it.second ); } for( auto &it : mIntParams ) { glslRef->uniform( it.first, it.second ); } for( auto &it : mFloatParams ) { glslRef->uniform( it.first, it.second ); } for( auto &it : mVec2Params ) { glslRef->uniform( it.first, it.second ); } for( auto &it : mVec3Params ) { glslRef->uniform( it.first, it.second ); } for( auto &it : mVec4Params ) { glslRef->uniform( it.first, it.second ); } for( auto &it : mColorParams ) { glslRef->uniform( it.first, it.second ); } }
void GpGpuApp::draw() { // We're going to draw new data onto the "ping" FBO, // using the "pong" FBO's textures as input size_t pong = ( mFboIndex + 1 ) % 2; // Set up OpenGL for data gl::disableDepthRead(); gl::disableDepthWrite(); gl::setViewport( mFbo[ mFboIndex ].getBounds() ); gl::color( ColorAf::white() ); // Draw any new input onto the acceleration texture mFbo[ pong ].bindFramebuffer(); glDrawBuffer( GL_COLOR_ATTACHMENT2 ); if ( mMouseDown ) { Vec2f fboSize = Vec2f( mFbo[ mFboIndex ].getSize() ); Vec2f winSize = Vec2f( app::getWindowSize() ); gl::setMatricesWindow( fboSize, true ); Vec2f brushSize = Vec2f::one() * mBrushSize * fboSize; Vec2f pos = ( mMouse / winSize ); pos.y = 1.0f - pos.y; pos *= fboSize; mGlslProgGpGpu0->bind(); mGlslProgGpGpu0->uniform( "color", ColorAf( mMouseVelocity.x, 0.0f, 1.0f - mMouseVelocity.y, 1.0f ) ); mGlslProgGpGpu0->uniform( "tex", 0 ); gl::enable( GL_TEXTURE_2D ); mTextureBrush->bind(); gl::drawSolidRect( Rectf( pos - brushSize, pos + brushSize ) ); mTextureBrush->unbind(); gl::disable( GL_TEXTURE_2D ); mGlslProgGpGpu0->unbind(); } mFbo[ pong ].unbindFramebuffer(); // Now let's do an update pass in GLSL mFbo[ mFboIndex ].bindFramebuffer(); gl::setMatricesWindow( mFbo[ mFboIndex ].getSize(), false ); // Bind the "pong" textures to use as input data for ( int32_t i = 0; i < 3; ++i ) { mFbo[ pong ].bindTexture( i, i ); } // Set up shader to read data textures mGlslProgGpGpu1->bind(); mGlslProgGpGpu1->uniform( "offsets", 0 ); mGlslProgGpGpu1->uniform( "velocities", 1 ); mGlslProgGpGpu1->uniform( "acceleration", 2 ); // Draw a rect to process data glDrawBuffers( 3, kColorAttachments ); gl::drawSolidRect( mFbo[ pong ].getBounds() ); // Unbind everything mFbo[ pong ].unbindTexture(); mGlslProgGpGpu1->unbind(); mFbo[ mFboIndex ].unbindFramebuffer(); // Swap FBOs mFboIndex = pong; ///////////////////////////////// // Make sure we have data to work with before we draw geometry if ( mFbo[ mFboIndex ] && mFbo[ mFboIndex ].getTexture( 0 ) && mFbo[ mFboIndex ].getTexture( 1 ) ) { // Set up window for 3D drawing gl::clear( Colorf( 0.5f, 0.45f, 0.4f ) ); gl::setViewport( getWindowBounds() ); gl::setMatrices( mCamera ); gl::enableDepthRead(); gl::enableDepthWrite(); gl::multModelView( mArcball.getQuat() ); gl::color( ColorAf::black() ); // Set up shader to render scene mGlslProgDraw->bind(); mGlslProgDraw->uniform( "Ax", mLightAmbient ); mGlslProgDraw->uniform( "Ac", mLightAttenuationConstant ); mGlslProgDraw->uniform( "Al", mLightAttenuationLinear ); mGlslProgDraw->uniform( "Aq", mLightAttenuationQuadratic ); mGlslProgDraw->uniform( "Dx", mLightDiffuse ); mGlslProgDraw->uniform( "eyePoint", mEyePoint ); mGlslProgDraw->uniform( "Ka", mMaterialAmbient ); mGlslProgDraw->uniform( "Kd", mMaterialDiffuse ); mGlslProgDraw->uniform( "Ke", mMaterialEmissive ); mGlslProgDraw->uniform( "Ks", mMaterialSpecular ); mGlslProgDraw->uniform( "lightPos", mLightPosition ); mGlslProgDraw->uniform( "n", mLightShine ); mGlslProgDraw->uniform( "offsets", 0 ); mGlslProgDraw->uniform( "projection", mCamera.getProjectionMatrix() ); mGlslProgDraw->uniform( "size", Vec2f( mSize ) ); mGlslProgDraw->uniform( "Sx", mLightSpecular ); mGlslProgDraw->uniform( "t", (float)getElapsedSeconds() ); // Bind textures to use as input data for ( int32_t i = 0; i <= 2; ++i ) { mFbo[ mFboIndex ].bindTexture( i, i ); } // Draw instanced drawInstanced( mMesh, mSize.x * mSize.y ); // Finished drawing mFbo[ mFboIndex ].unbindTexture(); mGlslProgDraw->unbind(); // Draw textures so we can see what's going on under the hood gl::setMatricesWindow( getWindowSize() ); gl::disableDepthRead(); gl::disableDepthWrite(); gl::color( ColorAf::white() ); gl::pushMatrices(); float x = 20.0f; float y = 440.0f; float width = 64.0f; Area srcArea( Vec2i::zero(), mSize ); Rectf destRect( x, y, x + width, y + width ); gl::draw( mFbo[ 0 ].getTexture( 0 ), srcArea, destRect ); destRect.x1 += width; destRect.x2 += width; gl::draw( mFbo[ 1 ].getTexture( 0 ), srcArea, destRect ); destRect.y1 += width; destRect.y2 += width; destRect.x1 = x; destRect.x2 = x + width; gl::draw( mFbo[ 0 ].getTexture( 1 ), srcArea, destRect ); destRect.x1 += width; destRect.x2 += width; gl::draw( mFbo[ 1 ].getTexture( 1 ), srcArea, destRect ); destRect.y1 += width; destRect.y2 += width; destRect.x1 = x; destRect.x2 = x + width; gl::draw( mFbo[ 0 ].getTexture( 2 ), srcArea, destRect ); destRect.x1 += width; destRect.x2 += width; gl::draw( mFbo[ 1 ].getTexture( 2 ), srcArea, destRect ); gl::popMatrices(); } // Draw parameters if ( getElapsedFrames() > 1 ) { // This condition prevents a memory leak mParams->draw(); } }