コード例 #1
0
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();
    

    
}
コード例 #2
0
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);
    
}
コード例 #3
0
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 );
}
コード例 #4
0
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() );
    }
}
コード例 #5
0
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();
}
コード例 #6
0
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 ) );
    */
}
コード例 #7
0
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 ) );
			}
		}
	}
}
コード例 #8
0
ファイル: BayBridgeApp.cpp プロジェクト: SethGibson/BayBridge
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));
}
コード例 #9
0
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
}
コード例 #10
0
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();
}
コード例 #11
0
ファイル: BayBridgeApp.cpp プロジェクト: SethGibson/BayBridge
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);
}
コード例 #12
0
ファイル: Day41App.cpp プロジェクト: Craigson/100days
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);


}
コード例 #13
0
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();
}
コード例 #14
0
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() );
}
コード例 #15
0
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();
	}
}
コード例 #16
0
ファイル: GeometryApp.cpp プロジェクト: Ahbee/Cinder
void GeometryApp::resize()
{
	mCamera.setAspectRatio( getWindowAspectRatio() );

	if( mWireframeShader )
		mWireframeShader->uniform( "uViewportSize", vec2( getWindowSize() ) );
}
コード例 #17
0
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;
	}
}
コード例 #18
0
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);
}
コード例 #19
0
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() );
}
コード例 #20
0
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 );
}
コード例 #21
0
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);
}
コード例 #22
0
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();
}
コード例 #23
0
ファイル: Day44App.cpp プロジェクト: Craigson/100days
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;
    
}
コード例 #24
0
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());
	
}
コード例 #25
0
void SpiderWebApp::setupGlsl()
{
	// These are the names of our out going vertices. GlslProg needs to
	// know which attributes should be captured by Transform FeedBack.
	std::vector<std::string> feedbackVaryings({
		"tf_position_mass",
		"tf_velocity"
	});
	
	gl::GlslProg::Format updateFormat;
	updateFormat.vertex( loadAsset( "update.vert" ) )
				// Because we have separate buffers with which
				// to capture attributes, we're using GL_SEPERATE_ATTRIBS
				.feedbackFormat( GL_SEPARATE_ATTRIBS )
				// We also send the names of the attributes to capture
				.feedbackVaryings( feedbackVaryings );
	
	mUpdateGlsl = gl::GlslProg::create( updateFormat );
	// Set this, otherwise it will be set to vec3( 0, 0, 0 ),
	// which is in the center of the cloth
	mUpdateGlsl->uniform( "rayPosition", vec3( 0 ) );
	mUpdateGlsl->uniform( "gravity", vec3(0, 0.08f, 0) );
//	mUpdateGlsl->uniform( "rest_length", 20.0 );
	mUpdateGlsl->uniform( "c", mOptions->getDamping() );
	mUpdateGlsl->uniform( "k", mOptions->getSpringConstant() );
	mUpdateGlsl->uniform( "tension", mOptions->getTension() );
	mUpdateGlsl->uniform( "t", mOptions->getTimestep() );
	
	gl::GlslProg::Format renderFormat;
	renderFormat.vertex( loadAsset( "render.vert" ) )
				.fragment( loadAsset( "render.frag" ) );
	
	mRenderGlsl = gl::GlslProg::create( renderFormat );
}
コード例 #26
0
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();
}
コード例 #27
0
ファイル: ITA_ForcesApp.cpp プロジェクト: SethGibson/ITA
void ITA_ForcesApp::update()
{
	if (!mMouseInput)
	{
		if (mIsRunning)
			updateRS();
	}
	else
		mNumInputs = 1.0f;

	if (mIdle)
		mForceMode *= mParamDamping;
	mId = 1 - mId;

	gl::ScopedGlslProg tfShader(mShaderTF);
	//mShaderTF->uniform("u_ForcePos", vec3(mMousePos.x, mMousePos.y, 0.0f));
	mShaderTF->uniform("u_ForcePos", mMousePos.data(), 2);
	mShaderTF->uniform("u_Count", mNumInputs);
	mShaderTF->uniform("u_ForceScale", mForceMode);
	mShaderTF->uniform("u_Radius", P_RADIUS);
	mShaderTF->uniform("u_MagScale", P_MAG);
	mShaderTF->uniform("u_Damping", P_DAMP);
	mShaderTF->uniform("u_Bounds", vec2(getWindowSize()));

	gl::ScopedVao tfVao(mVao[mId]);
	gl::ScopedState tfState(GL_RASTERIZER_DISCARD, true);

	mTfo[1 - mId]->bind();
	gl::beginTransformFeedback(GL_POINTS);
	gl::drawArrays(GL_POINTS, 0, NUM_PTS.x*NUM_PTS.y);
	gl::endTransformFeedback();
}
コード例 #28
0
ファイル: TessellationBasicApp.cpp プロジェクト: Ahbee/Cinder
void TessellationShaderApp::draw()
{
	gl::clear();
#if ! defined( CINDER_GL_ES )
	gl::enableWireframe();
#endif
	
	gl::setMatricesWindow( getWindowSize() );
	gl::translate( getWindowCenter() );
	
	gl::ScopedGlslProg glslProg( mGlsl );
	mGlsl->uniform( "uTessLevelInner", (float)mTessLevelInner );
	mGlsl->uniform( "uTessLevelOuter", (float)mTessLevelOuter );
	mGlsl->uniform( "uRadius", mRadius );	
	
	mBatch->draw();

#if ! defined( CINDER_GL_ES )
	gl::disableWireframe();
	mParams->draw();
#endif
}
コード例 #29
0
void PointCloudVAO::drawCloud()
{
	gl::enableDepthRead();
	gl::setMatrices(mSceneView);

	mShader->uniform("u_PointSize", mParamPointSize);
	gl::ScopedVao vao(mVao);
	gl::ScopedGlslProg glsl(mShader);

	gl::context()->setDefaultShaderVars();
	gl::drawArrays(GL_POINTS, 0, mPoints.size());
	gl::disableDepthRead();
}
コード例 #30
0
void FragmentShaderToyApp::setup()
{
	// load fragment shader from the provided path
	// we always use the same vertex shader, so it isn't specified
	loadShader(getAssetPath("default.fs"));
	string pathToStartupFile = (getAssetPath("") / "startup.jpg").string();
	if (fs::exists(pathToStartupFile))
	{
		texture = gl::Texture::create(loadImage(loadAsset("startup.jpg")));
	}
	// create a rectangle to be drawn with our shader program
	// default is from -0.5 to 0.5, so we scale by 2 to get -1.0 to 1.0
	mMesh = gl::VboMesh::create(geom::Rect());// .scale(vec2(2.0f, 2.0f)));

	// load a new shader on file drop
	getWindow()->getSignalFileDrop().connect([this](FileDropEvent &event)
	{
		auto file = event.getFile(0);
		if (fs::is_regular_file(file));
		{ loadShader(file); }
	});
	// set iMouse XY on mouse move
	getWindow()->getSignalMouseMove().connect([this](MouseEvent &event)
	{
		mMouseCoord.x = event.getX();
		mMouseCoord.y = getWindowHeight() - event.getY();
	});
	// set iMouse ZW on mouse down
	getWindow()->getSignalMouseDown().connect([this](MouseEvent &event)
	{
		mMouseCoord.z = event.getX();
		mMouseCoord.w = getWindowHeight() - event.getY();
	});
	// reload last fragment shader on keypress, or save frame if key == 's'
	getWindow()->getSignalKeyDown().connect([this](KeyEvent &event)
	{
		if (event.getCode() == KeyEvent::KEY_s)
		{
			mDoSave = true;
		}
		else
		{
			loadShader(mCurrentShaderPath);
		}
	});
	// set shader resolution uniform on resize (if shader has that uniform)
	getWindow()->getSignalResize().connect([this]()
	{
			mProg->uniform("iResolution", vec3(getWindowWidth(), getWindowHeight(), 0.0f));
	});
}