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 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 ShaderToyApp::setUniforms() { auto shader = gl::context()->getGlslProg(); if( !shader ) return; // Calculate shader parameters. vec3 iResolution( vec2( getWindowSize() ), 1 ); float iGlobalTime = (float)getElapsedSeconds(); float iChannelTime0 = (float)getElapsedSeconds(); float iChannelTime1 = (float)getElapsedSeconds(); float iChannelTime2 = (float)getElapsedSeconds(); float iChannelTime3 = (float)getElapsedSeconds(); vec3 iChannelResolution0 = mChannel0 ? vec3( mChannel0->getSize(), 1 ) : vec3( 1 ); vec3 iChannelResolution1 = mChannel1 ? vec3( mChannel1->getSize(), 1 ) : vec3( 1 ); vec3 iChannelResolution2 = mChannel2 ? vec3( mChannel2->getSize(), 1 ) : vec3( 1 ); vec3 iChannelResolution3 = mChannel3 ? vec3( mChannel3->getSize(), 1 ) : vec3( 1 ); time_t now = time( 0 ); tm* t = gmtime( &now ); vec4 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 InstascopeApp::updateMirrors( vector<TrianglePiece> *vec ) { if( ! mMirrorTexture ) return; vec2 mSamplePt1( -0.5, -(sin(M_PI/3)/3) ); vec2 mSamplePt2( mSamplePt1.x + 1, mSamplePt1.y); vec2 mSamplePt3( mSamplePt1.x + (cos(M_PI/3)), mSamplePt1.y + (sin(M_PI/3))); mat3 mtrx( 1.0f ); mtrx = glm::translate( mtrx, mSamplePt.value() ); mtrx = glm::scale( mtrx, vec2( mSampleSize ) ); mtrx = glm::rotate( mtrx, float((getElapsedFrames()*4)/2*M_PI) ); mSamplePt1 = vec2( mtrx * vec3( mSamplePt1, 1.0 ) ); mSamplePt2 = vec2( mtrx * vec3( mSamplePt2, 1.0 ) ); mSamplePt3 = vec2( mtrx * vec3( mSamplePt3, 1.0 ) ); mSamplePt1 /= mMirrorTexture->getSize(); mSamplePt2 /= mMirrorTexture->getSize(); mSamplePt3 /= mMirrorTexture->getSize(); // loop through all the pieces and pass along the current texture and it's coordinates int outCount = 0; int inCount = 0; for( int i = 0; i < vec->size(); i++ ) { (*vec)[i].update( mMirrorTexture, mSamplePt1, mSamplePt2, mSamplePt3 ); if( (*vec)[i].isOut() ) outCount++; if( (*vec)[i].isIn() ) inCount++; } // if all are out, then make a new mirror grid if( outCount > 0 && outCount == mTriPieces.size() ) { mirrorOut(); } // if all the pieces are in if( inCount > 0 && inCount == mTriPieces.size() && ! mPiecesIn ) { mPiecesIn = true; mirrorIn(); } }
void ciApp::setup() { setWindowSize(1280, 720); setFrameRate(60.f); int maxVertUniformsVect; glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxVertUniformsVect); mSize = 0; mSizePrev = -1; mSizeMax = 17; mAmplifier = 1.f; mExposure = 1.f; mGamma = 2.2f; printf("max uniform: %i, %i\n", maxVertUniformsVect, mSizeMax); mParams = params::InterfaceGl::create(getWindow(), "App parameters", ivec2(250, 300)); mParams->setPosition(ivec2(20, 250)); mTexture = gl::Texture::create(loadImage(loadFile(data_path + "demo.png"))); mFbo = gl::Fbo::create(mTexture->getWidth(), mTexture->getHeight(), gl::Fbo::Format().colorTexture()); //mShader.setup("filterGaussianBlur"); filter = hb::GlslFilter::create(mTexture->getSize()); filter->setParams(mParams); vector_blur.setup(getWindowSize()); vector_blur.setParams(mParams); spout_receiver = hb::Receiver::create("Spout DX11 Sender"); //spout_receiver = hbSpoutReceiver::create("KidsLandSea"); spout_sender = hb::Sender::create("cinder_spout", mFbo->getWidth(), mFbo->getHeight()); #if 0 auto ctx = audio::Context::master(); // The InputDeviceNode is platform-specific, so you create it using a special method on the Context: mInputDeviceNode = ctx->createInputDeviceNode(); // By providing an FFT size double that of the window size, we 'zero-pad' the analysis data, which gives // an increase in resolution of the resulting spectrum data. auto monitorFormat = audio::MonitorSpectralNode::Format().fftSize(2048).windowSize(1024); mMonitorSpectralNode = ctx->makeNode(new audio::MonitorSpectralNode(monitorFormat)); mInputDeviceNode >> mMonitorSpectralNode; // InputDeviceNode (and all InputNode subclasses) need to be enabled()'s to process audio. So does the Context: mInputDeviceNode->enable(); ctx->enable(); #endif }