Beispiel #1
0
void App::render_gaussian_blur(clan::Canvas &canvas, float blur_amount, clan::Texture2D &source_texture, clan::ProgramObject &program_object, float dx, float dy)
{
    uniforms.sample[0].weight = compute_gaussian(0, blur_amount);
    uniforms.sample[0].offset_x = 0.0f;
    uniforms.sample[0].offset_y = 0.0f;

    float totalWeights = uniforms.sample[0].weight;

    for (int i = 0; i < sampleCount / 2; i++)
    {
        float weight = compute_gaussian(i + 1.0f, blur_amount);

        uniforms.sample[i * 2 + 1].weight = weight;
        uniforms.sample[i * 2 + 2].weight = weight;

        totalWeights += weight * 2;

        float sampleOffset = i * 2 + 1.5f;

        clan::Vec2f delta(dx * sampleOffset, dy * sampleOffset);

        uniforms.sample[i * 2 + 1].offset_x = delta.x;
        uniforms.sample[i * 2 + 1].offset_y = delta.y;
        uniforms.sample[i * 2 + 2].offset_x = -delta.x;
        uniforms.sample[i * 2 + 2].offset_y = -delta.y;
    }

    for (int i = 0; i < sampleCount; i++)
    {
        uniforms.sample[i].weight /= totalWeights;
    }

    canvas.flush();
    clan::GraphicContext gc = canvas.get_gc();

    gc.set_texture(0, source_texture);
    gc.set_program_object(program_object);

    uniforms.cl_ModelViewProjectionMatrix = canvas.get_projection() * canvas.get_transform();
    gpu_uniforms.upload_data(gc, &uniforms, 1);
    gc.set_uniform_buffer(0, gpu_uniforms);

    draw_texture(gc, clan::Rectf(0,0,canvas.get_width(),canvas.get_height()), clan::Rectf(0.0f, 0.0f, 1.0f, 1.0f));

    gc.reset_program_object();
    gc.reset_texture(0);

}
Beispiel #2
0
void App::render_shockwave(clan::Canvas &canvas, clan::Texture2D &source_texture, clan::ProgramObject &program_object)
{
	canvas.flush();
	clan::GraphicContext gc = canvas.get_gc();

	gc.set_texture(0, source_texture);
	gc.set_program_object(program_object);

	uniforms.cl_ModelViewProjectionMatrix = canvas.get_projection() * canvas.get_transform();
	gpu_uniforms.upload_data(gc, &uniforms, 1);
	gc.set_uniform_buffer(0, gpu_uniforms);

	draw_texture(gc, clan::Rectf(0,0,canvas.get_width(),canvas.get_height()), clan::Rectf(0.0f, 0.0f, 1.0f, 1.0f));

	gc.reset_program_object();
	gc.reset_texture(0);
}
SvgTransformScope::SvgTransformScope(clan::Canvas &canvas, clan::DomElement &e) : canvas(canvas)
{
	try
	{
		clan::Mat4d mat = clan::Mat4d::identity();

		SvgAttributeReader transform(e, "transform");
		while (!transform.is_end())
		{
			clan::Mat4d t;
			if (transform.is_keyword("matrix"))
			{
				transform.get_keyword("matrix");
				transform.get_operator("(");
				t = clan::Mat4d::identity();
				t.matrix[0] = transform.get_number();
				t.matrix[1] = transform.get_number();
				t.matrix[4] = transform.get_number();
				t.matrix[5] = transform.get_number();
				t.matrix[12] = transform.get_number();
				t.matrix[13] = transform.get_number();
				transform.get_operator(")");
			}
			else if (transform.is_keyword("translate"))
			{
				transform.get_keyword("translate");
				transform.get_operator("(");
				double tx = transform.get_number();
				double ty = transform.is_number() ? transform.get_number() : 0.0;
				transform.get_operator(")");

				t = clan::Mat4d::translate(tx, ty, 0.0);
			}
			else if (transform.is_keyword("scale"))
			{
				transform.get_keyword("scale");
				transform.get_operator("(");
				double sx = transform.get_number();
				double sy = transform.is_number() ? transform.get_number() : sx;
				transform.get_operator(")");

				t = clan::Mat4d::scale(sx, sy, 0.0);
			}
			else if (transform.is_keyword("rotate"))
			{
				transform.get_keyword("rotate");
				transform.get_operator("(");
				double a = transform.get_number() * clan::PI / 180.0;

				t = clan::Mat4d::identity();
				t.matrix[0] = std::cos(a);
				t.matrix[1] = std::sin(a);
				t.matrix[4] = -t.matrix[1];
				t.matrix[5] = -t.matrix[0];

				if (transform.is_number())
				{
					double tx = transform.get_number();
					double ty = transform.is_number() ? transform.get_number() : 0.0;
					t = clan::Mat4d::translate(tx, ty, 0.0) * t * clan::Mat4d::translate(-tx, -ty, 0.0);
				}

				transform.get_operator(")");
			}
			else if (transform.is_keyword("skewX"))
			{
				transform.get_keyword("skewX");
				transform.get_operator("(");
				double a = transform.get_number() * clan::PI / 180.0;
				transform.get_operator(")");

				t = clan::Mat4d::identity();
				t.matrix[4] = std::tan(a);
			}
			else if (transform.is_keyword("skewY"))
			{
				transform.get_keyword("skewY");
				transform.get_operator("(");
				double a = transform.get_number() * clan::PI / 180.0;
				transform.get_operator(")");

				t = clan::Mat4d::identity();
				t.matrix[1] = std::tan(a);
			}
			else
			{
				transform.parse_error("expected transform keyword");
			}

			mat = mat * t;

			if (transform.is_operator(","))
				transform.get_operator(",");
		}

		old_transform = canvas.get_transform();
		canvas.mult_transform(clan::Mat4f(mat));
		transform_active = true;
	}
	catch (clan::Exception &)
	{
	}
}
SvgTransformScope::SvgTransformScope(clan::Canvas &canvas, const clan::Mat4f &transform, bool transform_active) : canvas(canvas), transform_active(transform_active)
{
	old_transform = canvas.get_transform();
	canvas.mult_transform(transform);
}
SvgTransformScope::SvgTransformScope(clan::Canvas &canvas, clan::DomElement &e) : canvas(canvas)
{
	old_transform = canvas.get_transform();
	canvas.mult_transform(parse_transform(e, transform_active));
}
Beispiel #6
0
void App::render_bloom_combine(clan::Canvas &canvas, clan::Texture2D &tex_base, clan::Texture2D &tex_bloom, clan::ProgramObject &program_object)
{
	canvas.flush();
	clan::GraphicContext gc = canvas.get_gc();

	gc.set_texture(0, tex_base);
	gc.set_texture(1, tex_bloom);

	gc.set_program_object(program_object);
	program_object.set_uniform1i(("BaseTexture"), 0);
	program_object.set_uniform1f(("BaseIntensity"), base_intensity);
	program_object.set_uniform1f(("BaseSaturation"), base_saturation);

	program_object.set_uniform1i(("BloomTexture"), 1);
	program_object.set_uniform1f(("BloomIntensity"), bloom_intensity);
	program_object.set_uniform1f(("BloomSaturation"), bloom_saturation);

	program_object.set_uniform_matrix("cl_ModelViewProjectionMatrix", canvas.get_projection() * canvas.get_transform());

	draw_texture(gc, clan::Rectf(0,0,canvas.get_width(),canvas.get_height()), clan::Rectf(0.0f, 0.0f, 1.0f, 1.0f));

	gc.reset_program_object();
	gc.reset_texture(0);
	gc.reset_texture(1);

}
Beispiel #7
0
void App::render_extract_highlights(clan::Canvas &canvas, clan::Texture2D &source_texture, clan::ProgramObject &program_object)
{
	canvas.flush();
	clan::GraphicContext gc = canvas.get_gc();

	gc.set_texture(0, source_texture);

	gc.set_program_object(program_object);
	program_object.set_uniform1i(("SourceTexture"), 0);
	program_object.set_uniform1f(("Threshold"), highlight_threshold);

	program_object.set_uniform_matrix("cl_ModelViewProjectionMatrix", canvas.get_projection() * canvas.get_transform());

	draw_texture(gc, clan::Rectf(0,0,canvas.get_width(),canvas.get_height()), clan::Rectf(0.0f, 0.0f, 1.0f, 1.0f));

	gc.reset_program_object();
	gc.reset_texture(0);

}