void InstancedTeapotsApp::draw() { gl::clear( Color::black() ); gl::setMatrices( mCam ); mBatch->drawInstanced( NUM_INSTANCES_X * NUM_INSTANCES_Y ); }
void RandomSpawn::drawParticles() { mBatch_P->getGlslProg()->uniform("ViewDirection", mCamera.getViewDirection()); mBatch_P->getGlslProg()->uniform("LightPosition", vec3(0, 10, 0)); mBatch_P->getGlslProg()->uniform("SpecPow", 4.0f); mBatch_P->getGlslProg()->uniform("SpecStr", 2.0f); mBatch_P->drawInstanced(mPointsParticles.size()); }
void BulletSpheresApp::drawToDepthFbo() { // draw into the depth fbo for shadow casting gl::ScopedFramebuffer bindFbo( mLight->getFbo() ); gl::clear(); gl::ScopedState scopeCull( GL_CULL_FACE, true ); gl::cullFace( GL_FRONT ); gl::ScopedMatrices scopeMat; gl::setMatrices( mLight->getCam() ); gl::viewport( mLight->getFbo()->getSize() ); mShadowSphere->drawInstanced( NUM_PARTICLES-2 ); }
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 InstancedStereoApp::update() { mTime = getElapsedSeconds(); gl::clear(); hmd::ScopedRiftBuffer bind{ mRift }; std::array<mat4, 6> worldToEyeClipMatrices; // Calc clip space conversion matrices for both eyes for( auto eye : mRift->getEyes() ) { gl::ScopedMatrices push; mRift->enableEye( eye ); auto idx = 3 * static_cast<size_t>(eye); worldToEyeClipMatrices.at( idx ) = mRift->getViewMatrix() * mRift->getModelMatrix(); worldToEyeClipMatrices.at( idx + 1 ) = mRift->getProjectionMatrix(); // non-instanced scene gl::lineWidth( 3.0f ); gl::drawCoordinateFrame( 2 ); gl::drawSphere( vec3( mLightWorldPosition ), 0.05f, 36 ); } { gl::ScopedViewport port{ vec2( 0 ), mRift->getFboSize() }; gl::ScopedModelMatrix push; gl::rotate( (float)mTime, vec3( -0.3f, -1.0f, 0.2f ) ); gl::scale( vec3( 0.5f ) ); gl::translate( 0.0f, -0.5f, 0.0f ); auto normalMatrix = glm::transpose( glm::inverse( gl::getModelMatrix() ) ); worldToEyeClipMatrices.at( 2 ) = worldToEyeClipMatrices.at( 5 ) = normalMatrix; mShader->uniform( "uLightPosition", mLightWorldPosition ); mShader->uniform( "uWorldToEyeClipMatrices", worldToEyeClipMatrices.data(), 6 ); mTeapot->drawInstanced( 2 ); } }
void Choreo3DApp::draw() { //gl::clear( ColorA::gray( background ) ); gl::clear(ColorAf(testBK)); //THIS MAY NEED TO BE CLEANED UP vector<std::string> dataVector = {"CCL_JOINT_CCL3_00_skip10.json"}; if( CURRENT_DATA_SET != LOADED_DATA_SET){ // paused = true; // jointList = {}; jointList = ccl::loadMotionCaptureFromJson(getAssetPath(dataVector[CURRENT_DATA_SET])); FRAME_COUNT = 0; TOTAL_FRAMES = jointList[0].jointPositions.size(); //SHOULD PROBABLY PUT A TRY/CATCH HERE std::cout << "total frames: " << TOTAL_FRAMES << ", total joints:"<< jointList.size() << std::endl; gl::VboMeshRef body = gl::VboMesh::create( geom::Sphere().subdivisions( 16 ).radius(4) ); //CREATE A CONTAINER TO STORE THE INITIAL POSITIONS FOR INITIALISING THE JOINTS std::vector<glm::vec3> positions; // CREATE THE SPHERES AT THE INITIAL JOINT LOCATIONS for ( int i = 0; i < jointList.size(); ++i ) { glm::vec3 jointAt = jointList[i].jointPositions[i]; float instanceX = jointAt.x; float instanceY = jointAt.y; float instanceZ = jointAt.z; // float instanceZ = 0; positions.push_back( vec3( instanceX, instanceY, instanceZ)); } //std::cout << "positions: " << positions[0] << std::endl; // create the VBO which will contain per-instance (rather than per-vertex) data mInstanceDataVbo = gl::Vbo::create( GL_ARRAY_BUFFER, positions.size() * sizeof(vec3), positions.data(), GL_DYNAMIC_DRAW ); // we need a geom::BufferLayout to describe this data as mapping to the CUSTOM_0 semantic, and the 1 (rather than 0) as the last param indicates per-instance (rather than per-vertex) geom::BufferLayout instanceDataLayout; instanceDataLayout.append( geom::Attrib::CUSTOM_0, 3, 0, 0, 1 /* per instance */ ); //NOW ADD IT TO THE VBO MESH THAT WE INITIAL CREATED FOR THE BODY / SKELETON body->appendVbo( instanceDataLayout, mInstanceDataVbo ); //FINALLY, BUILD THE BATCH, AND MAP THE CUSTOM_0 ATTRIBUTE TO THE "vInstancePosition" GLSL VERTEX ATTRIBUTE mSphereBatch = gl::Batch::create( body, mGlsl, { { geom::Attrib::CUSTOM_0, "vInstancePosition" } } ); LOADED_DATA_SET = CURRENT_DATA_SET; } gl::setMatrices( mCamera ); if (showGrid)renderScene(); Color( dancerColor[0], dancerColor[1], dancerColor[2] ); //gl::ScopedModelMatrix modelScope; if(markersActive)mSphereBatch->drawInstanced( jointList.size() ); if(skeletonActive)skeleton.renderSkeleton(); if(ribbonsActive)drawRibbons(); if(trailsActive)handTrail.render(dancerColor); }