void ShadowMappingBasic::draw()
{
	renderDepthFbo();

	gl::clear( Color::black() );
	gl::setMatrices( mCam );

	gl::ScopedTextureBind texScope( mShadowMapTex, (uint8_t) 0 );

	vec3 mvLightPos	= vec3( gl::getModelView() * vec4( mLightPos, 1.0f ) ) ;
	mat4 shadowMatrix = mLightCam.getProjectionMatrix() * mLightCam.getViewMatrix();

	mGlsl->uniform( "uShadowMap", 0 );
	mGlsl->uniform( "uLightPos", mvLightPos );
	mGlsl->uniform( "uShadowMatrix", shadowMatrix );
	
	drawScene( false );
    
    // Uncomment for debug
    /*
    gl::setMatricesWindow( getWindowSize() );
    gl::color( 1.0f, 1.0f, 1.0f );
    float size = 0.5f*std::min( getWindowWidth(), getWindowHeight() );
    gl::draw( mShadowMapTex, Rectf( 0, 0, size, size ) );
    */
}
void MotionBlurVelocityBufferApp::dilateVelocity()
{
    gl::ScopedFramebuffer fbo( mVelocityDilationBuffer );
    gl::ScopedViewport viewport( ivec2( 0, 0 ), mVelocityDilationBuffer->getSize() );
    gl::ScopedMatrices	matrices;
    gl::setMatricesWindowPersp( mVelocityDilationBuffer->getSize() );

    {   // downsample velocity into tilemax
        gl::ScopedTextureBind tex( mGBuffer->getTexture2d( G_VELOCITY ), 0 );
        gl::ScopedGlslProg prog( mTileProg );
        gl::drawBuffer( DILATE_TILE_MAX );

        mTileProg->uniform( "uVelocityMap", 0 );
        mTileProg->uniform( "uTileSize", mTileSize );

        gl::drawSolidRect( mVelocityDilationBuffer->getBounds() );
    }
    {   // build max neighbors from tilemax
        gl::ScopedTextureBind tex( mVelocityDilationBuffer->getTexture2d( DILATE_TILE_MAX ), 0 );
        gl::ScopedGlslProg prog( mNeighborProg );
        gl::drawBuffer( DILATE_NEIGHBOR_MAX );

        mNeighborProg->uniform( "uTileMap", 0 );

        gl::drawSolidRect( mVelocityDilationBuffer->getBounds() );
    }
}
Exemple #3
0
void MeshViewApp::loadShader(const std::string& fileName)
{
	DBG_REMOVE(DBG_INFO);
	DBG_REMOVE(DBG_ERROR);

	try
	{
		std::string vertexFile = fileName + ".vert";
		std::string fragmentFile = fileName + ".frag";

		m_fileMonitorVert = FileMonitor::create(getAssetPath(vertexFile));
		m_fileMonitorFrag = FileMonitor::create(getAssetPath(fragmentFile));
		m_shader = gl::GlslProg::create(loadAsset(vertexFile), loadAsset(fragmentFile));
		const std::string log = m_shader->getShaderLog(m_shader->getHandle());

		if(log != std::string())
			DBG(DBG_INFO, m_shader->getShaderLog(m_shader->getHandle()));
	}
	catch(gl::GlslProgCompileExc& e)
	{
		console() << "Shader load or compile error:" << std::endl;
		console() << e.what() << std::endl;
		DBG(DBG_ERROR, std::string(e.what()));
	}
}
void SphericalStereoApp::update()
{
	if( mRift ) {
		hmd::ScopedRiftBuffer bind{ mRift };
		gl::clear();
		for( auto eye : mRift->getEyes() ) {
			mRift->enableEye( eye );
			const auto& pano = mPanos.at( mPanoIndex );
			mStereoGlsl->uniform( "uDisplayMode", pano.mDisplayMode );
			mStereoGlsl->uniform( "uRightEye", static_cast<int>(eye) );
			gl::ScopedTextureBind tex0( pano.mLatLong );
			mSphere->draw();

			{
				auto size = mRift->getFboSize();
				gl::ScopedMatrices push;
				gl::setMatricesWindow( size.x / 2, size.y );
				vec3 latencies = mRift->getLatencies();

				stringstream ss;
				ss << mPanos.at( mPanoIndex ).mName << std::endl;
				ss << " " << std::endl;
				ss << "App fps: " << toString( getAverageFps() ) << std::endl;
				ss << "Ren: " << latencies.x << std::endl;
				ss << "TWrp: " << latencies.y << std::endl;
				ss << "PostPresent: " << latencies.z << std::endl;

				auto tbox = TextBox().text( ss.str() ).font( Font( "Arial", 20.0f ) ).color( Color::white() ).backgroundColor( Color::black() );
				gl::draw( gl::Texture2d::create( tbox.render() ), vec2( size.x / 3, size.y / 2 ) );
			}
		}
	}
}
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 gpgpuFrameBufferApp::draw()
{
    gl::clear( Color( 0, 0, 0 ) );
    gl::viewport(getWindowSize());
    gl::setMatricesWindow( getWindowSize() );
    
    gl::enableAdditiveBlending();
    
    //using scoped
    {
        gl::ScopedTextureBind t0(mBuffer->getTexture(), 0);
        gl::ScopedTextureBind t1(mTexture, 1);
        
        gl::ScopedGlslProg sh(shaderRefraction);
        shaderRefraction->uniform( "pixel", vec2(1.0f)/vec2(mBuffer->getSize()) );
        shaderRefraction->uniform( "texBuffer", 0 );
        shaderRefraction->uniform( "texRefract", 1 );
        
        gl::drawSolidRect(getWindowBounds());
    }
    
    mBuffer->draw();
    

    
}
void TextParticlesApp::update()
{
	if( !mActive )
		return;

	// Update particles on the GPU
	gl::ScopedGlslProg prog( mUpdateProg );
	gl::ScopedState rasterizer( GL_RASTERIZER_DISCARD, true );	// turn off fragment stage
	mPerlin3dTex->bind(0);
	mUpdateProg->uniform( "uPerlinTex", 0 );
	mUpdateProg->uniform( "uStep", mStep.value() );
	mUpdateProg->uniform( "uDampingSpeed", mDampingSpeed );
	mUpdateProg->uniform( "uNoiseOffset", mNoiseOffset );
	mUpdateProg->uniform( "uEndColor", mEndColor );
	
	// Bind the source data (Attributes refer to specific buffers).
	gl::ScopedVao source( mAttributes[mSourceIndex] );
	// Bind destination as buffer base.
	gl::bindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER, 0, mParticleBuffer[mDestinationIndex] );
	gl::beginTransformFeedback( GL_POINTS );

	// Draw source into destination, performing our vertex transformations.
	gl::drawArrays( GL_POINTS, 0, mTextParticleCount );
	gl::endTransformFeedback();
	
	mPerlin3dTex->unbind();
	
	// Swap source and destination for next loop
	std::swap( mSourceIndex, mDestinationIndex );
}
void AudioVisualizerApp::draw()
{
	gl::clear();

	// use camera
	gl::pushMatrices();
	gl::setMatrices( mCamera );
	{
		// bind shader
		gl::ScopedGlslProg shader( mShader );
		mShader->uniform( "uTexOffset", mOffset / float( kHistory ) );
		mShader->uniform( "uLeftTex", 0 );
		mShader->uniform( "uRightTex", 1 );

		// create textures from our channels and bind them
		mTextureLeft = gl::Texture2d::create( mChannelLeft, mTextureFormat );
		mTextureRight = gl::Texture2d::create( mChannelRight, mTextureFormat );

		gl::ScopedTextureBind tex0( mTextureLeft, 0 );
		gl::ScopedTextureBind tex1( mTextureRight, 1 );

		// draw mesh using additive blending
		gl::ScopedBlendAdditive blend;
		gl::ScopedColor color( 1, 1, 1 );
		gl::draw( mMesh );
	}
	gl::popMatrices();
}
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 GeometryApp::draw()
{
	// Prepare for drawing.
	gl::clear();
	gl::setMatrices( mCamera );
	
	// Draw the grid.
	if( mShowGrid && mGrid ) {
		gl::ScopedGlslProg scopedGlslProg( gl::context()->getStockShader( gl::ShaderDef().color() ) );
		// draw the coordinate frame with length 2.
		gl::drawCoordinateFrame( 2 );
		mGrid->draw();
	}

	if( mPrimitive ) {
		gl::ScopedTextureBind scopedTextureBind( mTexture );
		mPhongShader->uniform( "uTexturingMode", mTexturingMode );

		// Rotate it slowly around the y-axis.
		gl::ScopedModelMatrix matScope;
		gl::rotate( float( getElapsedSeconds() / 5 ), 0, 1, 0 );

		// Draw the normals.
		if( mShowNormals && mPrimitiveNormalLines ) {
			gl::ScopedColor colorScope( Color( 1, 1, 0 ) );
			mPrimitiveNormalLines->draw();
		}

		// Draw the primitive.
		gl::ScopedColor colorScope( Color( 0.7f, 0.5f, 0.3f ) );

		if( mViewMode == WIREFRAME ) {
			// We're using alpha blending, so render the back side first.
			gl::ScopedAlphaBlend blendScope( false );
			gl::ScopedFaceCulling cullScope( true, GL_FRONT );

			mWireframeShader->uniform( "uBrightness", 0.5f );
			mPrimitiveWireframe->draw();

			// Now render the front side.
			gl::cullFace( GL_BACK );

			mWireframeShader->uniform( "uBrightness", 1.0f );
			mPrimitiveWireframe->draw();
		}
		else
			mPrimitive->draw();
	}

	// Render the parameter window.
#if ! defined( CINDER_GL_ES )
	if( mParams )
		mParams->draw();
#endif
}
void GeometryShaderIntroApp::draw()
{
	gl::clear();
	
	gl::setMatricesWindow( getWindowWidth(), getWindowHeight() );
	gl::translate( getWindowCenter() );

	gl::ScopedGlslProg glslProg( mGlsl );
	mGlsl->uniform( "uNumSides", mNumSides );
	mGlsl->uniform( "uRadius", mRadius );	
	mBatch->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);
}
Exemple #13
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);
}
Exemple #14
0
void Day41App::update()
{
    lightPos.x = (1.5f * cos(theta)) - 0.5;
    lightPos.y = 2+ 1.5f * sin(theta);
    lightPos.z = 1.5f;// * sin(theta*2);

    theta += 0.0523;

    eyePos = mCam.getEyePoint();

    mGlsl->uniform("light.position", vec3(mCam.getViewMatrix() * vec4(lightPos, 1.0f)));
    mGlsl->uniform("viewPos",  vec3(mCam.getViewMatrix() * vec4(eyePos, 1.0f)));

    vec3 lightColor = vec3(1.f);

    vec3 diffuseColor = lightColor * vec3(0.9f);
    vec3 ambientColor = diffuseColor * vec3(0.5f);

    mGlsl->uniform("light.diffuse", diffuseColor);
    mGlsl->uniform("light.specular", vec3(1.f));

    mGlsl->uniform("material.ambient", vec3(1.0f, 0.5f, 0.31f));
    mGlsl->uniform("material.diffuse", 0); //pass the diffuse map texture to shader
    mGlsl->uniform("material.specular", 1); //pass the specular map texture to the shader
    mGlsl->uniform("material.shininess", 32.f);


}
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 MotionBlurVelocityBufferApp::drawBlurredContent()
{
    gl::ScopedTextureBind colorTex( mGBuffer->getTexture2d( G_COLOR ), 0 );
    gl::ScopedTextureBind velTex( mGBuffer->getTexture2d( G_VELOCITY ), 1 );
    gl::ScopedTextureBind neigborTex( mVelocityDilationBuffer->getTexture2d( DILATE_NEIGHBOR_MAX ), 2 );
    gl::ScopedGlslProg prog( mMotionBlurProg );
    gl::ScopedBlendPremult blend;

    mMotionBlurProg->uniform( "uColorMap", 0 );
    mMotionBlurProg->uniform( "uVelocityMap", 1 );
    mMotionBlurProg->uniform( "uNeighborMaxMap", 2 );
    mMotionBlurProg->uniform( "uNoiseFactor", mBlurNoise );
    mMotionBlurProg->uniform( "uSamples", mSampleCount );

    gl::drawSolidRect( getWindowBounds() );
}
void ProfilerTestApp::draw()
{
	CI_SCOPED_CPU( mCpuProfiler, "Draw" );
	CI_SCOPED_GPU( mGpuProfiler, "Draw" );

	gl::clear();

	// Expensive CPU operation
	for( size_t i = 0; i < 20000; ++i ) {
		Rand::randVec3();
	}

	// Expensive GPU pass
	{
		CI_SCOPED_GPU( mGpuProfiler, "Noise pass" );
		gl::ScopedGlslProg s( mNoiseShader );
		mNoiseShader->uniform( "uTime", (float)app::getElapsedSeconds() );
		gl::drawSolidRect( app::getWindowBounds() );
	}

	// More gpu work...
	gl::drawSolidCircle( app::getWindowSize()/2, 100.0f, 50000 );

	CI_CHECK_GL();
}
void TransformFeedbackClothSimulationApp::update()
{
	gl::ScopedGlslProg	updateScope( mUpdateGlsl );
	gl::ScopedState		stateScope( GL_RASTERIZER_DISCARD, true );
	
	// This for loop allows iteration on the gpu of solving the
	// physics of the cloth.
	// Change mIterationsPerFrame to see the difference it makes
	for( int i = mIterationsPerFrame; i != 0; --i ) {
		// Pick using the mouse if it's pressed
		if( mouseMoving ) {
			mUpdateGlsl->uniform( "mouse_pos", currentMousePosition );
			mouseMoving = false;
		}
		
		gl::ScopedVao			vaoScope( mVaos[mIterationIndex & 1] );
		gl::ScopedTextureBind	textureBind( mPosBufferTextures[mIterationIndex & 1]->getTarget(),
											mPosBufferTextures[mIterationIndex & 1]->getId() );
		
		mIterationIndex++;
		
		mFeedbackObjs[mIterationIndex & 1]->bind();
		
		gl::beginTransformFeedback( GL_POINTS );
		gl::drawArrays( GL_POINTS, 0, POINTS_TOTAL );
		gl::endTransformFeedback();
	}
}
Exemple #19
0
void GeometryApp::resize()
{
	mCamera.setAspectRatio( getWindowAspectRatio() );

	if( mWireframeShader )
		mWireframeShader->uniform( "uViewportSize", vec2( getWindowSize() ) );
}
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 ImmediateModeApp::setup()
{
	mGlsl = gl::getStockShader( gl::ShaderDef().color() );
	mGlsl->bind();

	mBatch = gl::VertBatch::create( GL_POINTS, true );

}
void ParticleSphereCSApp::update()
{
	// Update particles on the GPU
	gl::ScopedGlslProg prog( mUpdateProg );
	
	mUpdateProg->uniform( "uMouseForce", mMouseForce );
	mUpdateProg->uniform( "uMousePos", mMousePos );
	gl::ScopedBuffer scopedParticleSsbo( mParticleBuffer );

	gl::dispatchCompute( NUM_PARTICLES / WORK_GROUP_SIZE, 1, 1 );
	gl::memoryBarrier( GL_SHADER_STORAGE_BARRIER_BIT );

	// Update mouse force.
	if( mMouseDown ) {
		mMouseForce = 150.0f;
	}
}
void PointCloudVAO::setupCloud()
{
	mShader = gl::GlslProg::create(loadAsset("shaders/points.vert"), loadAsset("shaders/points.frag"));
	GLint posLoc = mShader->getAttribLocation("vPosition");
	GLint colorLoc = mShader->getAttribLocation("vColor");
	mVao = gl::Vao::create();
	mVbo = gl::Vbo::create(GL_ARRAY_BUFFER, mPoints, GL_DYNAMIC_DRAW);

	gl::ScopedVao vao(mVao);
	gl::ScopedBuffer vbo(mVbo);
	gl::enableVertexAttribArray(posLoc);
	gl::vertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, sizeof(Pt), (const GLvoid*)offsetof(Pt, PPos));
	gl::enableVertexAttribArray(colorLoc);
	gl::vertexAttribPointer(colorLoc, 3, GL_FLOAT, GL_FALSE, sizeof(Pt), (const GLvoid*)offsetof(Pt, PCol));

	gl::enable(GL_PROGRAM_POINT_SIZE);
}
void ShadowMappingBasic::draw()
{
	renderDepthFbo();

	gl::clear( Color::black() );
	gl::setMatrices( mCam );

	gl::ScopedTextureBind texScope( mShadowMapTex, (uint8_t) 0 );

	vec3 mvLightPos	= vec3( gl::getModelView() * vec4( mLightPos, 1.0f ) ) ;
	mat4 shadowMatrix = mLightCam.getProjectionMatrix() * mLightCam.getViewMatrix();

	mGlsl->uniform( "uShadowMap", 0 );
	mGlsl->uniform( "uLightPos", mvLightPos );
	mGlsl->uniform( "uShadowMatrix", shadowMatrix );
	
	drawScene( false );
}
void HighDynamicRangeApp::draw()
{
	gl::clear( Color( 0, 0, 0 ) );

	gl::ScopedGlslProg shaderScp( mShader );
	gl::ScopedTextureBind texBindScp( mHdrTexture );
	mShader->uniform( "uExposure", mExposure );
	gl::drawSolidRect( mHdrTexture->getBounds() );
}
void SlingshotSmokeApp::setup()
{
	mVolumeMult = 5.0;

	mLastTime = 0;

	getWindowIndex(0)->getSignalDraw().connect([=]() { drawRender(); });

	mAudioSource = AudioSource();
	mAudioSource.setup();

	vec2 fluidResolution = vec2(512);
	vec2 smokeResolution = app::getWindowSize();

	mFluid = Fluid(fluidResolution);
	mSmokers.reserve(2);
	mSmokers.push_back(shared_ptr<FakeSmoker>(new FakeSmoker(fluidResolution, smokeResolution)));
	mSmokers.push_back(shared_ptr<PositionSmoker>(new PositionSmoker(fluidResolution, smokeResolution)));
	mSmokers.push_back(shared_ptr<TransitionSmoker>(new TransitionSmoker(fluidResolution, smokeResolution)));
	mSmokers.push_back(shared_ptr<BottomSmoker>(new BottomSmoker(fluidResolution, smokeResolution)));
	mCurrentSmoker = 0;

	mSmokers[mCurrentSmoker]->light(vec2(0.5, 0.2), mParams);


	gl::GlslProg::Format renderFormat;
	renderFormat.vertex(app::loadAsset("passthru.vert"));
	renderFormat.fragment(app::loadAsset("Smokers/smoke_draw.frag"));
	mRenderProg = gl::GlslProg::create(renderFormat);
	mRenderProg->uniform("i_resolution", smokeResolution);

	gl::Texture2d::Format texFmt;
	texFmt.setInternalFormat(GL_RGBA32F);
	texFmt.setDataType(GL_FLOAT);
	texFmt.setTarget(GL_TEXTURE_2D);
	texFmt.setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
	gl::Fbo::Format fmt;
	fmt.disableDepth()
		.setColorTextureFormat(texFmt);
	mSmokeField = PingPongFBO(fmt, smokeResolution, 4);


	// Do params last so that all the FBOs are in the right context
	vec2 paramsSize = vec2(255, 512);
	auto format = Window::Format();
	format.setSize(paramsSize + vec2(40, 20));
	format.setPos(ivec2(100));
	WindowRef paramsWindow = createWindow(format);
	paramsWindow->getSignalDraw().connect([=]() { drawParams(); });
	mParams = params::InterfaceGl::create(paramsWindow, "Options", paramsSize);

	mParams->addParam("Volume", &mVolumeMult)
		.max(10.0)
		.min(0.0)
		.step(0.1);
}
void NormalMappingBasicApp::draw()
{
	gl::clear();

	gl::setMatrices( mCam );
	gl::ScopedModelMatrix modelScope;
	gl::multModelMatrix( mCubeRotation );
	mGlsl->uniform( "uLightLocViewSpace", vec3( mCam.getViewMatrix() * vec4( mLightPosWorldSpace, 1 )) );
	mBatch->draw();
}
Exemple #28
0
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();
}
Exemple #29
0
void Day44App::update()
{
    lightPos.x = 8.f * cos(theta);
    lightPos.y = 8.f * sin(theta);
    lightPos.z = 2.f * sin(theta * 2);
    
    theta += 0.0523;
    
    eyePos = mCam.getEyePoint();
    
    //VERY NB! CONVERT THE LIGHT'S POSITION TO VIEW SPACE BEFORE SENDING IT TO THE GPU, THIS IS BECAUSE ALL THE CALCULATIONS IN THE SHADERS ARE HAPPENING IN VIEW SPACE!
    
    mGlsl->uniform("uLightPos", vec3( mCam.getViewMatrix() * vec4( lightPos, 1 )));
    mGlsl->uniform("uConstant", 1.f);
    mGlsl->uniform("uLinear", 0.09f);
    mGlsl->uniform("uQuatratic", 0.01f);
    
    cout << lightPos << endl;
    
}
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());
	
}