Ejemplo n.º 1
0
void BloomPass::run(GraphicContext &gc)
{
    final_color->set_min_filter(filter_linear);
    final_color->set_mag_filter(filter_linear);

    ScopeTimeFunction();
    setup_bloom_extract(gc);
    gc.set_frame_buffer(fb_bloom_extract);
    gc.set_viewport(bloom_contribution->get_size());
    gc.set_texture(0, final_color.get());
    gc.set_blend_state(blend_state);
    gc.set_program_object(bloom_shader);
    gc.draw_primitives(type_triangles, 6, rect_primarray);
    gc.reset_program_object();
    gc.reset_texture(0);
    gc.reset_frame_buffer();

    bloom_blur.blur(gc, tf_rgba8, 4.0f, 15);
}
Ejemplo n.º 2
0
std::string ScopeTimerResults::timer_results()
{
	ScopeTimeFunction();
	std::map<const char *, bool> result_names;
	for (size_t i = 0; i < instance.results.size(); i++)
		result_names[instance.results[i].name] = true;

	std::string final_results;
	for (std::map<const char *, bool>::iterator it = result_names.begin(); it != result_names.end(); ++it)
	{
		int time_spent = percentage(it->first);
		if (time_spent > 0)
		{
			if (!final_results.empty())
				final_results += "\n";
			final_results += string_format("%1: %2%%", it->first, time_spent);
		}
	}
	return final_results;
}
Ejemplo n.º 3
0
void LightsourceSimplePass::render(GraphicContext &gc, GPUTimer &timer)
{
	ScopeTimeFunction();

	//timer.begin_time(gc, "light(simple)");

	gc.set_frame_buffer(fb);

	gc.set_viewport(viewport->get_size());

	gc.set_depth_range(0.0f, 0.9f);

	gc.set_uniform_buffer(0, uniforms);
	gc.set_texture(0, light_instance_texture);
	gc.set_texture(1, normal_z_gbuffer.get());
	gc.set_texture(2, diffuse_color_gbuffer.get());
	gc.set_texture(3, specular_color_gbuffer.get());
	gc.set_texture(4, specular_level_gbuffer.get());
	gc.set_texture(5, shadow_maps.get());
	gc.set_texture(6, self_illumination_gbuffer.get());

	gc.set_blend_state(blend_state);

	gc.clear();

	// To do: use icosahedron for smaller lights and when the camera is not inside the light influence sphere
	// To do: combine multiple lights into the same rect pass to reduce overdraw penalty

	gc.set_depth_stencil_state(rect_depth_stencil_state);
	gc.set_rasterizer_state(rect_rasterizer_state);
	gc.set_program_object(rect_light_program);

	gc.set_primitives_array(rect_prim_array);
	gc.draw_primitives_array_instanced(type_triangles, 0, 6, std::max(lights.size(), (size_t)1));
	gc.reset_primitives_array();

/*
	gc.set_depth_stencil_state(icosahedron_depth_stencil_state);
	gc.set_rasterizer_state(icosahedron_rasterizer_state);
	gc.set_program_object(icosahedron_light_program);

	gc.set_primitives_array(icosahedron_prim_array);
	gc.draw_primitives_elements_instanced(type_triangles, icosahedron->num_elements, icosahedron->elements, 0, lights.size());
	gc.reset_primitives_array();
*/

	gc.set_depth_stencil_state(icosahedron_depth_stencil_state);
	gc.set_rasterizer_state(icosahedron_rasterizer_state);
	gc.set_program_object(icosahedron_light_program);

	gc.set_primitives_array(icosahedron_prim_array);
	gc.draw_primitives_elements_instanced(type_triangles, icosahedron->num_elements, icosahedron->elements, 0, lights.size());
	gc.reset_primitives_array();

	//timer.end_time(gc);
	//timer.begin_time(gc, "light(simple)");

	gc.reset_texture(6);
	gc.reset_texture(5);
	gc.reset_texture(4);
	gc.reset_texture(3);
	gc.reset_texture(2);
	gc.reset_texture(1);
	gc.reset_texture(0);
	gc.reset_uniform_buffer(0);

	//timer.end_time(gc);
}
Ejemplo n.º 4
0
void LightsourceSimplePass::upload(GraphicContext &gc, Scene_Impl *scene)
{
	ScopeTimeFunction();

	Size viewport_size = viewport->get_size();
	Mat4f eye_to_projection = Mat4f::perspective(field_of_view.get(), viewport_size.width/(float)viewport_size.height, 0.1f, 1.e4f, handed_left, gc.get_clip_z_range());

	float aspect = viewport->get_width()/(float)viewport->get_height();
	float field_of_view_y_degrees = field_of_view.get();
	float field_of_view_y_rad = (float)(field_of_view_y_degrees * PI / 180.0);
	float f = 1.0f / tan(field_of_view_y_rad * 0.5f);
	float rcp_f = 1.0f / f;
	float rcp_f_div_aspect = 1.0f / (f / aspect);
	Vec2f two_rcp_viewport_size(2.0f / viewport->get_width(), 2.0f / viewport->get_height());

	Uniforms cpu_uniforms;
	cpu_uniforms.eye_to_projection = eye_to_projection;
	cpu_uniforms.object_to_eye = Quaternionf::inverse(scene->get_camera().get_orientation()).to_matrix();
	cpu_uniforms.rcp_f = rcp_f;
	cpu_uniforms.rcp_f_div_aspect = rcp_f_div_aspect;
	cpu_uniforms.two_rcp_viewport_size = two_rcp_viewport_size;
	uniforms.upload_data(gc, &cpu_uniforms, 1);

	int num_lights = lights.size();

	Mat4f normal_world_to_eye = Mat4f(Mat3f(world_to_eye.get())); // This assumes uniform scale
	Mat4f eye_to_world = Mat4f::inverse(world_to_eye.get());

	PixelBufferLock4f lock(light_instance_transfer);
	Vec4f *instance_data = lock.get_row(0);

	for (int i = 0; i < num_lights; i++)
	{
		float radius = lights[i]->attenuation_end;
		if (lights[i]->rectangle_shape)
			radius *= 1.414213562373f;

		float attenuation_delta = lights[i]->attenuation_end - lights[i]->attenuation_start;
		if (attenuation_delta == 0.0f)
			attenuation_delta = 1e-6f;
		float sqr_radius = radius * radius;
#ifdef USE_QUADRATIC_ATTENUATION
		float sqr_attenuation_start = lights[i]->attenuation_start * lights[i]->attenuation_start;
		float sqr_attenuation_delta = attenuation_delta * attenuation_delta;
#else
		float attenuation_start = lights[i]->attenuation_start;
#endif
		float sqr_falloff_begin = 0.0f;
		float light_type = 0.0f;
		if (lights[i]->type == SceneLight::type_spot)
		{
			light_type = lights[i]->rectangle_shape ? 2.0f : 1.0f;
			float falloff_begin = lights[i]->hotspot / lights[i]->falloff;
			sqr_falloff_begin = falloff_begin * falloff_begin;
		}
		Vec3f position_in_eye = Vec3f(world_to_eye.get() * Vec4f(lights[i]->position, 1.0f));
		Mat4f eye_to_shadow_projection = lights[i]->vsm_data->world_to_shadow_projection * eye_to_world;

		int shadow_map_index = lights[i]->vsm_data->shadow_map.get_index();

		instance_data[i * vectors_per_light + 0] = Vec4f(position_in_eye, (float)shadow_map_index);
		instance_data[i * vectors_per_light + 1] = Vec4f(lights[i]->color, lights[i]->ambient_illumination);
#ifdef USE_QUADRATIC_ATTENUATION
		instance_data[i * vectors_per_light + 2] = Vec4f(sqr_radius, sqr_attenuation_start, 1.0f / sqr_attenuation_delta, sqr_falloff_begin);
#else
		instance_data[i * vectors_per_light + 2] = Vec4f(sqr_radius, attenuation_start, 1.0f / attenuation_delta, sqr_falloff_begin);
#endif
		instance_data[i * vectors_per_light + 3] = Vec4f(eye_to_shadow_projection[0], eye_to_shadow_projection[4], eye_to_shadow_projection[8], light_type);
		instance_data[i * vectors_per_light + 4] = Vec4f(eye_to_shadow_projection[1], eye_to_shadow_projection[5], eye_to_shadow_projection[9], 0.0f);
		instance_data[i * vectors_per_light + 5] = Vec4f(eye_to_shadow_projection[2], eye_to_shadow_projection[6], eye_to_shadow_projection[10], 0.0f);
	}

	instance_data[num_lights * vectors_per_light + 0] = Vec4f(0.0f);
	instance_data[num_lights * vectors_per_light + 1] = Vec4f(0.0f);
	instance_data[num_lights * vectors_per_light + 2] = Vec4f(0.0f);
	instance_data[num_lights * vectors_per_light + 3] = Vec4f(0.0f);
	instance_data[num_lights * vectors_per_light + 4] = Vec4f(0.0f);
	instance_data[num_lights * vectors_per_light + 5] = Vec4f(0.0f);

	lock.unlock();

	light_instance_texture.set_image(gc, light_instance_transfer);
}