-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Simplify globe custom layer interface #12545
base: main
Are you sure you want to change the base?
Conversation
src/render/draw_custom.js
Outdated
if (painter.transform.projection.name === "globe") { | ||
implementation.render(context.gl, painter.transform.customLayerMatrix(), painter.transform.getProjection(), painter.transform.globeToMercatorMatrix(), globeToMercatorTransition(painter.transform.zoom)); | ||
if (shaderProgram) { |
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.
If we're ok with the approach, I'll clean up this section for better error reporting as well as safeguard (ensuring that the user properly injected user code snippet helper).
void main() { | ||
gl_PointSize = 30.; | ||
gl_Position = u_projection * vec4(a_pos_merc, 1.); | ||
gl_Position = project_custom_layer(a_pos_merc, a_pos_ecef); |
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.
We could simplify this one step further on the globe custom layer, since it's now consolidated in the same shader program the user may not need to provide two buffers (ecef + merc) and we could ask for them to only provide the merc while doing the projection to ecef for them in project_custom_layer(a_pos_merc)
.
It would mean moving some computations from CPU to GPU but I think that's an ok tradeoff for the sake of simplified use. This also has the advantage that translating custom layer code to the new system becomes fairly trivial.
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 am wondering though if this approach won't limit users. In the debug example where only a few points are rendered what's proposed above works quite ok. But what if a client decides to use a heavy model (e.g. a satellite model). In that case all the mercator points need to be transformed into ECEF and this could be quite expensive since the operation is not a linear one that could be done like before using a standard transformation matrix. What are your thoughts on that?
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.
Discussed offline: let's hold on this suggestion, e.g. transform ECEF on the GPU on our side for performance concern. We'll still keep API conservative and simple as in this PR and introduce other hooks as needed. The idea being that we don't over-commit by giving too much through the API, since it's always easy to give more later than give too much now and introduce breaking changes by removing it.
debug/satellites-custom-layer.js
Outdated
const EARTH_CIRCUMFERENCE_METERS = 2 * Math.PI * EARTH_RADIUS_METERS; | ||
const GLOBE_CIRCUMFERENCE_ECEF = 8192; | ||
const METERS_TO_ECEF = GLOBE_CIRCUMFERENCE_ECEF / EARTH_CIRCUMFERENCE_METERS; | ||
|
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.
thanks for removing this as well it was leftovers which I had forgotten to clean up.
void main() { | ||
gl_PointSize = 30.; | ||
gl_Position = u_projection * vec4(a_pos_merc, 1.); | ||
gl_Position = project_custom_layer(a_pos_merc, a_pos_ecef); |
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 am wondering though if this approach won't limit users. In the debug example where only a few points are rendered what's proposed above works quite ok. But what if a client decides to use a heavy model (e.g. a satellite model). In that case all the mercator points need to be transformed into ECEF and this could be quite expensive since the operation is not a linear one that could be done like before using a standard transformation matrix. What are your thoughts on that?
677fdec
to
1b54482
Compare
@akoylasar the changes suggested as part of PR review were implemented here, please take it from there to add extra requirement on 3d models example and adapt the API as needed. |
Hey, for past few days I'm following progress on custom layers in globe view and would like to discuss about usage of
and also adjusting coordinates to ECEF from mercator. Problem appeared during transitioning from globe to mercator projection at the edges of camera frustum, objects further from the center of camera were "sliding" towards middle - probably that's why this PR is created. My concern is that (AFAIK) if this PR will get merged every object in globe view would have to use custom shaders to adjust for both projections and transitioning. |
Hey @sienki-jenki !
Exactly, this was fixed in #12544, but it requires quite some extra code for the user to add, which we'd like to prevent. threejs may be a bit more challenging, as the threejs API can be used without writing shader code. In our case, we need extra GPU code to interpolate between two vertex arrays to support the transition properly, and it isn't a transformation we can encode in a single matrix at the moment. Do you have the threejs example that has the issue you mentioned? That would be helpful to clarify this use case, and a potential solution might be going through writing a custom shader for your threejs object. |
Removing release-blocker as this needs more examples to validate the immediate mode API. Immediate mode support will be excluded from changelog for now. |
Hey @karimnaaji , sorry for late response, I had some troubles making it work from this branch 😅 I can already tell that the way I implemented |
Simplifications suggested in #12544 (comment) to hide the complexity/internal details from the user and simplify interface.
customLayerVertexHeader
is now used to include as shader prelude for boilerplate code. For globe custom layers, users only have to about the following:project_custom_layer
getShaderProgram
, allowing us to upload necessary uniforms