-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Improve label readability #188
Conversation
A while back I tweaked BillboardCollectionVS.glsl to align to pixel in one direction. This improved text legibility somewhat, but in many cases text still gets pretty ugly. It also caused images to look worse in some cases. This change adds a `BillboardCollection.clampToPixel` boolean property which aligns all vertices to a pixel in screen space. I then updated the LabelCollection to turn it on by default (it's off by default for Billboards). The end result is more readable text and smoother non-text billboard animation.
Fix breakage from my last commit. Expose `clampToPixel` as an option on `LabelCollection`.
Conflicts: CHANGES.md
@@ -163,6 +163,15 @@ define([ | |||
this._projection = undefined; | |||
|
|||
/** | |||
* If true, aligns all vertices to a pixel in screen space, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that we want to say "vertices" here. It is precise, but maybe too precise for some users. Perhaps just "billboards?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wasn't too keen on my description either, I'll update it but couldn't think of anything better. I'll update it.
@@ -658,7 +667,11 @@ define([ | |||
blending : BlendingState.ALPHA_BLEND | |||
}); | |||
|
|||
this._sp = context.getShaderCache().getShaderProgram(BillboardCollectionVS, BillboardCollectionFS, attributeIndices); | |||
this._sp = context.getShaderCache().getShaderProgram( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a pretty significant bug here, and below when assigning to _spPick
. Do you see it?
.
.
.
When does this get called? What happens if clampToPixel
changes? Does that trigger a recompile to change the #define
?
However, I don't think we need the #define
; a uniform should be OK. The shader could do something like
mix(vec2(positionWC.x, positionWC.y), vec2(floor(positionWC.x), floor(positionWC.y)), u_clampToPixel);
where u_clampToPixel
is a floating-point uniform that is 0.0
for false or 1.0
for true. The GLSL compiler should do a good job of optimizing this. Even if not, the floor
calls probably aren't too bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll update the code to use a uniform instead of a #define.
As far as the bug goes, I didn't notice the tricky this.updateForPick = function(context) {};
after the compile. I understand it's an optimization, but a comment at the beginning of the function mentioning it would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually shying away from code like this.updateForPick = function(context) {};
now. This code is from my earlier JavaScript experimenting days.
As you can see, one PIA in our graphics code is some changes to a primitive (material changes are probably the best example) require a shader recompile, and we need to carefully track these changes, and only recompile when need be. Another strategy that I want to explore is compiling shaders on load - at least the ones we know we will use. This will also help us help the driver compile them asynchronously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'm still learning glsl, so maybe I'm being overzealous, but couldn't I avoid the vec2 construction and simplify your suggestion like this?
vec2 clampedXY = mix(positionWC.xy, floor(positionWC.xy), u_clampToPixel);
gl_Position = czm_viewportOrthographic * vec4(clampedXY, -positionWC.z, 1.0);
Seems to work great, but I wasn't sure if there was a reason you wrote the original version like you did.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer your solution because it is concise. From a performance point of view, I expect them to be identical if the compiler does any optimizations at all.
Okay, this should be ready. |
Code looks good. By the way, we can also use a vector swizzle as an l-value:
There are, however, six test failures in the |
Something is screwy. I actually already changed the |
As we saw, the test failures were more a problem with the test than the change. Everything passes now on both Chrome and Firefox. |
Looks good. Tests passed. Merged. |
@@ -42,6 +42,7 @@ Beta Releases | |||
* Added `affectedByLighting` to `ComplexConicSensorVolume`, `CustomSensorVolume`, and `RectangularPyramidSensorVolume` to turn lighting on/off for these objects. | |||
* CZML `Polygon`, `Cone`, and `Pyramid` objects are no longer affected by lighting. | |||
* Added `czm_viewRotation` and `czm_viewInverseRotation` automatic GLSL uniforms. | |||
* Added a `clampToPixel` property to `BillboardCollection` and `LabelCollection`. When true, it aligns all billboards and text to a pixel in screen space, providing a crisper images at the cost of jumpier motion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"providing a crisper images" should either be "providing crisper images" or "providing a crisper image"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mramato it's OK to make this tweak in master since I just merged this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to close the loop, this has been fixed in master.
A while back I tweaked BillboardCollectionVS.glsl to align to pixel in one direction. This improved text legibility somewhat, but in many cases text still gets pretty ugly. It also caused images to look worse in some cases. This change adds a
BillboardCollection.clampToPixel
boolean property which aligns all vertices to a pixel in screen space. I then updated the LabelCollection to turn it on by default (it's off by default for Billboards).The end result is more readable text and smoother non-text billboard animation.
Look out @pjcozzi I'm learning just enough about graphics to be dangerous ;)