Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlaps and anisotropic filtering #22

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a80c04f
Geometry code to check for arc (and segment) intersections. Runs, but…
May 9, 2012
cbde181
Revised arc interesection detection functions. Does not always work i…
May 11, 2012
77654e9
Intersection check of segment interior with endpoints should work.
May 16, 2012
9167fce
Changed intersect functions to return intersection points, rather tha…
May 17, 2012
a7051bd
Removed glyph-overlap attempt; will have to restart with new approach.
May 18, 2012
9ff48ee
Added a check for arc endpoint/segment intersection.
May 18, 2012
46429c4
Updated "segment contains point" method. Updated check for parallel l…
May 22, 2012
a2e13ad
Lots of work on rearrange_endpoints, which should change order that c…
May 22, 2012
8c789d9
Rearrange contours works, sorts contours by some intersection rule.
May 23, 2012
9ba70e2
Moved code around; rearranging endpoints now done in glyphy-blob. Con…
May 24, 2012
6290a3e
Started work on processing intersecting contours in stages. Not compl…
May 29, 2012
87ab802
Intersecting contours work! Kind of. Outlines on overlap regions are …
May 30, 2012
a023ecd
Outlines work properly in intersecting contours!!! Just need to fix a…
May 31, 2012
e3e08b2
Simple code cleanup. No major change
Jun 1, 2012
fce3ed7
Fixed outline seam glitch, as in DroidSans.ttf glyph (a+cedilla) ą.
Jun 4, 2012
d57d973
Began work on graph method for grouping contours. Set up vertex struc…
Jun 4, 2012
8e7da16
Added support for solid edges between vertices. The same framework ca…
Jun 5, 2012
d42b6fb
Dotted edges are now formed between contours that surround/contain ea…
Jun 6, 2012
a6f26c7
No functional change, but started setting up for collapsed dotted edges.
Jun 8, 2012
e0af0fb
Dotted edges are collapsed and the relevant vertices are merged in th…
Jun 8, 2012
68ece9c
Handled cases where a cell is completely within one contour group, bu…
Jun 12, 2012
aed4e4a
Partition now chosen using the graph algorithm. Edges are repeated af…
Jun 13, 2012
44eb644
Edges in the new graph are no longer repeated.
Jun 14, 2012
3b353f2
Small floating point fix to help coincident outlines keep working.
Jun 14, 2012
3838582
Fixed missing edge bug (very rare - need coincident points), and gene…
Jun 15, 2012
a7a6d90
Minor. Some light code cleanup; added some comments.
Jun 19, 2012
5e946bb
Modified glyphy_sdf to keep track of vector to nearest contour. Still…
Jun 20, 2012
b051088
Subpixel rendering - Some progress on min_dist_vector returned by gly…
Jun 25, 2012
d61590b
SDF now has min_dist_vector with some nice shading, and functions now…
Jun 26, 2012
27b20fa
Merged repeated code into a single "find_min_dist" function in glyphy…
Jun 27, 2012
309f59c
The sdf vector now points in the correct direction... but seams still…
Jun 28, 2012
4e78597
Minor fix.. but SEAMS ARE GONE. Smooth outlines, yessir.
Jun 29, 2012
8cbc8da
Added TestFont with some bad examples; some colour revamp for sdf.
Jul 4, 2012
d8f10c3
Some work on anisotrpic antialias
Jul 4, 2012
7c7575c
Enable anisotropic antialiasing: apply P_inverse to shortest vector w…
Jul 9, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Subpixel rendering - Some progress on min_dist_vector returned by gly…
…phy_sdf, but still not perfect at corners.
Maysum Panju committed Jun 25, 2012
commit b051088f1eea20de375189799fa49f854d158566
8 changes: 7 additions & 1 deletion demo/demo-fshader.glsl
Original file line number Diff line number Diff line change
@@ -62,8 +62,9 @@ main()
float w = abs (normalize (dpdx).x) + abs (normalize (dpdy).x);

vec4 color = vec4 (0,0,0,1);
vec2 hi;

float gsdist = glyphy_sdf (p, gi.nominal_size GLYPHY_DEMO_EXTRA_ARGS);
float gsdist = glyphy_sdf (p, gi.nominal_size, hi GLYPHY_DEMO_EXTRA_ARGS);
float sdist = gsdist / m * u_contrast;

if (!u_debug) {
@@ -97,6 +98,11 @@ main()
glyphy_arc_list_t arc_list = glyphy_arc_list (p, gi.nominal_size GLYPHY_DEMO_EXTRA_ARGS);
// Color the number of endpoints per cell blue
color += vec4 (0,0,1,.1) * float(arc_list.num_endpoints) * 32./255.;

// if (hi.x >= 0. && hi.y >= 0.)
color = vec4 (GLYPHY_INFINITY*abs(hi.x), GLYPHY_INFINITY*abs(hi.y), 0.3, 1);
// else
// color = vec4 (0,0,0,1);
}

gl_FragColor = color;
4 changes: 2 additions & 2 deletions src/glyphy-blob.cc
Original file line number Diff line number Diff line change
@@ -139,8 +139,8 @@ closest_arcs_to_cell (Point c0, Point c1, /* corners */
double radius_squared = (min_dist + half_diagonal) * (min_dist + half_diagonal);
unsigned int main_contour_arcs = 0;

if (min_dist - half_diagonal <= faraway &&
(min_dist1 > -1 * half_diagonal && min_dist2 > -1 * half_diagonal) ) {
if (0 || (min_dist - half_diagonal <= faraway && /// RANDOM FUN. Change 0 to 1 to get cooler debug images. ///
(min_dist1 > -1 * half_diagonal && min_dist2 > -1 * half_diagonal)) ) {
Point p0 (0, 0);


7 changes: 7 additions & 0 deletions src/glyphy-common.glsl
Original file line number Diff line number Diff line change
@@ -158,6 +158,13 @@ glyphy_arc_radius (glyphy_arc_t a)
return distance (a.p0, a.p1) / (2. * glyphy_sin2atan (a.d));
}

vec2
glyphy_segment_normal (glyphy_arc_t a)
{
float unit = sign (a.d);
return vec2 (unit * (a.p0.y - a.p1.y), unit * (a.p1.x - a.p0.x));
}

bool
glyphy_arc_wedge_contains (const glyphy_arc_t a, const vec2 p)
{
4 changes: 2 additions & 2 deletions src/glyphy-geometry.hh
Original file line number Diff line number Diff line change
@@ -379,7 +379,7 @@ inline const Point Line::operator+ (const Line &l) const {

inline const SignedVector Line::operator- (const Point &p) const {
double mag = -(n * Vector (p) - c) / n.len ();
return SignedVector (n.normalized () * mag, mag < 0); /******************************************************************************************* FIX. *************************************/
return SignedVector (n.normalized () * mag, mag < 0); /******************************************************* FIX. *************************************/
}

inline const SignedVector operator- (const Point &p, const Line &l) {
@@ -397,7 +397,7 @@ inline const Vector Line::normal (void) const {
/* Segment */
inline const SignedVector Segment::operator- (const Point &p) const {
/* shortest vector from point to line */
return p - Line (p1, p0); /************************************************************************************************** Should the order (p1, p0) depend on d?? ***********************/
return p - Line (p1, p0); /*********************************************************************** Should the order (p1, p0) depend on d?? ***********************/
}

/* Segment */
65 changes: 46 additions & 19 deletions src/glyphy-sdf.glsl
Original file line number Diff line number Diff line change
@@ -52,15 +52,17 @@ glyphy_arc_list (vec2 p, ivec2 nominal_size GLYPHY_SDF_TEXTURE1D_EXTRA_DECLS)
}








float
glyphy_sdf (vec2 p, ivec2 nominal_size GLYPHY_SDF_TEXTURE1D_EXTRA_DECLS /*, vec2 min_dist_vector*/)
glyphy_sdf (vec2 p, ivec2 nominal_size, out vec2 min_dist_vector GLYPHY_SDF_TEXTURE1D_EXTRA_DECLS)
{
glyphy_arc_list_t arc_list = glyphy_arc_list (p, nominal_size GLYPHY_SDF_TEXTURE1D_EXTRA_ARGS);

/* TODO: Make these returned parameter/global variables/etc so that it is returned from the function.*/
vec2 min_dist_vector;
vec2 min_dist_vector2;

/* Short-circuits: 0 to 1 arcs near cell*/
if (arc_list.num_endpoints == 0) {
/* far-away cell */
@@ -70,14 +72,17 @@ glyphy_sdf (vec2 p, ivec2 nominal_size GLYPHY_SDF_TEXTURE1D_EXTRA_DECLS /*, vec2
/* single-line */
float angle = arc_list.line_angle;
vec2 n = vec2 (cos (angle), sin (angle));
float dist = dot (p - (vec2(nominal_size) * .5), n) - arc_list.line_distance;
min_dist_vector = n * dist;

/* TODO: Update min_dist_vector in this case. What should it be? */
return dot (p - (vec2(nominal_size) * .5), n) - arc_list.line_distance;
return dist;
}

float side = float(arc_list.side);
float min_dist = GLYPHY_INFINITY;
glyphy_arc_t closest_arc;
glyphy_arc_t closest_arc;

// float answer = shortest_dist_to_contours (arc_list, p, true, glyphy_arc_endpoint_decode (GLYPHY_SDF_TEXTURE1D (arc_list.offset), nominal_size) )

float side2 = float(arc_list.side);
float min_dist2 = GLYPHY_INFINITY;
@@ -110,9 +115,17 @@ glyphy_sdf (vec2 p, ivec2 nominal_size GLYPHY_SDF_TEXTURE1D_EXTRA_DECLS /*, vec2
side = (sdist <= 0. ? -1. : +1.);
side = (float(arc_list.side) == -1. ? -1. : side);

/* TODO: Handle case where d=0 (and a has no center) */
min_dist_vector = udist * glyphy_unit_vector (glyphy_arc_center (a) - p);

/* TODO: Handle case where d=0 (and a has no center). CHECK VECTOR DIRECTION (+/-) */
if (a.d == 0.) {
min_dist_vector = udist * glyphy_unit_vector (glyphy_segment_normal (a));
if (distance (p + min_dist_vector, a.p0) > distance (p, a.p0))
return 0.;
}
else {
vec2 center = glyphy_arc_center (a);
min_dist_vector = udist * glyphy_unit_vector (center - p)
* (distance (center, p) < glyphy_arc_radius (a) ? -1. : 1.);
}
}

} else {
@@ -145,13 +158,17 @@ glyphy_sdf (vec2 p, ivec2 nominal_size GLYPHY_SDF_TEXTURE1D_EXTRA_DECLS /*, vec2
#endif
side = sign (ext_dist);


float dist0 = distance (p, a.p0);
float dist1 = distance (p, a.p1);
if (dist0 < dist1)
min_dist_vector = udist * glyphy_unit_vector (a.p0 - p);
else
min_dist_vector = udist * glyphy_unit_vector (a.p1 - p);


if (abs (old_ext_dist) < abs (new_ext_dist)) {
float dist0 = distance (p, a.p0);
float dist1 = distance (p, a.p1);
if (dist0 < dist1)
min_dist_vector = glyphy_unit_vector (a.p0 - p) * udist ;
else
min_dist_vector = glyphy_unit_vector (a.p1 - p) * udist ;

}


@@ -171,6 +188,7 @@ glyphy_sdf (vec2 p, ivec2 nominal_size GLYPHY_SDF_TEXTURE1D_EXTRA_DECLS /*, vec2
* Second contour group is non-empty IFF arc_list.num_endpoints > arc_list.first_contours_length
* IFF min_dist2 == GLYPHY_INFINITY after this loop
*/
vec2 min_dist_vector2;
endpoint_prev = glyphy_arc_endpoint_decode (GLYPHY_SDF_TEXTURE1D
(arc_list.offset + arc_list.first_contours_length), nominal_size);

@@ -192,8 +210,17 @@ glyphy_sdf (vec2 p, ivec2 nominal_size GLYPHY_SDF_TEXTURE1D_EXTRA_DECLS /*, vec2
if (udist <= min_dist2) {
min_dist2 = udist;
side2 = sdist <= 0. ? -1. : +1.;
/* TODO: Handle case where d=0 (and a has no center) */
min_dist_vector2 = udist * glyphy_unit_vector (glyphy_arc_center (a) - p);
/* TODO: Handle case where d=0 (and a has no center). CHECK VECTOR DIRECTION (+/-) */
if (a.d == 0.) {
min_dist_vector2 = udist * glyphy_unit_vector (glyphy_segment_normal (a));
if (distance (p + min_dist_vector2, a.p0) >= distance (p, a.p0))
return 0.;
}
else {
vec2 center = glyphy_arc_center (a);
min_dist_vector2 = udist * glyphy_unit_vector (center - p)
* (distance (center, p) < glyphy_arc_radius (a) ? -1. : 1.);
}
}
} else {
float dist0 = distance (p, a.p0);