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

Shared clip source for the shaders #444

Merged
merged 3 commits into from Oct 14, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Fixed do_clip() undefined behavior

  • Loading branch information
kvark committed Oct 14, 2016
commit b89ecd1746c5b4fe8ef84bcfc72b61e563a42bc4
@@ -557,25 +557,24 @@ float do_clip(vec2 pos, vec4 clip_rect, vec4 radius) {
float d_bl = distance(pos, ref_bl);

float pixels_per_fragment = length(fwidth(pos.xy));
// TODO: compute the `nudge` separately for X and Y
float nudge = 0.5 * pixels_per_fragment;

bool out0 = pos.x < ref_tl.x && pos.y < ref_tl.y && d_tl > radius.x - nudge;
bool out1 = pos.x > ref_tr.x && pos.y < ref_tr.y && d_tr > radius.y - nudge;
bool out2 = pos.x > ref_br.x && pos.y > ref_br.y && d_br > radius.z - nudge;
bool out3 = pos.x < ref_bl.x && pos.y > ref_bl.y && d_bl > radius.w - nudge;

float distance_from_border = (float(out0) * (d_tl - radius.x + nudge)) +
(float(out1) * (d_tr - radius.y + nudge)) +
(float(out2) * (d_br - radius.z + nudge)) +
(float(out3) * (d_bl - radius.w + nudge));
vec4 distances = vec4(d_tl, d_tr, d_br, d_bl) - radius + nudge;
float distance_from_border = dot(vec4(out0, out1, out2, out3), distances);

// Move the distance back into pixels.
distance_from_border /= pixels_per_fragment;

// Apply a more gradual fade out to transparent.
//distance_from_border -= 0.5;

return smoothstep(1.0, 0.0, distance_from_border);
return 1.0 - smoothstep(0.0, 1.0, distance_from_border);
}

float squared_distance_from_rect(vec2 p, vec2 origin, vec2 size) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.