예제 #1
0
void LightsourcePass::render(const GraphicContextPtr &gc, GPUTimer &timer)
{
	ScopeTimeFunction();

	zminmax.viewport = inout.viewport;
	zminmax.normal_z = inout.normal_z_gbuffer;
	zminmax.minmax(gc);
	update_buffers(gc);

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

	gc->set_uniform_buffer(0, compute_uniforms);
	gc->set_storage_buffer(0, compute_lights);
	gc->set_storage_buffer(1, compute_visible_lights);
	gc->set_texture(0, zminmax.result);
	gc->set_texture(1, inout.normal_z_gbuffer);
	gc->set_texture(2, inout.diffuse_color_gbuffer);
	gc->set_texture(3, inout.specular_color_gbuffer);
	gc->set_texture(4, inout.specular_level_gbuffer);
	gc->set_texture(5, inout.shadow_maps);
	gc->set_texture(6, inout.self_illumination_gbuffer);
	gc->set_image_texture(0, inout.final_color);

	gc->set_program_object(cull_tiles_program);
	gc->dispatch((num_tiles_x + tile_size - 1) / tile_size, (num_tiles_y + tile_size - 1) / tile_size);

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

	gc->set_program_object(render_tiles_program);
	gc->dispatch(num_tiles_x, num_tiles_y);

	gc->reset_image_texture(0);
	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(2);
	gc->reset_uniform_buffer(1);
	gc->reset_uniform_buffer(0);

	//timer.end_time(gc);
}
예제 #2
0
void LightsourceSimplePass::render(const GraphicContextPtr &gc, GPUTimer &timer)
{
	ScopeTimeFunction();

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

	gc->set_frame_buffer(inout.fb_final_color);

	gc->set_viewport(inout.viewport.size(), gc->texture_image_y_axis());

	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, inout.normal_z_gbuffer);
	gc->set_texture(2, inout.diffuse_color_gbuffer);
	gc->set_texture(3, inout.specular_color_gbuffer);
	gc->set_texture(4, inout.specular_level_gbuffer);
	gc->set_texture(5, inout.shadow_maps);
	gc->set_texture(6, inout.self_illumination_gbuffer);

	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, type_unsigned_int, 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);
}