Example #1
0
void SceneRenderer::render()
{
	reset().clearAll();

	addSceneGraph(world->sceneGraph);
	camera = world->currentCamera;

	gBuffer.create(fbWidth, fbHeight);

	geometryPass().lightPass().outPass();
}
Example #2
0
void DeferredRender::doRender() {
	if(!loaded)
		return;
	
	//std::cout << "geometry" << std::endl;
	geometryPass();
	//backgroundPass();
	//std::cout << "light" << std::endl;
	lightPass();
	//std::cout << "alpha" << std::endl;
	alphaPass();
	// TODO: ajouter pass SSAO, MXAA

	//std::cout << "final" << std::endl;

	renderScreen();
	//throw -1;
}
Example #3
0
void Scene::deferredRendering(RenderTarget * target)
{
    if(target->isEnableClipPlane ())
    {
        glEnable(GL_CLIP_PLANE0);
        glClipPlane(GL_CLIP_PLANE0, target->getClipPlane());
    }
    if(!this->spotLights.empty ())
    {
        this->shadowPassForSpot(spotLights[0],target);
    }
    if(this->directionLight.getIntensity ()>0)
    {
        this->shadowPassDirectional (target);
    }

    geometryPass(target);
    if(target->isEnableClipPlane ())
    {
        glDisable(GL_CLIP_PLANE0);
    }
    glEnable(GL_BLEND);
    glBlendEquation(GL_FUNC_ADD);
    glBlendFunc(GL_ONE, GL_ONE);
    target->getGBuffer ()->BindForReading(bloom_fbo1->buffer ());

    lightPass(target);

    bloom_fbo1->BindForReading (bloom_fbo2);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    pickBright();
    bloom_fbo2->BindForReading (bloom_fbo3);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    gaussianBlur_H (2);
    bloom_fbo3->BindForReading (NULL);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    gaussianBlur_V (2);

    if(target->type () == RenderTarget::TargetType::ON_SCREEN)
    {
        bloom_fbo1->BindForReading (NULL);
    }
    else
    {
        bloom_fbo1->BindForReading (target->resultBuffer ());
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    }

    ShaderProgram * shader =ShaderPool::getInstance ()->get("deffered_simple");
    shader->use ();
    QMatrix4x4 m;
    m.setToIdentity ();
    m_quad->setShaderProgram (shader);
    auto camera =target->camera ();
    shader->setUniformMat4v ("g_MVP_matrix",m.data ());
    shader->setUniform2Float ("g_screen_size",1024,768);
    shader->setUniformInteger ("g_color_map",0);
    shader->setUniformInteger ("g_position_map",1);
    shader->setUniformInteger ("g_normal_map",2);
    if(camera)
    {
        shader->setUniform3Float ("g_eye_position",
                                  camera->pos ().x(),
                                  camera->pos ().y(),
                                  camera->pos ().z());
    }
    m_quad->draw (true);
}
Example #4
0
void MyView::
windowViewRender(std::shared_ptr<tygra::Window> window)
{
	assert(scene_ != nullptr);

	updateBuffers(); //update positions of meshes and light sources

	geometryPass(); //must be done first to write to g-buffer

	glUseProgram(shadowMap_program_);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, shadowMap_fbo_);
	glClear(GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);

	GLuint lightPVLocation = glGetUniformLocation(shadowMap_program_, "lightPV");

	glViewport(0, 0, 1024, 1024);

	int i;
	for (i = 0; i < spotLightCount_; i++){
		//generate shadow maps for spot

		float far = scene_->getCamera().getFarPlaneDistance();
		float near = scene_->getCamera().getNearPlaneDistance();

		glm::vec3 lightPos = scene_->getAllSpotLights()[i].getPosition();
		glm::vec3 lightLookAt = scene_->getAllSpotLights()[i].getDirection() - lightPos;
		float fov = scene_->getAllSpotLights()[i].getConeAngleDegrees();
		glm::mat4 view_xform = glm::lookAt(lightPos, lightLookAt, upDir_);
		glm::mat4 projection = glm::perspective(fov, 1.0f, near, far);

		glm::mat4 lightPV = projection * view_xform;

		glUniformMatrix4fv(lightPVLocation, 1, GL_FALSE, glm::value_ptr(lightPV));

		glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadowMap_tex_, 0, i);

		Mesh mesh;
		for (int i = 0; i < meshes_.size(); i++)
		{
			mesh = meshes_[i];
			glBindVertexArray(mesh.vao);
			glDrawElementsInstanced(GL_TRIANGLES, mesh.element_count, GL_UNSIGNED_INT, 0, mesh.instanceIDs.size());
		}
	}

	glViewport(0, 0, width_, height_);

	ambientPass();
	directionalLightPass(); //must be done after ambient and before point, as the quad vao is bound in ambient pass

	//pointlightPass();

	glCullFace(GL_FRONT);

	//point lights

	//glEnable(GL_DEPTH_TEST);
	//glDepthFunc(GL_GREATER);

	//bind the sphere mesh, used by point and spot lights
	glBindVertexArray(light_sphere_mesh_.vao);
	spotlightPass(); //must be done after point lights, as the sphere vao is bound in point light pass

	//apply SSMAA to the image
	antiAliasingPasses();

	//blit l-buffer to screen
	glBindFramebuffer(GL_READ_FRAMEBUFFER, lbuffer_fbo_);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
	glBlitFramebuffer(0, 0, width_, height_, 0, 0, width_, height_, GL_COLOR_BUFFER_BIT, GL_LINEAR);

}