예제 #1
0
void ZMinMax::update_buffers(const GraphicContextPtr &gc)
{
	Size texture_size = find_texture_size(normal_z);

	if (!texture0 || texture0->size() != texture_size)
	{ 
		std::string vertex_shader, fragment_shader0, fragment_shader1;
		if (gc->shader_language() == shader_glsl)
			get_shader_glsl(vertex_shader, fragment_shader0, fragment_shader1);
		else
			get_shader_hlsl(vertex_shader, fragment_shader0, fragment_shader1);

		program0 = compile_and_link(gc, vertex_shader, fragment_shader0);
		program1 = compile_and_link(gc, vertex_shader, fragment_shader1);

		Vec4f positions[6] =
		{
			Vec4f(-1.0f, -1.0f, 1.0f, 1.0f),
			Vec4f( 1.0f, -1.0f, 1.0f, 1.0f),
			Vec4f(-1.0f,  1.0f, 1.0f, 1.0f),
			Vec4f( 1.0f, -1.0f, 1.0f, 1.0f),
			Vec4f(-1.0f,  1.0f, 1.0f, 1.0f),
			Vec4f( 1.0f,  1.0f, 1.0f, 1.0f)
		};
		vertices = VertexArrayVector<Vec4f>(gc, positions, 6);

		prim_array = PrimitivesArray::create(gc);
		prim_array->set_attributes(0, vertices);

		texture0 = Texture2D::create(gc, texture_size.width, texture_size.height, tf_rg32f);
		texture0->set_min_filter(filter_nearest);
		texture0->set_mag_filter(filter_nearest);
		texture0->set_wrap_mode(wrap_clamp_to_edge, wrap_clamp_to_edge);

		texture1 = Texture2D::create(gc, texture_size.width, texture_size.height, tf_rg32f);
		texture1->set_min_filter(filter_nearest);
		texture1->set_mag_filter(filter_nearest);
		texture1->set_wrap_mode(wrap_clamp_to_edge, wrap_clamp_to_edge);

		fb0 = FrameBuffer::create(gc);
		fb0->attach_color(0, texture0);

		fb1 = FrameBuffer::create(gc);
		fb1->attach_color(0, texture1);

		BlendStateDescription blend_desc;
		blend_desc.enable_blending(false);
		blend_state = gc->create_blend_state(blend_desc);
	}

	result = (iterations % 2 == 0) ? texture1 : texture0;
}
예제 #2
0
LightsourcePass::LightsourcePass(const GraphicContextPtr &gc, SceneRender &inout) : inout(inout)
{
	if (gc->shader_language() == shader_glsl)
	{
		cull_tiles_program = compile_and_link(gc, "cull tiles", cull_tiles_glsl());
		render_tiles_program = compile_and_link(gc, "render tiles", render_tiles_glsl());
	}
	else
	{
		cull_tiles_program = compile_and_link(gc, "cull tiles", cull_tiles_hlsl());
		render_tiles_program = compile_and_link(gc, "render tiles", render_tiles_hlsl());
	}

	compute_uniforms = UniformVector<Uniforms>(gc, 1);
	compute_lights = StorageVector<GPULight>(gc, max_lights);
	transfer_lights = StagingVector<GPULight>(gc, max_lights);
}
예제 #3
0
LightsourceSimplePass::LightsourceSimplePass(const GraphicContextPtr &gc, SceneRender &inout) : inout(inout)
{
	if (gc->shader_language() == shader_glsl)
	{
		//icosahedron_light_program = compile_and_link(gc, vertex_icosahedron_glsl(), fragment_light_glsl());
		//rect_light_program = compile_and_link(gc, vertex_rect_glsl(), fragment_light_glsl(), "RECT_PASS");
	}
	else
	{
		icosahedron_light_program = compile_and_link(gc, vertex_icosahedron_hlsl(), fragment_light_hlsl());
		rect_light_program = compile_and_link(gc, vertex_rect_hlsl(), fragment_light_hlsl(), "RECT_PASS");
	}

	light_instance_texture = Texture1D::create(gc, max_lights * vectors_per_light, tf_rgba32f);
	light_instance_transfer = PixelBuffer::create(max_lights * vectors_per_light, 1, tf_rgba32f);

	icosahedron.reset(new Icosahedron(gc, true));
}
예제 #4
0
DiffuseGIPassCS::DiffuseGIPassCS(const GraphicContextPtr &gc, SceneRender &inout) : inout(inout)
{
	if (gc->shader_language() == shader_glsl)
	{
		//init_lpv_program = compile_and_link(gc, "init lpv", init_lpv_glsl());
		//init_gv_program = compile_and_link(gc, "init gv", init_gv_glsl());
		//propagate_lpv_program = compile_and_link(gc, "propagate lpv", propagate_lpv_glsl());
		//accumulate_lpv_program = compile_and_link(gc, "accumulate lpv", accumulate_lpv_glsl());
		//render_result_program = compile_and_link(gc, "render result", render_result_glsl());
	}
	else
	{
		init_lpv_program = compile_and_link(gc, "init lpv", init_lpv_hlsl());
		init_gv_program = compile_and_link(gc, "init gv", init_gv_hlsl());
		propagate_lpv_program = compile_and_link(gc, "propagate lpv", propagate_lpv_hlsl());
		accumulate_lpv_program = compile_and_link(gc, "accumulate lpv", accumulate_lpv_hlsl());
		render_result_program = compile_and_link(gc, "render result", render_result_hlsl());
	}
}
예제 #5
0
FinalPass::FinalPass(const GraphicContextPtr &gc, SceneRender &inout) : inout(inout)
{
	if (gc->shader_language() == shader_glsl)
	{
		present_shader = ShaderSetup::compile(gc, "present", vertex_present_glsl(), fragment_present_glsl(), "");
		present_shader->bind_frag_data_location(0, "FragColor");
	}
	else
	{
		present_shader = ShaderSetup::compile(gc, "present", vertex_present_hlsl(), fragment_present_hlsl(), "");
	}
	if (!present_shader->try_link())
		throw Exception("Shader linking failed!");
	present_shader->bind_attribute_location(0, "PositionInProjection");
	present_shader->set_uniform1i("FinalColors", 0);
	present_shader->set_uniform1i("FinalColorsSampler", 0);
	present_shader->set_uniform1i("LogAverageLight", 1);
	present_shader->set_uniform1i("BloomColors", 2);
	present_shader->set_uniform1i("BloomColorsSampler", 2);
	present_shader->set_uniform1i("AmbientOcclusion", 3);
	present_shader->set_uniform1i("AmbientOcclusionSampler", 3);

	Vec4f positions[6] =
	{
		Vec4f(-1.0f, -1.0f, 1.0f, 1.0f),
		Vec4f( 1.0f, -1.0f, 1.0f, 1.0f),
		Vec4f(-1.0f,  1.0f, 1.0f, 1.0f),
		Vec4f( 1.0f, -1.0f, 1.0f, 1.0f),
		Vec4f(-1.0f,  1.0f, 1.0f, 1.0f),
		Vec4f( 1.0f,  1.0f, 1.0f, 1.0f)
	};
	rect_positions = VertexArrayVector<Vec4f>(gc, positions, 6);
	rect_primarray = PrimitivesArray::create(gc);
	rect_primarray->set_attributes(0, rect_positions);

	RasterizerStateDescription rasterizer_desc;
	rasterizer_desc.set_culled(false);
	rasterizer_state = gc->create_rasterizer_state(rasterizer_desc);
}
예제 #6
0
void GaussianBlur::setup(const GraphicContextPtr &gc, float blur_amount, int sample_count)
{
	for (blur_setup_index = 0; blur_setup_index < blur_setups.size(); blur_setup_index++)
	{
		if (blur_setups[blur_setup_index].blur_amount == blur_amount && blur_setups[blur_setup_index].sample_count == sample_count)
			return;
	}

	std::string vertex_shader, vertical_fragment_shader, horizontal_fragment_shader;
	if (gc->shader_language() == shader_glsl)
	{
		vertex_shader = vertex_shader_glsl();
		horizontal_fragment_shader = fragment_shader_glsl(blur_amount, sample_count, false);
		vertical_fragment_shader = fragment_shader_glsl(blur_amount, sample_count, true);
	}
	else
	{
		vertex_shader = vertex_shader_hlsl();
		horizontal_fragment_shader = fragment_shader_hlsl(blur_amount, sample_count, false);
		vertical_fragment_shader = fragment_shader_hlsl(blur_amount, sample_count, true);
	}

	auto vertex = ShaderObject::create(gc, ShaderType::vertex, vertex_shader);
	auto vertical_fragment = ShaderObject::create(gc, ShaderType::fragment, vertical_fragment_shader);
	auto horizontal_fragment = ShaderObject::create(gc, ShaderType::fragment, horizontal_fragment_shader);
	if (!vertex->try_compile())
		throw Exception(string_format("Could not compile Gaussian blur vertex shader: %1", vertex->info_log()));
	if (!vertical_fragment->try_compile())
		throw Exception(string_format("Could not compile vertical Gaussian blur fragment shader: %1", vertical_fragment->info_log()));
	if (!horizontal_fragment->try_compile())
		throw Exception(string_format("Could not compile horizontal Gaussian blur fragment shader: %1", horizontal_fragment->info_log()));

	BlurSetup blur_setup(blur_amount, sample_count);
	blur_setup.vertical_blur_program = ProgramObject::create(gc);
	blur_setup.vertical_blur_program->attach(vertex);
	blur_setup.vertical_blur_program->attach(vertical_fragment);
	blur_setup.vertical_blur_program->bind_frag_data_location(0, "FragColor");
	blur_setup.vertical_blur_program->bind_attribute_location(0, "PositionInProjection");
	if (!blur_setup.vertical_blur_program->try_link())
		throw Exception("Could not link vertical Gaussian blur program");
	blur_setup.vertical_blur_program->set_uniform1i("SourceTexture", 0);
	blur_setup.vertical_blur_program->set_uniform1i("SourceSampler", 0);

	blur_setup.horizontal_blur_program = ProgramObject::create(gc);
	blur_setup.horizontal_blur_program->attach(vertex);
	blur_setup.horizontal_blur_program->attach(horizontal_fragment);
	blur_setup.horizontal_blur_program->bind_frag_data_location(0, "FragColor");
	blur_setup.horizontal_blur_program->bind_attribute_location(0, "PositionInProjection");
	if (!blur_setup.horizontal_blur_program->try_link())
		throw Exception("Could not link horizontal Gaussian blur program");
	blur_setup.horizontal_blur_program->set_uniform1i("SourceTexture", 0);
	blur_setup.horizontal_blur_program->set_uniform1i("SourceSampler", 0);

	blur_setups.push_back(blur_setup);

	if (!gpu_positions.buffer())
	{
		Vec4f positions[6] =
		{
			Vec4f(-1.0f, -1.0f, 1.0f, 1.0f),
			Vec4f( 1.0f, -1.0f, 1.0f, 1.0f),
			Vec4f(-1.0f,  1.0f, 1.0f, 1.0f),
			Vec4f( 1.0f, -1.0f, 1.0f, 1.0f),
			Vec4f(-1.0f,  1.0f, 1.0f, 1.0f),
			Vec4f( 1.0f,  1.0f, 1.0f, 1.0f)
		};
		gpu_positions = VertexArrayVector<Vec4f>(gc, positions, 6);

		prim_array = PrimitivesArray::create(gc);
		prim_array->set_attributes(0, gpu_positions);

		BlendStateDescription blend_desc;
		blend_desc.enable_blending(false);
		blend_state = gc->create_blend_state(blend_desc);
	}
}