void MarineSnow::draw(const ofCamera& cam)
 {
     // putting this here otherwise isn't working in VSE
     tex.bind();
     glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
     tex.unbind();
     
     ofPushStyle();
     glPushAttrib(GL_ENABLE_BIT);
     glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
     glEnable(GL_POINT_SPRITE);
     ofEnableAlphaBlending();
     shader.begin();
     shader.setUniform1f("innerFogStart", innerFogStart);
     shader.setUniform1f("innerFogEnd", innerFogEnd);
     shader.setUniform1f("fogStart", fogStart);
     shader.setUniform1f("fogEnd", fogEnd);
     shader.setUniform1f("nearClip", cam.getNearClip());
     shader.setUniform1f("camZ", cam.getPosition().z);
     shader.setUniform1f("time", ofGetElapsedTimef());
     shader.setUniform1f("yMin", yMin);
     shader.setUniform1f("yRange", yMax - yMin);
     shader.setUniformTexture("tex", tex, 1);
     mesh.draw();
     shader.end();
     glPopAttrib();
     ofPopStyle();
 }
Пример #2
0
        //--------------------------------------------------------------
        void ClusterGrid::setup(const ofCamera & camera)
        {
			this->clear();

			this->projInfo.fov = ofDegToRad(camera.getFov());
			this->projInfo.aspectRatio = camera.getAspectRatio();
			this->projInfo.nearZ = camera.getNearClip();
			this->projInfo.farZ = camera.getFarClip();

            memset(this->culledPointLightIndices, 0, sizeof(this->culledPointLightIndices[0]) * MAX_POINT_LIGHTS);
            this->numCulledLightIndices = 0;

            memset(this->lightIndices, 0, sizeof(this->lightIndices[0]) * MAX_CLUSTERED_LIGHTS);
            memset(this->lightSortKeys, 0, sizeof(this->lightSortKeys[0]) * MAX_CLUSTERED_LIGHTS);
            memset(this->tempLightSortKeys, 0, sizeof(this->tempLightSortKeys[0]) * MAX_CLUSTERED_LIGHTS);
            memset(this->tempLightIndices, 0, sizeof(this->tempLightIndices[0]) * MAX_CLUSTERED_LIGHTS);

            memset(this->clusterLightPointerList, 0, sizeof(this->clusterLightPointerList[0]) * NUM_CLUSTERS);

            this->createLightIndexTextures();

            this->planesX = new util::Plane[NUM_PLANES_X];
            this->planesY = new util::Plane[NUM_PLANES_Y];
            this->planesZ = new util::Plane[NUM_PLANES_Z];

            this->createPlanes();
        }
Пример #3
0
        //--------------------------------------------------------------
        void ViewUbo::update(const ofCamera & camera)
        {
            const auto bounds = ofGetCurrentViewport();
            this->data.viewportSize = glm::vec2(bounds.width, bounds.height);
            this->data.rcpViewportSize = 1.0f / this->data.viewportSize;
            this->data.nearClip = camera.getNearClip();
            this->data.farClip = camera.getFarClip();
			this->data.viewMatrix = camera.getModelViewMatrix();
            this->data.inverseViewMatrix = glm::inverse(this->data.viewMatrix);

            this->ubo.updateData(sizeof(Data), &this->data);
        }
Пример #4
0
void SecondCamera::setFromOtherCamera(ofCamera& other)
{
	setFarClip(other.getFarClip());
	setNearClip(other.getNearClip());
	setFov(other.getFov());
	
	matProjection = other.getProjectionMatrix();
	matModelView = other.getModelViewMatrix();
	
	matModelView.postMultTranslate(-_offset);
	
	isActive = true;
}
 void Creature::draw(const ofCamera& cam)
 {
     ofPushMatrix();
     if (cam.getPosition().z - getPosition().z > Creature::fogEnd)
     {
         ofTranslate(0, 0, Creature::fogEnd * floor((cam.getPosition().z - getPosition().z) / Creature::fogEnd));
     }
     else if (getPosition().z > cam.getPosition().z)
     {
         ofTranslate(0, 0, -Creature::fogEnd * ceil((getPosition().z - cam.getPosition().z) / Creature::fogEnd));
     }
     ofMultMatrix(getGlobalTransformMatrix());
     customDraw();
     ofPopMatrix();
 }
Пример #6
0
void PostProcController::endDraw(ofCamera& cam) {
  if (_params.enabled()) {
    _postProc.end();
  } else {
    cam.end();
  }
}
Пример #7
0
void PostProcController::beginDraw(ofCamera &cam) {
  if (_params.enabled()) {
    _postProc.begin(cam);
  } else {
    cam.begin();
  }
}
Пример #8
0
void ParticleSystem::depthSort(ofCamera& cam)
{
        /* depth sorting */
	list< pair<int, float> > depthList;

	// put indexed points and z-values into the list
	for(unsigned int i = 0; i < particles.size(); i++) {
		depthList.push_back( make_pair(i, ofVec3f(particles[i].pos - cam.getPosition()).length() ));
	}

	// sort the list
	depthList.sort(DepthSortPredicate);

	std::list<pair<int, float> >::iterator it;
	int j = 0;
    for(it = depthList.begin(); it != depthList.end(); it++) {

	int i = it->first;
        billboards.getVertices()[j] = particles[i].pos;
        billboards.getColors()[j] = particles[i].colour;
        billboards.setNormal(j,ofVec3f(particles[i].scale,spriteSheetWidth,particles[i].spriteCount));
        rotations[j] = particles[i].rotation;

        if(particles[i].animSpeed > 0) {
            if((int)particles[i].age % particles[i].animSpeed == 0) particles[i].spriteCount++;
            if(particles[i].spriteCount >= totalSprites) particles[i].spriteCount = 0;
        }

		j++;
	}

}
Пример #9
0
void lb::LightSystem::Update( const ofCamera& _camera )
{
    m_clusterGrid.CullPointLights( _camera.getModelViewMatrix(), m_pointLights );
    m_clusterGrid.SortLightIndexList();
    m_clusterGrid.UpdateLightIndexTextures();

    UpdateUbo();
}
Пример #10
0
void lb::LightSystem::Update( const ofCamera& _camera )
{
    // updateData() will use direct state access (DSA) on GL 4.5, faster than map?
    m_pointLightUbo.updateData( m_pointLights.size() * sizeof( lb::PointLight ), m_pointLights.data() );

    m_clusterGrid.CullPointLights( _camera.getModelViewMatrix(), m_pointLights );
    m_clusterGrid.SortLightIndexList();
    m_clusterGrid.UpdateLightIndexTextures();
}
Пример #11
0
 void PostProcessing::begin(ofCamera& cam)
 {
     // update camera matrices
     cam.begin();
     cam.end();
     
     raw.begin(false);
     
     glMatrixMode(GL_PROJECTION);
     glPushMatrix();
     glLoadMatrixf(cam.getProjectionMatrix(ofRectangle(0, 0, width, height)).getPtr());
     
     glMatrixMode(GL_MODELVIEW);
     glPushMatrix();
     glLoadMatrixf(cam.getModelViewMatrix().getPtr());
     
     glViewport(0, 0, raw.getWidth(), raw.getHeight());
     
     glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
 }
Пример #12
0
void BlobMask::updateWith(ofCamera & camera){
	for(auto & sphere: blob){
		sphere.radius = ofNoise(sphere.pos.x, sphere.pos.y, sphere.pos.z, ofGetElapsedTimef() * 0.5) * this->radius;
	}

	ofEnableDepthTest();
	minMaxDepthShader.begin();

	minDepthFbo.begin();
	minDepthFbo.clearDepthBuffer(0.f);
	glDepthFunc(GL_GREATER);
	camera.begin();
	for(auto & sphere: blob){
		ofDrawSphere(sphere.pos, sphere.radius);
	}
	camera.end();
	minDepthFbo.end();


	maxDepthFbo.begin();
	maxDepthFbo.clearDepthBuffer(1.f);
	glDepthFunc(GL_LESS);
	camera.begin();
	for(auto & sphere: blob){
		ofDrawSphere(sphere.pos, sphere.radius);
	}
	camera.end();
	maxDepthFbo.end();

	minMaxDepthShader.end();
	ofDisableDepthTest();


	/*ofEnableDepthTest();
	camera.begin();
	for(auto & sphere: blob){
		ofDrawSphere(sphere.pos, sphere.radius);
	}
	camera.end();
	ofDisableDepthTest();*/
}
Пример #13
0
void lb::LightSystem::Init( const ofCamera& _camera )
{
    lb::ProjInfo projInfo;
    projInfo.fov = ofDegToRad( _camera.getFov() );
    projInfo.aspectRatio = _camera.getAspectRatio();
    projInfo.nearZ = _camera.getNearClip();
    projInfo.farZ = _camera.getFarClip();

    m_pointLights.reserve( lb::ClusterGrid::MAX_POINT_LIGHTS );

    m_clusterGrid.Init( projInfo );
    m_clusterGridDebug.CreateClusterMesh( m_clusterGrid, projInfo );

    // Create point light uniform buffer
    m_pointLightUbo.allocate( lb::ClusterGrid::MAX_POINT_LIGHTS * sizeof( lb::PointLight ), nullptr, GL_DYNAMIC_DRAW );
    assert( true == m_pointLightUbo.isAllocated() );

    m_debugSphere = ofSpherePrimitive( 1.0f, 8 );

    m_pointLights.clear();
}
Пример #14
0
 void PostProcessing::begin(ofCamera& cam)
 {
     // update camera matrices
     cam.begin();
     cam.end();
     
     raw.begin(ofFboBeginMode::NoDefaults);
     
     ofMatrixMode(OF_MATRIX_PROJECTION);
     ofPushMatrix();
     ofLoadMatrix(cam.getProjectionMatrix(ofRectangle(0, 0, width, height)));
     
     ofMatrixMode(OF_MATRIX_MODELVIEW);
     ofPushMatrix();
     ofLoadMatrix(cam.getModelViewMatrix());
     
     ofViewport(0, 0, raw.getWidth(), raw.getHeight());
     
     glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
     
     ofPushStyle();
     glPushAttrib(GL_ENABLE_BIT);
 }
Пример #15
0
void lb::LightSystem::Init( const ofCamera& _camera )
{
    lb::ProjInfo projInfo;
    projInfo.fov = ofDegToRad( _camera.getFov() );
    projInfo.aspectRatio = _camera.getAspectRatio();
    projInfo.nearZ = _camera.getNearClip();
    projInfo.farZ = _camera.getFarClip();

    m_directionalLights.reserve( skMaxDirectionalLights );
    m_pointLights.reserve( skMaxPointLights );

    m_clusterGrid.Init( projInfo );
    m_clusterGridDebug.CreateClusterMesh( m_clusterGrid, projInfo );

    // Create point light uniform buffer
    size_t numBytes = sizeof( LightUbo );
    ofLogNotice() << numBytes << endl;
    m_pointLightUbo.allocate( numBytes, nullptr, GL_DYNAMIC_DRAW );
    assert( true == m_pointLightUbo.isAllocated() );

    m_debugSphere = ofSpherePrimitive( 1.0f, 8 );

    m_pointLights.clear();
}
Пример #16
0
 void Creatures::draw(const ofCamera& cam)
 {
     glPushAttrib(GL_ENABLE_BIT);
     ofEnableDepthTest();
     
     // draw all creatures except point creatures
     for (unsigned i = 0; i < creaturesByType.size(); ++i)
     {
         if (!creaturesByType[i].empty() && creaturesByType[i][0]->getType() == Creature::POINT) break;
         
         for (unsigned j = 0; j < creaturesByType[i].size(); ++j)
         {
             creaturesByType[i][j]->draw(cam);
         }
     }
     
     // tentacles
     ofPushStyle();
     ofEnableBlendMode(OF_BLENDMODE_ADD);
     glDepthMask(GL_FALSE);
     ofSetColor(255);
     tentacles.getDrawShaderRef().begin();
     tentacles.getDrawShaderRef().setUniform1f("fogStart", Creature::fogStart);
     tentacles.getDrawShaderRef().setUniform1f("fogEnd", Creature::fogEnd);
     tentacles.getDrawShaderRef().setUniform1f("camZ", cam.getZ());
     tentacles.getDrawShaderRef().end();
     tentacles.draw();
     glDepthMask(GL_TRUE);
     ofDisableBlendMode();
     ofPopStyle();
     
     
     // point creatures
     pointCreatureMesh.draw();
     
     /*
     for (int i = 0; i < creatures.size(); ++i)
     {
         creatures[i]->draw();
     }*/
     glPopAttrib();
 }