void gpgpuFrameBufferApp::update() { //Using bind call mBuffer->bindBuffer(); gl::viewport(mBuffer->getSize()); gl::setMatricesWindow( mBuffer->getSize() ); gl::clear(); mBuffer->bindTexture(); { shader->bind(); shader->uniform( "pixel", vec2(1.0f)/vec2(mBuffer->getSize()) ); shader->uniform( "texBuffer", 0 ); gl::color(Color::white()); gl::drawSolidRect(Rectf(vec2(0.0f),mBuffer->getSize())); } mBuffer->unbindTexture(); if(mMouseDown) { gl::getStockShader(gl::ShaderDef().color())->bind(); //Red channel will host the injected force from mouse position gl::color( ColorAf( 1.0f, 0.0f, 0.0f, 1.0f ) ); gl::drawSolidCircle( ( mMousePos ), 5.0f ); gl::color( Color::white() ); } mBuffer->unbindBuffer(true); }
void BayBridgeApp::drawFbo() { mFboRaw->bindFramebuffer(); gl::clear(Color::black()); gl::setMatrices(mCamera); drawBridge(vec3(0), 0.0f); mBridge.Draw(); mFboRaw->unbindFramebuffer(); //////////////////////////////////////////////////// mFboHiPass->bindFramebuffer(); mFboRaw->bindTexture(0); mShaderHiPass->bind(); gl::enableAlphaBlending(); gl::clear(ColorA::zero()); gl::setMatricesWindow(getWindowSize()); gl::drawSolidRect(Rectf({vec2(0), getWindowSize()})); gl::disableAlphaBlending(); mFboRaw->unbindTexture(0); mFboHiPass->unbindFramebuffer(); //////////////////////////////////////////////////// mFboBlurU->bindFramebuffer(); mFboHiPass->bindTexture(0); mShaderBlur->bind(); mShaderBlur->uniform("uBlurAxis", vec2(1.0, 0.0)); mShaderBlur->uniform("uBlurStrength", 2.0f); mShaderBlur->uniform("uBlurSize", 1.0f); gl::clear(ColorA::zero()); gl::setMatricesWindow(getWindowSize()); gl::drawSolidRect(Rectf({ vec2(0), getWindowSize() })); mFboHiPass->unbindTexture(0); mFboBlurU->unbindFramebuffer(); //////////////////////////////////////////////////// mFboBlurV->bindFramebuffer(); mFboBlurU->bindTexture(0); mShaderBlur->bind(); mShaderBlur->uniform("uBlurAxis", vec2(0.0, 1.0)); mShaderBlur->uniform("uBlurStrength", 2.0f); mShaderBlur->uniform("uBlurSize", 2.0f); gl::clear(ColorA::zero()); gl::setMatricesWindow(getWindowSize()); gl::drawSolidRect(Rectf({ vec2(0), getWindowSize() })); mFboBlurU->unbindTexture(0); mFboBlurV->unbindFramebuffer(); }
void ImmediateModeApp::setup() { mGlsl = gl::getStockShader( gl::ShaderDef().color() ); mGlsl->bind(); mBatch = gl::VertBatch::create( GL_POINTS, true ); }
void BayBridgeApp::drawBridge(vec3 pColor, float pAmbient) { mShaderDiffuse->bind(); mShaderDiffuse->uniform("uColor", pColor); mShaderDiffuse->uniform("uAmbient", pAmbient); gl::drawCube(vec3(0, -2, 0), vec3(1050, 5, 30)); gl::drawCube(vec3(500, -25, 0), vec3(30,50,30)); gl::drawCube(vec3(-500, -25, 0), vec3(30, 50, 30)); gl::drawCube(vec3(0, 30, 0), vec3(5, 180, 50)); }
void AudioObjApp::draw() { gl::clear( Color( 0, 0, 0 ) ); gl::enableAlphaBlending(); gl::enableDepthRead(); gl::enableDepthWrite(); gl::pushMatrices(); gl::setMatrices( mMayaCam.getCamera() ); if ( mFeature && mFeatureTex ) { mShader->bind(); mFeatureTex.enableAndBind(); mShader->uniform( "dataTex", 0 ); mShader->uniform( "texWidth", (float)mFeatureTex.getWidth() ); mShader->uniform( "texHeight", (float)mFeatureTex.getHeight() ); mShader->uniform( "soundDataSize", (float)mFeature->getSize() ); mShader->uniform( "spread", mFeatureSpread ); mShader->uniform( "spreadOffset", mFeatureSpreadOffset ); mShader->uniform( "time", (float)getElapsedSeconds() ); mShader->uniform( "tintColor", mObjColor ); } if ( mRenderWireframe ) gl::enableWireframe(); gl::color( Color(1.0f, 0.0f, 0.0f ) ); if ( mVbo ) gl::draw( mVbo ); if ( mRenderWireframe ) gl::disableWireframe(); mShader->unbind(); mFeatureTex.unbind(); gl::color( Color::white() ); // gl::drawCoordinateFrame(); gl::popMatrices(); gl::disableDepthRead(); gl::disableDepthWrite(); gl::setMatricesWindow( getWindowSize() ); ciXtractReceiver::drawData( mFeature, Rectf( 15, getWindowHeight() - 150, 255, getWindowHeight() - 35 ) ); gl::draw( mFeatureSurf ); mParams->draw(); }
void ShaderToyApp::bindShader(gl::GlslProgRef shader) { // Nothing to bind if we don't have a shader. if(!shader) return; // Bind the shader. shader->bind(); // Make sure it was successfull by checking for errors. GLenum err = glGetError(); if(err != GL_NO_ERROR) fatal("Failed to bind the shader!\n\nYour driver may not properly support shared contexts. Make sure you use the latest driver version and a proper GPU."); // Calculate shader parameters. Vec3f iResolution( Vec2f( getWindowSize() ), 1.f ); float iGlobalTime = (float) getElapsedSeconds(); float iChannelTime0 = (float) getElapsedSeconds(); float iChannelTime1 = (float) getElapsedSeconds(); float iChannelTime2 = (float) getElapsedSeconds(); float iChannelTime3 = (float) getElapsedSeconds(); Vec3f iChannelResolution0 = mChannel0 ? Vec3f( mChannel0->getSize(), 1.f ) : Vec3f::one(); Vec3f iChannelResolution1 = mChannel1 ? Vec3f( mChannel1->getSize(), 1.f ) : Vec3f::one(); Vec3f iChannelResolution2 = mChannel2 ? Vec3f( mChannel2->getSize(), 1.f ) : Vec3f::one(); Vec3f iChannelResolution3 = mChannel3 ? Vec3f( mChannel3->getSize(), 1.f ) : Vec3f::one(); time_t now = time(0); tm* t = gmtime(&now); Vec4f iDate( float(t->tm_year + 1900), float(t->tm_mon + 1), float(t->tm_mday), float(t->tm_hour * 3600 + t->tm_min * 60 + t->tm_sec) ); // Set shader uniforms. shader->uniform("iResolution", iResolution); shader->uniform("iGlobalTime", iGlobalTime); shader->uniform("iChannelTime[0]", iChannelTime0); shader->uniform("iChannelTime[1]", iChannelTime1); shader->uniform("iChannelTime[2]", iChannelTime2); shader->uniform("iChannelTime[3]", iChannelTime3); shader->uniform("iChannelResolution[0]", iChannelResolution0); shader->uniform("iChannelResolution[1]", iChannelResolution1); shader->uniform("iChannelResolution[2]", iChannelResolution2); shader->uniform("iChannelResolution[3]", iChannelResolution3); shader->uniform("iMouse", mMouse); shader->uniform("iChannel0", 0); shader->uniform("iChannel1", 1); shader->uniform("iChannel2", 2); shader->uniform("iChannel3", 3); shader->uniform("iDate", iDate); }
void ShaderLoadingApp::draw() { // Clear the window gl::clear( Color( 0, 0, 0 ) ); // Set a perspective projection matrix and center // the drawing at the center of the window gl::setMatricesWindowPersp( getWindowSize() ); gl::translate( getWindowCenter() ); // Draw a sphere and use our shader if available. // Wrapping the shader code into a "if" block ensure // that it won't be used if the shader hasn't been validated. if( mShader ) mShader->bind(); gl::drawSphere( Vec3f::zero(), 180, 36 ); if( mShader ) mShader->unbind(); }
void BulletSpheresApp::draw() { drawToDepthFbo(); gl::clear( Color( 0.1f, 0.1f, 0.1f ) ); gl::setMatrices( mCam ); gl::viewport( vec2( 0 ), getWindowSize() ); // Draw small spheres { gl::ScopedTextureBind scopeTex0( mLight->getFbo()->getDepthTexture(), 0 ); gl::ScopedTextureBind scopeTex1( mStripeTex, 1 ); mRenderGlsl->uniform( "uShadowMap", 0 ); mRenderGlsl->uniform( "uStripeTex", 1 ); mRenderGlsl->uniform( "uLightPos", mLight->getPos() ); mRenderGlsl->uniform( "uDepthBias", mLight->getDepthBias() ); mRenderGlsl->uniform( "uLightPos1", mRigidBodies[0].getPos() ); mRenderGlsl->uniform( "uLightPos2", mRigidBodies[1].getPos() ); mRenderGlsl->uniform( "uRadius1", mRigidBodies[0].getSize() ); mRenderGlsl->uniform( "uRadius2", mRigidBodies[1].getSize() ); mRenderGlsl->uniform( "uShadowMvp", mLight->getViewProjection() ); mRenderSphere->drawInstanced( NUM_PARTICLES - 2 ); } // Draw big spheres mGlowGlsl->bind(); mGlowGlsl->uniform( "uLightPos", mLight->getPos() ); for( auto &body : mRigidBodies ){ auto index = body.getId(); if( index < NUM_GLOWS ){ mGlowGlsl->uniform( "uColor", mGlowColors[index] ); body.draw(); } } // Draw light source (if point light) if( mLight->getPos().w > 0.5f ) mLight->draw(); mContext->debugDraw(); }
void SyphonBasicApp::draw() { gl::enableAlphaBlending(); gl::clear(Color::white()); gl::color(ColorA(1.f, 1.f, 1.f, 1.f)); mShader->bind(); mShader->uniform( "tex0", 0 ); mShader->uniform( "sampleOffset", Vec2f( cos( mAngle ), sin( mAngle ) ) * ( 3.0f / getWindowWidth() ) ); gl::draw(mLogo, Vec2f::zero()); mShader->unbind(); mClientSyphon.draw(Vec2f(16.f, 64.f)); //draw our client image mScreenSyphon.publishScreen(); //publish the screen's output mTextureSyphon.publishTexture(mLogo); //publish our texture without shader //anything that we draw after here will not be published gl::drawStringCentered("This text will not be published to Syphon.", Vec2f(getWindowCenter().x, 20.f), ColorA::black()); }
void DelayFeedback::draw() { gl::clear(); if( ! mGlsl || ! mMesh ) return; mGlsl->bind(); for( const auto &splash : mSplashes ) { float radiusNormalized = splash.mRadius / MAX_RADIUS; mGlsl->uniform( "uRadius", radiusNormalized ); Color splashColor( CM_HSV, splash.mColorHsv ); gl::color( splashColor.r, splashColor.g, splashColor.b, splash.mAlpha() ); gl::pushModelView(); gl::translate( splash.mCenter ); gl::draw( mMesh ); gl::popModelView(); } mGlsl->unbind(); }
void ProceduralAnimApp::draw() { // clear out the window with black gl::clear( Color( 0.4f, 0.5f, 0.6f ) ); gl::setMatrices( mMayaCam.getCamera() ); gl::enableDepthRead(); gl::Light light( gl::Light::DIRECTIONAL, 0 ); light.setAmbient( Color::white() ); light.setDiffuse( Color::white() ); light.setSpecular( Color::white() ); light.lookAt( mLightPos, Vec3f::zero() ); light.update( mMayaCam.getCamera() ); light.enable(); gl::pushMatrices(); float e = (float)getElapsedSeconds(); gl::translate( math<float>::sin( 1.3f * e ), math<float>::cos( 2.7f * e ) ); gl::enable( GL_LIGHTING ); gl::enable( GL_NORMALIZE ); if ( mEnableWireframe ) gl::enableWireframe(); if( mDrawMesh ) { SkinningRenderer::draw( mSkinnedVboBird ); } if ( mEnableWireframe ) gl::disableWireframe(); gl::disable( GL_LIGHTING ); gl::disable( GL_NORMALIZE ); if( mDrawSkeleton) { SkinningRenderer::draw( mSkinnedVboBird->getSkeleton() ); } if( mDrawLabels ) { SkinningRenderer::drawLabels( mSkinnedVboBird->getSkeleton(), mMayaCam.getCamera() ); } gl::popMatrices(); Vec3f mRight, mUp; mMayaCam.getCamera().getBillboardVectors(&mRight, &mUp); // gl::disableDepthRead(); gl::disableDepthWrite(); gl::enableAlphaBlending(); dustParticleTex->enableAndBind(); mDustShader->bind(); mDustShader->uniform( "tex", 0 ); for( const auto& d : mDust ) { mDustShader->uniform( "transparency", 1.0f - math<float>::abs(d.z)/(SCENE_SIZE/2.0f) ); gl::drawBillboard(d, Vec2f(60.f, 60.f), 0.0f, mRight, mUp); } mDustShader->unbind(); dustParticleTex->unbind(); mParams.draw(); }
void redEyeApp::draw() { gl::clear(mColorBack); mTextureSnd.bind(0); mTextureFft.bind(1); if(mShader!=NULL) { mShader->bind(); mShader->uniform("iResolution", (Vec2f)getWindowSize()); mShader->uniform("iGlobalTime", (float)getElapsedSeconds()); mShader->uniform("iAmplitude", mAmplitude); mShader->uniform("iChannel0", 0); //sound mShader->uniform("iChannel1", 1); //fft } //TODO more drawing modes (lines, bars, rects, cubes...) //TODO mDownSample glPushMatrix(); gl::translate(getWindowCenter()); gl::scale(mScale0); gl::rotate(mRotate0); gl::translate(mTranslate0); gl::color(mColor0); gl::lineWidth(mWidth); switch(mMode) { case 0: gl::drawSolidRect(Rectf(getWindowBounds()-(getWindowSize()*0.5))); break; case 1: gl::drawSolidRect(Rectf(getWindowBounds()-(getWindowSize()*0.5)).scaledCentered(0.8f)); break; case 2: gl::drawSolidTriangle( (Vec2f)getWindowSize()*Vec2f(0.0f, -0.375f), (Vec2f)getWindowSize()*Vec2f(-0.375f, 0.375f), (Vec2f)getWindowSize()*Vec2f(0.375f, 0.375f)); break; case 3: gl::drawSolidCircle(Vec2f::zero(), getWindowHeight()*0.4f, 100); break; case 4: gl::drawSphere(Vec3f::zero(), getWindowHeight()*0.4f, 12); //sphere detail break; case 5: drawWaveform(false); break; case 6: drawWaveform(true); break; case 7: drawSpectrum(false); break; case 8: drawSpectrum(true); break; } glPopMatrix(); if(mShader!=NULL) { mShader->unbind(); mTextureSnd.unbind(); mTextureFft.unbind(); } if(!mHide) { mParams->draw(); } }
void ShaderToyApp::draw() { // Bind textures. if(mChannel0) mChannel0->bind(0); if(mChannel1) mChannel1->bind(1); if(mChannel2) mChannel2->bind(2); if(mChannel3) mChannel3->bind(3); // Render the current shader to a frame buffer. if(mShaderCurrent && mBufferCurrent) { mBufferCurrent.bindFramebuffer(); // Bind shader. bindShader(mShaderCurrent); // Clear buffer and draw full screen quad (flipped). gl::clear(); gl::drawSolidRect( Rectf(0, getWindowHeight(), getWindowWidth(), 0) ); // Done. mShaderCurrent->unbind(); mBufferCurrent.unbindFramebuffer(); } // Render the next shader to a frame buffer. if(mShaderNext && mBufferNext) { mBufferNext.bindFramebuffer(); // Bind shader. bindShader(mShaderNext); // Clear buffer and draw full screen quad (flipped). gl::clear(); gl::drawSolidRect( Rectf(0, getWindowHeight(), getWindowWidth(), 0) ); // Done. mShaderNext->unbind(); mBufferCurrent.unbindFramebuffer(); } // Perform a cross-fade between the two shaders. double time = getElapsedSeconds() - mTransitionTime; double fade = math<double>::clamp( time / mTransitionDuration, 0.0, 1.0 ); if(fade <= 0.0) { // Transition has not yet started. Keep drawing current buffer. gl::draw( mBufferCurrent.getTexture(), getWindowBounds() ); } else if(fade < 1.0) { // Transition is in progress. // Use a transition shader to avoid having to draw one buffer on top of another. mBufferNext.getTexture().bind(1); mShaderTransition->bind(); mShaderTransition->uniform("iSrc", 0); mShaderTransition->uniform("iDst", 1); mShaderTransition->uniform("iFade", (float)fade); gl::draw( mBufferCurrent.getTexture(), getWindowBounds() ); mShaderTransition->unbind(); } else if(mShaderNext) { // Transition is done. Swap shaders. gl::draw( mBufferNext.getTexture(), getWindowBounds() ); mShaderCurrent = mShaderNext; mShaderNext.reset(); mPathCurrent = mPathNext; mPathNext.clear(); getWindow()->setTitle( std::string("ShaderToyApp - Showing ") + mPathCurrent.filename().string() ); } else { // No transition in progress. gl::draw( mBufferCurrent.getTexture(), getWindowBounds() ); } }
void MeshViewApp::draw() { // Clear the window gl::clear(); gl::color(Color::white()); if(isInitialized()) { // Get ready to draw in 3D gl::pushMatrices(); gl::setMatrices(m_camera); gl::enableDepthRead(); gl::enableDepthWrite(); // Bind textures if(m_texDiffuse) m_texDiffuse->enableAndBind(); if (m_texNormal) m_texNormal->bind(1); if (m_texSpecular) m_texSpecular->bind(2); if(m_texAO) m_texAO->bind(3); if(m_texEmissive) m_texEmissive->bind(4); // Bind shader m_shader->bind(); m_shader->uniform("texDiffuse", 0); m_shader->uniform("texNormal", 1); m_shader->uniform("texSpecular", 2); m_shader->uniform("texAO", 3); m_shader->uniform("texEmissive", 4); m_shader->uniform("texDiffusePower", m_texDiffusePower); m_shader->uniform("texNormalPower", m_texNormalPower); m_shader->uniform("texSpecularPower", m_texSpecularPower); m_shader->uniform("texAOPower", m_texAOPower); m_shader->uniform("texEmissivePower", m_texEmissivePower); m_shader->uniform("diffuseEnabled", m_diffuseEnabled); m_shader->uniform("normalEnabled", m_normalEnabled); m_shader->uniform("specularEnabled", m_specularEnabled); m_shader->uniform("aoEnabled", m_aoEnabled); m_shader->uniform("emissiveEnabled", m_emissiveEnabled); m_shader->uniform("material.Ka", m_matAmbient); m_shader->uniform("material.Kd", m_matDiffuse); m_shader->uniform("material.Ks", m_matSpecular); m_shader->uniform("material.Shininess", m_matShininess); m_shader->uniform("gamma", m_gamma); // Enable lights m_light1->enable(); m_light2->enable(); // Render model gl::pushModelView(); gl::multModelView(m_matrix); m_assimpLoader.draw(); gl::popModelView(); // Disable lights m_light1->disable(); m_light2->disable(); // Unbind shader m_shader->unbind(); // Unbind textures gl::disable(m_texDiffuse->getTarget()); // Disable 3D rendering gl::disableDepthWrite(); gl::disableDepthRead(); // Restore matrices gl::popMatrices(); // Enable 2D rendering gl::setMatricesWindow(getWindowSize()); gl::setViewport(getWindowBounds()); // Render parameter window if(m_params) m_params->draw(); } // Render debug information Debug::get().draw(ColorAf::white()); }
void shader02vertexApp::draw() { gl::clear(Color(0, 0, 0)); if(mPcmBuffer) { mTextureSnd.bind(0); mTextureFft.bind(1); } mShader->bind(); mShader->uniform("iResolution", (Vec2f)getWindowSize()); mShader->uniform("iGlobalTime", (float)getElapsedSeconds()); mShader->uniform("iAmplitude", mAmplitude); if(mPcmBuffer) { mShader->uniform("iChannel0", 0); //sound mShader->uniform("iChannel1", 1); //fft } mShader->uniform("iMouse", mMouse); gl::color(1.0f, 1.0f, 1.0f); switch(mMode) { case 0: gl::drawSolidRect(Rectf(getWindowBounds())); break; case 1: gl::drawSolidRect(Rectf(getWindowBounds()).scaledCentered(0.8f)); break; case 2: gl::drawSolidTriangle( getWindowCenter()*Vec2f(1.0f, 0.25f), getWindowCenter()*Vec2f(0.25f, 1.75f), getWindowCenter()*Vec2f(1.75f, 1.75f)); break; case 3: gl::drawSolidCircle(getWindowCenter(), getWindowHeight()*0.4f, 100); break; case 4: gl::drawSphere((Vec3f)getWindowCenter(), getWindowHeight()*0.4f, 12); //sphere detail break; case 5: drawWaveform(false); break; case 6: drawWaveform(true); break; case 7: drawSpectrum(false); break; case 8: drawSpectrum(true); break; } mShader->unbind(); if(mPcmBuffer) { mTextureSnd.unbind(); mTextureFft.unbind(); } if(!mHide) { Color col= Color(1, 1, 1); Font fnt= Font("Verdana", 12); gl::drawString("mode (m): "+toString(mMode), Vec2f(30.0f, getWindowHeight()-100.0f), col, fnt); gl::drawString("frag (f): "+toString(mPathFrag.filename()), Vec2f(30.0f, getWindowHeight()-80.0f), col, fnt); gl::drawString("vert (v): "+toString(mPathVert.filename()), Vec2f(30.0f, getWindowHeight()-60.0f), col, fnt); gl::drawString("error: "+mError, Vec2f(30.0f, getWindowHeight()-40.0f), col, fnt); gl::drawString("fps: "+toString(getAverageFps()), Vec2f(30.0f, getWindowHeight()-20.0f), col, fnt); } }