예제 #1
0
void viewing_session::draw_color_overlay(augs::renderer& renderer, const rgba col) const {
	components::sprite overlay;
	overlay.set(assets::texture_id::BLANK, col);
	overlay.size = camera.smoothed_camera.visible_world_area;

	components::sprite::drawing_input in(renderer.get_triangle_buffer());
	in.camera = camera.smoothed_camera;
	in.renderable_transform = camera.smoothed_camera.transform;

	overlay.draw(in);

	renderer.call_triangles();
	renderer.clear_triangles();
}
예제 #2
0
void light_system::render_all_lights(augs::renderer& output, const std::array<float, 16> projection_matrix, const viewing_step step, std::function<void()> neon_callback) {
	const auto& cosmos = step.cosm;
	const auto dt = step.get_delta();
	const float global_time_seconds = static_cast<float>(step.get_interpolated_total_time_passed_in_seconds());

	ensure_eq(0, output.get_triangle_count());

	output.light_fbo.use();
	glClearColor(0.1f, 0.2f, 0.2f, 1.0f);
	output.clear_current_fbo();
	glClearColor(0.f, 0.f, 0.f, 0.f);

	auto& light_program = *get_resource_manager().find(assets::program_id::LIGHT);
	auto& default_program = *get_resource_manager().find(assets::program_id::DEFAULT);
	light_program.use();

	const auto light_pos_uniform = glGetUniformLocation(light_program.id, "light_pos");
	const auto light_max_distance_uniform = glGetUniformLocation(light_program.id, "max_distance");
	const auto light_attenuation_uniform = glGetUniformLocation(light_program.id, "light_attenuation");
	const auto light_multiply_color_uniform = glGetUniformLocation(light_program.id, "multiply_color");
	const auto projection_matrix_uniform = glGetUniformLocation(light_program.id, "projection_matrix");
	const auto& interp = step.session.systems_audiovisual.get<interpolation_system>();
	const auto& particles = step.session.systems_audiovisual.get<particles_simulation_system>();
	
	const auto& visible_per_layer = step.visible.per_layer;

	std::vector<messages::visibility_information_request> requests;
	std::vector<messages::visibility_information_response> responses;

	glUniformMatrix4fv(projection_matrix_uniform, 1, GL_FALSE, projection_matrix.data());

	for (const auto it : cosmos.get(processing_subjects::WITH_LIGHT)) {
		messages::visibility_information_request request;
		request.eye_transform = it.viewing_transform(interp);
		request.filter = filters::line_of_sight_query();
		request.square_side = it.get<components::light>().max_distance.base_value;
		request.subject = it;

		requests.push_back(request);
	}

	{
		std::vector<messages::line_of_sight_response> dummy;
		visibility_system().respond_to_visibility_information_requests(cosmos, {}, requests, dummy, responses);
	}

	const auto camera_transform = step.camera.transform;
	const auto camera_size = step.camera.visible_world_area;
	const auto camera_offset = -camera_transform.pos + camera_size / 2;

	glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE); glerr;
	for (size_t i = 0; i < responses.size(); ++i) {
		const auto& r = responses[i];
		const auto& light_entity = cosmos[requests[i].subject];
		const auto& light = light_entity.get<components::light>();
		auto& cache = per_entity_cache[light_entity.get_id().pool.indirection_index];

		const float delta = dt.in_seconds();

		light.constant.variation.update_value(rng, cache.all_variation_values[0], delta);
		light.linear.variation.update_value(rng, cache.all_variation_values[1], delta);
		light.quadratic.variation.update_value(rng, cache.all_variation_values[2], delta);
		
		light.wall_constant.variation.update_value(rng, cache.all_variation_values[3], delta);
		light.wall_linear.variation.update_value(rng, cache.all_variation_values[4], delta);
		light.wall_quadratic.variation.update_value(rng, cache.all_variation_values[5], delta);
		
		light.position_variations[0].update_value(rng, cache.all_variation_values[6], delta);
		light.position_variations[1].update_value(rng, cache.all_variation_values[7], delta);

		for (size_t t = 0; t < r.get_num_triangles(); ++t) {
			const auto world_light_tri = r.get_world_triangle(t, requests[i].eye_transform.pos);
			augs::vertex_triangle renderable_light_tri;

			renderable_light_tri.vertices[0].pos = world_light_tri.points[0] + camera_offset;
			renderable_light_tri.vertices[1].pos = world_light_tri.points[1] + camera_offset;
			renderable_light_tri.vertices[2].pos = world_light_tri.points[2] + camera_offset;

			auto considered_color = light.color;
			
			if (considered_color == black) {
				considered_color.set_hsv({ fmod(global_time_seconds / 16.f, 1.f), 1.0, 1.0 });
			}

			renderable_light_tri.vertices[0].color = considered_color;
			renderable_light_tri.vertices[1].color = considered_color;
			renderable_light_tri.vertices[2].color = considered_color;

			output.push_triangle(renderable_light_tri);
		}

		//for (size_t d = 0; d < r.get_num_discontinuities(); ++d) {
		//	const auto world_discontinuity = *r.get_discontinuity(d);
		//	
		//	if (!world_discontinuity.is_boundary) {
		//		vertex_triangle renderable_light_tri;
		//
		//		const float distance_from_light = (requests[i].eye_transform.pos - world_discontinuity.points.first).length();
		//		const float angle = 80.f / ((distance_from_light+0.1f)/50.f);
		//		
		//		//(requests[i].eye_transform.pos - world_discontinuity.points.first).length();
		//
		//		if (world_discontinuity.winding == world_discontinuity.RIGHT) {
		//			renderable_light_tri.vertices[0].pos = world_discontinuity.points.first + camera_offset;
		//			renderable_light_tri.vertices[1].pos = world_discontinuity.points.second + camera_offset;
		//			renderable_light_tri.vertices[2].pos = vec2(world_discontinuity.points.second).rotate(-angle, world_discontinuity.points.first) + camera_offset;
		//		}
		//		else {
		//			renderable_light_tri.vertices[0].pos = world_discontinuity.points.first + camera_offset;
		//			renderable_light_tri.vertices[1].pos = world_discontinuity.points.second + camera_offset;
		//			renderable_light_tri.vertices[2].pos = vec2(world_discontinuity.points.second).rotate(angle, world_discontinuity.points.first) + camera_offset;
		//		}
		//
		//		renderable_light_tri.vertices[0].color = light.color;
		//		renderable_light_tri.vertices[1].color = light.color;
		//		renderable_light_tri.vertices[2].color = light.color;
		//
		//		output.push_triangle(renderable_light_tri);
		//	}
		//}


		vec2 light_displacement = vec2(cache.all_variation_values[6], cache.all_variation_values[7]);

		auto screen_pos = requests[i].eye_transform - camera_transform;
		screen_pos.pos.x += camera_size.x * 0.5f;
		screen_pos.pos.y = camera_size.y - (screen_pos.pos.y + camera_size.y * 0.5f);
		screen_pos += light_displacement;

		glUniform2f(light_pos_uniform, screen_pos.pos.x, screen_pos.pos.y);

		glUniform1f(light_max_distance_uniform, light.max_distance.base_value);
		
		glUniform3f(light_attenuation_uniform,
			cache.all_variation_values[0] + light.constant.base_value,
			cache.all_variation_values[1] + light.linear.base_value,
			cache.all_variation_values[2] + light.quadratic.base_value
		);

		glUniform3f(light_multiply_color_uniform,
			1.f,
			1.f,
			1.f);

		output.call_triangles();
		output.clear_triangles();
		
		light_program.use();

		glUniform1f(light_max_distance_uniform, light.wall_max_distance.base_value);
		
		glUniform3f(light_attenuation_uniform,
			cache.all_variation_values[3] + light.wall_constant.base_value,
			cache.all_variation_values[4] + light.wall_linear.base_value,
			cache.all_variation_values[5] + light.wall_quadratic.base_value
		);
		
		glUniform3f(light_multiply_color_uniform,
			light.color.r/255.f,
			light.color.g/255.f,
			light.color.b/255.f);
		
		render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::DYNAMIC_BODY], step.camera, renderable_drawing_type::NORMAL);

		output.call_triangles();
		output.clear_triangles();

		glUniform3f(light_multiply_color_uniform,
			1.f,
			1.f,
			1.f);
	}

	default_program.use();

	render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::DYNAMIC_BODY], step.camera, renderable_drawing_type::NEON_MAPS);
	render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::SMALL_DYNAMIC_BODY], step.camera, renderable_drawing_type::NEON_MAPS);
	render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::FLYING_BULLETS], step.camera, renderable_drawing_type::NEON_MAPS);
	render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::CAR_INTERIOR], step.camera, renderable_drawing_type::NEON_MAPS);
	render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::CAR_WHEEL], step.camera, renderable_drawing_type::NEON_MAPS);
	render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::EFFECTS], step.camera, renderable_drawing_type::NEON_MAPS);
	render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::ON_GROUND], step.camera, renderable_drawing_type::NEON_MAPS);
	render_system().draw_entities(interp, global_time_seconds,output.triangles, visible_per_layer[render_layer::ON_TILED_FLOOR], step.camera, renderable_drawing_type::NEON_MAPS);

	{
		particles_simulation_system::drawing_input in(output.triangles);
		in.camera = step.camera;
		in.drawing_type = renderable_drawing_type::NEON_MAPS;

		particles.draw(render_layer::EFFECTS, in);
	}

	neon_callback();

	output.call_triangles();
	output.clear_triangles();

	glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); glerr;

	augs::graphics::fbo::use_default();

	output.set_active_texture(2);
	output.bind_texture(output.light_fbo);
	output.set_active_texture(0);
}
예제 #3
0
void viewing_session::view(
	augs::renderer& renderer,
	const cosmos& cosmos,
	const entity_id viewed_character,
	const augs::variable_delta& dt,
	const augs::gui::text::fstr& custom_log,
	const game_drawing_settings settings
	) {
	frame_profiler.new_measurement();

	const auto screen_size = camera.smoothed_camera.visible_world_area;
	const vec2i screen_size_i(static_cast<int>(screen_size.x), static_cast<int>(screen_size.y));

	renderer.set_viewport({ viewport_coordinates.x, viewport_coordinates.y, screen_size_i.x, screen_size_i.y });

	const auto character_chased_by_camera = cosmos[viewed_character];

	camera.tick(systems_audiovisual.get<interpolation_system>(), dt, character_chased_by_camera);
	world_hover_highlighter.cycle_duration_ms = 700;
	world_hover_highlighter.update(dt.in_milliseconds());

	const auto visible = visible_entities(camera.smoothed_camera, cosmos);

	auto main_cosmos_viewing_step = viewing_step(
		cosmos, 
		*this, 
		dt, 
		renderer, 
		camera.smoothed_camera, 
		character_chased_by_camera,
		visible
	);

	main_cosmos_viewing_step.settings = settings;

#if NDEBUG || _DEBUG
	rendering_scripts::illuminated_rendering(main_cosmos_viewing_step);
#else
	rendering_scripts::illuminated_rendering(main_cosmos_viewing_step);
#endif

	using namespace augs::gui::text;

	if (show_profile_details) {
		const auto coords = character_chased_by_camera.alive() ? character_chased_by_camera.logic_transform().pos : vec2();
		const auto rot = character_chased_by_camera.alive() ? character_chased_by_camera.logic_transform().rotation : 0.f;
		const auto vel = character_chased_by_camera.alive() ? character_chased_by_camera.get<components::physics>().velocity() : vec2();

		const auto bbox = quick_print_format(renderer.triangles, typesafe_sprintf(L"Entities: %x\nX: %f2\nY: %f2\nRot: %f2\nVelX: %x\nVelY: %x\n", cosmos.entities_count(), coords.x, coords.y, rot, vel.x, vel.y)
			+ summary() + cosmos.profiler.sorted_summary(show_profile_details), style(assets::font_id::GUI_FONT, rgba(255, 255, 255, 150)), vec2i(0, 0), 0);

		quick_print(renderer.triangles, multiply_alpha(global_log::format_recent_as_text(assets::font_id::GUI_FONT), 150.f / 255), vec2i(screen_size_i.x - 300, 0), 300);
		quick_print(renderer.triangles, custom_log, vec2i(0, static_cast<int>(bbox.y)), 0);
	}
		
	renderer.call_triangles();
	renderer.clear_triangles();

	triangles.measure(static_cast<double>(renderer.triangles_drawn_total));
	renderer.triangles_drawn_total = 0;

	fps_profiler.end_measurement();
	fps_profiler.new_measurement();
	frame_profiler.end_measurement();
}