template<UnsignedInt dimensions>
Magnum::Shaders::DistanceFieldVector class

Distance field vector shader.

Renders vector graphics in form of signed distance field. See TextureTools::distanceField() for more information. Note that the final rendered outlook will greatly depend on radius of input distance field and value passed to setSmoothness(). You need to provide Position and TextureCoordinates attributes in your triangle mesh and call at least setTransformationProjectionMatrix(), setColor() and bindVectorTexture().

Image

Example usage

Common mesh setup:

struct Vertex {
    Vector2 position;
    Vector2 textureCoordinates;
};
Vertex data[60]{
    // ...
};

GL::Buffer vertices;
vertices.setData(data, GL::BufferUsage::StaticDraw);

GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0,
    Shaders::DistanceFieldVector2D::Position{},
    Shaders::DistanceFieldVector2D::TextureCoordinates{})
    // ...
    ;

Common rendering setup:

Matrix3 transformationMatrix, projectionMatrix;
GL::Texture2D texture;

Shaders::DistanceFieldVector2D shader;
shader.setColor(0x2f83cc_rgbf)
    .setOutlineColor(0xdcdcdc_rgbf)
    .setOutlineRange(0.6f, 0.4f)
    .bindVectorTexture(texture)
    .setTransformationProjectionMatrix(projectionMatrix*transformationMatrix);

mesh.draw(shader);

Base classes

template<UnsignedInt dimensions>
class AbstractVector
Base for vector shaders.

Constructors, destructors, conversion operators

DistanceFieldVector(NoCreateT) explicit noexcept
Construct without creating the underlying OpenGL object.

Public functions

auto setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix) -> DistanceFieldVector&
Set transformation and projection matrix.
auto setColor(const Color4& color) -> DistanceFieldVector&
Set fill color.
auto setOutlineColor(const Color4& color) -> DistanceFieldVector&
Set outline color.
auto setOutlineRange(Float start, Float end) -> DistanceFieldVector&
Set outline range.
auto setSmoothness(Float value) -> DistanceFieldVector&
Set smoothness radius.

Function documentation

template<UnsignedInt dimensions>
Magnum::Shaders::DistanceFieldVector<dimensions>::DistanceFieldVector(NoCreateT) explicit noexcept

Construct without creating the underlying OpenGL object.

The constructed instance is equivalent to moved-from state. Useful in cases where you will overwrite the instance later anyway. Move another object over it to make it useful.

This function can be safely used for constructing (and later destructing) objects even without any OpenGL context being active.

template<UnsignedInt dimensions>
DistanceFieldVector& Magnum::Shaders::DistanceFieldVector<dimensions>::setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix)

Set transformation and projection matrix.

Returns Reference to self (for method chaining)

template<UnsignedInt dimensions>
DistanceFieldVector& Magnum::Shaders::DistanceFieldVector<dimensions>::setColor(const Color4& color)

Set fill color.

Returns Reference to self (for method chaining)

template<UnsignedInt dimensions>
DistanceFieldVector& Magnum::Shaders::DistanceFieldVector<dimensions>::setOutlineColor(const Color4& color)

Set outline color.

Returns Reference to self (for method chaining)

template<UnsignedInt dimensions>
DistanceFieldVector& Magnum::Shaders::DistanceFieldVector<dimensions>::setOutlineRange(Float start, Float end)

Set outline range.

Returns Reference to self (for method chaining)

Parameter start describes where fill ends and possible outline starts. Initial value is 0.5f, larger values will make the vector art look thinner, smaller will make it look thicker.

Parameter end describes where outline ends. If set to value larger than start the outline is not drawn. Initial value is 1.0f.

template<UnsignedInt dimensions>
DistanceFieldVector& Magnum::Shaders::DistanceFieldVector<dimensions>::setSmoothness(Float value)

Set smoothness radius.

Returns Reference to self (for method chaining)

Larger values will make edges look less aliased (but blurry), smaller values will make them look more crisp (but possibly aliased). Initial value is 0.04f.