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

Simple point cloud attenuation #5824

Closed
wants to merge 15 commits into from
Closed

Simple point cloud attenuation #5824

wants to merge 15 commits into from

Conversation

lilleyse
Copy link
Contributor

Before #5455 is ready, I've taken some code from there and tweaked a few things so we can support very basic point attenuation.

It just does a mix between the minimum point size and maximum point size based on the distance from the camera, given a max distance of 100 currently. Ideally this value should be tuned based on the tileset scale and point density, but these defaults are decent for now.

before

after

@cesium-concierge
Copy link

@lilleyse, thanks for the pull request! Maintainers, we have a signed CLA from @lilleyse, so you can review this at any time.

I am a bot who helps you make Cesium awesome! Thanks again.

scratchPointSizeAndTilesetTime.x = content._pointSize;
scratchPointSizeAndTilesetTime.y = content._tileset.timeSinceLoad;
return scratchPointSizeAndTilesetTime;
u_pointAttenuationMaxSize : function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not bundled in u_pointSizeAndTilesetTimeAndAttenuation because #5455 overrides just this uniform.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks; even though this behavior might seem redundant; it makes the uniform map easier to modify from future stages

@pjcozzi
Copy link
Contributor

pjcozzi commented Sep 11, 2017

@AnimatedRNG could you please do a first review of this and then bump to me for a quick final review?

@AnimatedRNG
Copy link
Contributor

@pcozzi Sure, I'll take a look soon!

@AnimatedRNG
Copy link
Contributor

@lilleyse Your code looks pretty good! I left a few comments for review.

@lilleyse
Copy link
Contributor Author

@AnimatedRNG is #5824 (comment) your only comment? Is this ready to merge?

@AnimatedRNG
Copy link
Contributor

@lileyse I left three other comments on the code for review. Can you see them?

@@ -432,6 +428,28 @@ defineSuite([
});
});

it('point attenuation', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

If my understanding is correct, this code renders a point with point attenuation disabled, fails to find it, then enables point attenuation and finds it. This test is useful because it proves that point attenuation "grows" points which are close to the camera.

A nice complement test would also check that point attenuation does not grow points which are far away from the camera. This test would prove that the point size is actually being attenuated, rather than just being scaled uniformly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, added a few more lines onto the existing test.

} else {
vs += ' gl_PointSize = u_pointSize; \n';
}

vs += ' color = color * u_highlightColor; \n';
if (pointAttenuation) {
vs += ' vec4 positionEC = czm_view * vec4(positionWC, 1.0); \n' +
Copy link
Contributor

Choose a reason for hiding this comment

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

In general, PointCloud3DTileContent modifies the shader by conditionally appending some code to it (e.g no normals vs has normals, has a point size vs doesn't have a point size, etc.). The shader code incision/excision is made in Javascript, which makes sense given that the shader string is formed, bit by bit, in Javascript.

An alternative may involve using preprocessor defines to selectively enable/disable regions of code, and then merely adding the defines to the defines array, or just prepending those lines to the source.

If you prefer constructing the shader completely in Javascript, then the current method is totally fine too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I could see it going either way. The one area that would be more complicated with defines is the attribute declaration section, but otherwise it falls pretty neatly into defines.

this._pointSize = 1.0;
this._pointAttenuationMaxSize = 10.0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any way to configure the maximum size or the start distance without access to private variables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure if I wanted to expose much of the internals yet since the attenuation is still kind of basic and not on by default. I could see those becoming options in the future though.

@AnimatedRNG
Copy link
Contributor

@lilleyse Ah okay it looks like I hadn't submitted my review yet, sorry! Here it is.

@lilleyse
Copy link
Contributor Author

@AnimatedRNG followed up with your comments.

@mramato
Copy link
Contributor

mramato commented Sep 27, 2017

@lilleyse please merge in master. Do we want this for the next release. @AnimatedRNG will you have time to do another quick review pass on it?

@lilleyse
Copy link
Contributor Author

It would nice to get this in before the release.

@AnimatedRNG
Copy link
Contributor

@mramato Sorry about the delay; everything looks good!

* @type {Boolean}
* @default true
*/
this.pointAttenuation = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Mention this in CHANGES.md.

Are you sure this is the only field you want to expose, e.g., no parameters to change the size?

Are you also sure that it belongs here and not on the style? This seems out of place and more tightly coupled.

Copy link
Contributor Author

@lilleyse lilleyse Sep 28, 2017

Choose a reason for hiding this comment

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

Are you also sure that it belongs here and not on the style? This seems out of place and more tightly coupled.

I don't think it makes sense to be on the style, all 3D Tiles-conformant engines would need to support point attenuation. I think of this as similar to the color blend mode for tilesets, just an engine option to tweak the visuals.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you sure this is the only field you want to expose, e.g., no parameters to change the size?

@AnimatedRNG also suggested this. I might make them private to start since I expect the attenuation to be more involved in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

@AnimatedRNG also suggested this. I might make them private to start since I expect the attenuation to be more involved in the future

Could be fine to be public and then deprecate everything when we have the new method; otherwise, I think users will ask for these properties right away.

@pjcozzi
Copy link
Contributor

pjcozzi commented Sep 27, 2017

Just that comment.

@pjcozzi
Copy link
Contributor

pjcozzi commented Oct 2, 2017

I don't think it makes sense to be on the style, all 3D Tiles-conformant engines would need to support point attenuation

What part of the spec says this?

Seems to be that this is exactly the type of behavior defined by a style.

@pjcozzi
Copy link
Contributor

pjcozzi commented Oct 2, 2017

@lilleyse please bump when ready. Just a heads up that I will not have the bandwidth to review in time for the release today.

@lilleyse
Copy link
Contributor Author

lilleyse commented Oct 2, 2017

Updated to make all the point size controls public.

I'm still not sure about adding this to the style. The same question applies to point cloud surface reconstruction (#5455) - should a style be able to say whether it uses that technique? I feel like these options are too tied to the rendering engine to be useful as styles. Maybe we can discuss more offline.

@pjcozzi
Copy link
Contributor

pjcozzi commented Oct 3, 2017

Discussed offline - we are going to try this with declarative styling.

@lilleyse
Copy link
Contributor Author

Closing in favor of #6069

@lilleyse lilleyse closed this Dec 22, 2017
@lilleyse lilleyse deleted the point-attenuation branch December 22, 2017 01:36
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.

5 participants