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

[wip] Circles support #1241

Closed
wants to merge 28 commits into from
Closed

[wip] Circles support #1241

wants to merge 28 commits into from

Conversation

tmcw
Copy link
Contributor

@tmcw tmcw commented Jun 2, 2015

Basic support to allow circle in v8 styles. Both the circle_bucket and
draw_circle need to be implemented.

This stub will not draw circles, but is sufficient to keep from failing
when it encounters a circle in a stylesheet.


if you use gl.POINTS you don't need to use indexed drawing. You don't need an element buffer and you would use drawArrays instead of drawElements. The tradeoffs:
ansis: gl.POINTS only needs one vertex in the buffer per point. gl.TRIANGLES needs 4 vertices.
ansis: gl.POINTS has a maximum size that varies depending on the platform. gl.TRIANGLES can be any size. I'm trying to find stats on what the minimum max size is for points.

The maximum size of a circle appears to be 64 https://developer.apple.com/opengl/capabilities/

With that limitation, we'll need to use triangles

you'd draw the circular part in the shader. there would be two triangles to make a square. the fragment shader would figure out the distance of each pixel from the center and shade it appropriately

Basic support to allow circle in v8 styles. Both the circle_bucket and
draw_circle need to be implemented.

This stub will not draw circles, but is sufficient to keep from failing
when it encounters a circle in a stylesheet.
@tmcw
Copy link
Contributor Author

tmcw commented Jun 2, 2015

I'm grabbing this branch and working on it today/tomorrow

@tmcw tmcw self-assigned this Jun 2, 2015
@tmcw tmcw mentioned this pull request Jun 4, 2015
2 tasks
@tmcw
Copy link
Contributor Author

tmcw commented Jun 4, 2015

CIRCLES! This branch is ready for review: it draws circles of various colors, with blurring. I assume we'll merge this into the v8 branch if it passes muster?

/cc @kkaefer @ansis @jfirebaugh @mourner


void main(void) {
v_extrude = a_extrude;
vec4 extrude = u_exmatrix * vec4(a_extrude * u_size / 2.0 * sqrt(2.0), 0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you switch from a rotated square to an axis aligned square with vertices ((-1, -1), (1, -1), (1, 1), (-1, 1)) you should be able to remove the sqrt(2.0) here

@ansis
Copy link
Contributor

ansis commented Jun 4, 2015

We can reduce the size of circle vertex buffers by half if we pack the position and extrude together into 4 bytes. If we switch to a square, there will be only two possible extrude component values: -1 and 1. Each component of the extrude only needs a single byte. Each position component has 16 bytes but doesn't need all of them.

The x position and x extrude could be combined into a single short with something like this:
Math.round(x * 2) + Math.round(extrudeX / 2 + 0.5)

They would need to be unpacked in the vertex shader.

We do something similar for lines: buffer, vertex shader.

@tmcw
Copy link
Contributor Author

tmcw commented Jun 4, 2015

  • Switched to axis-aligned boxes
  • Packed the data into fewer bytes

Remaining issue

  • It doesn't seem like pixel scaling is working correctly: a circle that should be 100px across is 134px, and the same if i drop out the shader magic and just draw the square that's behind it.

@tristen
Copy link
Member

tristen commented Jun 8, 2015

👀

@ansis
Copy link
Contributor

ansis commented Jun 9, 2015

The circle needs to be antialiased. Something needs to be added here so that 1px is always blurred.

Also, what are the units for circle-blur?

// unencode the extrusion vector that we snuck into the a_pos vector
v_extrude = vec2(
mod(a_pos.x, 2.0) * 2.0 - 1.0,
mod(a_pos.y, 2.0) * 2.0 - 1.0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most glsl operations can work with vectors, so this can be written as v_extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0);

@jfirebaugh jfirebaugh added this to the 0.9 milestone Jun 11, 2015
@tmcw tmcw changed the title Stub circles support Circles support Jun 15, 2015
@tmcw tmcw changed the title Circles support [wip] Circles support Jun 15, 2015
@tmcw
Copy link
Contributor Author

tmcw commented Jun 15, 2015

The circle needs to be antialiased. Something needs to be added here so that 1px is always blurred.

Done

Also, what are the units for circle-blur?

It's relative to the radius of the circle... blur: 1 is "fully blurred" afaik, where the gradient from center to outside is linear

@tmcw
Copy link
Contributor Author

tmcw commented Jun 15, 2015

@ansis @jfirebaugh - I've added anti-aliasing and expanded the documentation of the blur parameter in the v8 style spec. Anything else remaining?

@peterqliu
Copy link
Contributor

It's relative to the radius of the circle... blur: 1 is "fully blurred"

line-blur measures in pixels. I'm not partial to either way, but let's pick one

@tmcw
Copy link
Contributor Author

tmcw commented Jun 15, 2015

I think we should not pick one: relative blur makes sense for circles and their use cases, and line-blur as pixels makes sense for lines. Let's keep this as-is.

@tmcw
Copy link
Contributor Author

tmcw commented Jun 16, 2015

@kkaefer @ansis added retina/non-retina handling. I think this is good to merge. Final review?

@ansis
Copy link
Contributor

ansis commented Jun 16, 2015

Yes! looks good

tmcw added a commit that referenced this pull request Jun 17, 2015
This is a manual redo of #1241 on top of the v8 branch.
@tmcw
Copy link
Contributor Author

tmcw commented Jun 17, 2015

Merged in 59c7af4

@tmcw tmcw closed this Jun 17, 2015
@tmcw tmcw deleted the v8-circles branch June 17, 2015 22:21
@jfirebaugh
Copy link
Contributor

\o/

1 similar comment
@kkaefer
Copy link
Contributor

kkaefer commented Jun 18, 2015

\o/

tmcw added a commit that referenced this pull request Aug 7, 2015
This is a manual redo of #1241 on top of the v8 branch.
lucaswoj pushed a commit that referenced this pull request Dec 13, 2016
This is a manual redo of #1241 on top of the v8 branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants