0

I'm trying to draw an inner glow/shadow for an object consisting of four cubic Bezier curves. To draw a single Bezier curve I'm splitting it into segments and then calculating distances from current pixel to each line segment and finally I'm blending it with min:

// No GL_MAX blending mode in OpenGL ES 2.0 d_min = min(d_min, d)

where d is a distance for every segment. Zoomed in example of blending two line segments:

enter image description here

It works reasonably well when you have ~25 segments representing a short Bezier curve

enter image description here

except for "gutters" in the places where Bezier curves and their respective gradients combine.

Q: How can I avoid these artifacts? Is there a better method for drawing inner glow/shadow?

enter image description here

defhlt
  • 1,775
  • 2
  • 17
  • 24
  • 1
    this [Draw Quadratic Curve on GPU](http://stackoverflow.com/a/31423105/2521214) might help a bit – Spektre Jan 26 '16 at 16:31

2 Answers2

1

What about doing a blur on your curves and then masking the result to the inside area?

Dickson
  • 211
  • 1
  • 11
0

see:

It basically convert inputted 4-vertex geometry chunks into BEZIER cubics with defined curve width d.

In fragment you got information about distance to curve ll so you can use it directly to shade your stuff. For your case using white background and black color and these points:

double pnt[]=                   // cubic curve control points
    {
    +0.9,-0.8,0.0,
    +0.5,+0.8,0.0,
    -0.5,+0.8,0.0,
    -0.9,-0.8,0.0,
    };

I got this output (d=0.05):

output

I just change the final coloring line in vertex shader to:

l=ll/d; // distance from center of curve 0..1
col=vec4(l,l,l,1.0);

You can un-linearize the l by sqrt or pow to enhance the shading effect...

Spektre
  • 49,595
  • 11
  • 110
  • 380