Comments (4)
Hi,
Apologies for the late response. I haven't tried DirectX + HLSL. How did you convert to that, manual translation, Angle, something else?
In my experience, artifacts typically come from low-precision floats.
from glyphy.
Hi,
I had to put this on hold but now I'm retrying to get this working. I did manual translation but I also tried converting it using angle: same result. I get some little artifacts.
I'm using HLSL floats which are supposed to be equivalent to GLSL highp floats (32-bit). I'm compiling it with SM5 and testing it in a GTX 670MX (Kepler)
Here is a screenshot of what I get:
I think that if I got this far, it means that it is not related to texture lookup, filtering or something similar so I bet this has something to do with HLSL not doing his math homework exactly as GLSL.
Do you remember having this kind of artifacts? What do you think it could be?
If you have some time and you are interested, I can send you the shader so you give it a quick look.
from glyphy.
Do you remember having this kind of artifacts? What do you think it could be?
Hey. Thanks for the work. It almost always means we're losing float precision somewhere. Not sure why.
I don't have Windows, but sharing your work wouldn't hurt. Thanks.
from glyphy.
@andresiraola It's caused by a HLSL compiler bug in the glyphy_sdf
loop.
If you step through the shader code in the Visual Studio graphics debugger on one of the gimpy pixels, pay close attention to the register values and you should see endpoint_prev
ends up with the values that were set before entering the loop, and the line endpoint_prev = endpoint
is essentially discarded.
If we rekajigger the code slightly so that it flows without the first 'continue' statement, the emitted assembly comes out okay.
Compiled with /Gec /Fh /T ps_5_0:
float glyphy_sdf(const float2 p, const int2 nominal_size GLYPHY_SDF_TEXTURE1D_EXTRA_DECLS) {
glyphy_arc_list_t arc_list = glyphy_arc_list(p, nominal_size GLYPHY_SDF_TEXTURE1D_EXTRA_ARGS);
/* Short-circuits */
if (arc_list.num_endpoints == 0) {
/* far-away cell */
return GLYPHY_INFINITY * float(arc_list.side);
} if (arc_list.num_endpoints == -1) {
/* single-line */
float angle = arc_list.line_angle;
float2 n = float2(cos(angle), sin(angle));
return dot(p - (float2(nominal_size) * .5), n) - arc_list.line_distance;
}
float side = float(arc_list.side);
float min_dist = GLYPHY_INFINITY;
glyphy_arc_t closest_arc;
closest_arc.p0 = float2(GLYPHY_INFINITY, GLYPHY_INFINITY);
closest_arc.p1 = float2(GLYPHY_INFINITY, GLYPHY_INFINITY);
closest_arc.d = 0;
glyphy_arc_endpoint_t endpoint_prev, endpoint;
endpoint_prev = glyphy_arc_endpoint_decode(GLYPHY_SDF_TEXTURE1D(arc_list.offset), nominal_size);
for (int i = 1; i < GLYPHY_MAX_NUM_ENDPOINTS && i < arc_list.num_endpoints; i++) {
float4 data = GLYPHY_SDF_TEXTURE1D(arc_list.offset + i);
endpoint = glyphy_arc_endpoint_decode(data, nominal_size);
glyphy_arc_t a;
a.p0 = endpoint_prev.p;
a.p1 = endpoint.p;
a.d = endpoint.d;
if (!glyphy_isinf(a.d)) {
if (glyphy_arc_wedge_contains(a, p)) {
float sdist = glyphy_arc_wedge_signed_dist(a, p);
float udist = abs(sdist) * (1. - GLYPHY_EPSILON);
if (udist <= min_dist) {
min_dist = udist;
side = sdist <= 0. ? -1. : +1.;
}
} else {
float udist = min(distance(p, a.p0), distance(p, a.p1));
if (udist < min_dist) {
min_dist = udist;
side = 0.; /* unsure */
closest_arc = a;
} else if (side == 0. && udist == min_dist) {
/* If this new distance is the same as the current minimum,
* compare extended distances. Take the sign from the arc
* with larger extended distance. */
float old_ext_dist = glyphy_arc_extended_dist(closest_arc, p);
float new_ext_dist = glyphy_arc_extended_dist(a, p);
float ext_dist = abs(new_ext_dist) <= abs(old_ext_dist) ? old_ext_dist : new_ext_dist;
#ifdef GLYPHY_SDF_PSEUDO_DISTANCE
/* For emboldening and stuff: */
min_dist = abs(ext_dist);
#endif
side = sign(ext_dist);
}
}
}
endpoint_prev = endpoint;
}
if (side == 0.) {
// Technically speaking this should not happen, but it does. So try to fix it.
float ext_dist = glyphy_arc_extended_dist(closest_arc, p);
side = sign(ext_dist);
}
return min_dist * side;
}
from glyphy.
Related Issues (20)
- Perspective text rendering HOT 1
- Handle cusps HOT 1
- Better handle degenerate curves HOT 1
- Hook up Android touch events? HOT 2
- Emscription demo HOT 7
- I can not find iOS demo
- Glyphy output doesn't look good on my embedded system HOT 2
- what should demo look like? HOT 15
- Demo Programm, changing text size and position HOT 3
- Website unavailable HOT 1
- LiberationMono-Bold.ttf on RHEL7 causes glyphy to abort HOT 10
- Current status of glyphy? HOT 1
- porting to Qt HOT 2
- porting shaders to OpenGL 3.2 (first working version! yay ) HOT 6
- possible bug in glyph rendering? HOT 3
- Demo: Windows Visual Studio “hb.h”: No such file or directory HOT 2
- api misnomer HOT 3
- Retina displays not supported HOT 3
- Add configure option for --with-demo HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from glyphy.