Search code examples
c++directxdirect2d

directx11 add glow to DrawLine 2d


Im drawing a 2d line how would i add a glow effect to it?

auto renderer::draw_line(point<float> const& start_point, point<float> const& end_point, float const stroke_width, color const& stroke_color) -> void {

    brush->SetColor(D2D1::ColorF(stroke_color.r, stroke_color.g, stroke_color.b, stroke_color.a));

    device_context_d2d1->DrawLine(
        D2D1::Point2F(start_point.x + offsetX, start_point.y + offsetY),
        D2D1::Point2F(end_point.x + offsetX, end_point.y + offsetY),
        brush.get(), stroke_width
    );

}

I think it has something todo with this function

ID2D1Effect* shadowEffect;
device_context_d2d1->CreateEffect(CLSID_D2D1Shadow, &shadowEffect);

Solution

  • You can apply Gaussian blur effect (that is actually used in shadow effect), then (optionally) apply Brightness effect to blurred image and then finally draw blurred image on top of original line image.

    blurred line