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

Supporting reversed ranges in 3d scenes #1940 #3071

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 20 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@
"es6-promise": "^3.0.2",
"fast-isnumeric": "^1.1.1",
"font-atlas-sdf": "^1.3.3",
"gl-cone3d": "^1.1.0",
"gl-cone3d": "git://github.com/archmoj/gl-cone3d.git#823cabfbb19d8b457730320010cb58df748ff9ee",
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Why only the pick shaders here? Does triangle-fragment.glsl need to same discard statements?

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 question. In the previous version the checks for ranges were commented. When I added the checks similar to the other shaders the cones did not show up. Also for backward compatibility I thought there may be no need for them. But as you mentioned on another comment the are other issues with cones. So I will investigate this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also added discard logic for cone triangle-fragment.glsl as well as streamtubes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"gl-contour2d": "^1.1.4",
"gl-error3d": "^1.0.7",
"gl-error3d": "git://github.com/archmoj/gl-error3d.git#d09c224fe25671fcd588a8c803fe83129156fbab",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I remember Mikola telling me that if-statements in shaders can be slow on some hardware. It might be worth combining these 3 if-statements into one with 2 OR operator ||.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now the checks are performed with 2 OR operator ||.

"gl-heatmap2d": "^1.0.4",
"gl-line3d": "^1.1.2",
"gl-line3d": "git://github.com/archmoj/gl-line3d.git#681398a5477f64cfd92ff7494215d5b6854e834b",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

It might be nice to turn your new discard logic into a reusable module that we could import in (all?) our shaders using the glslify syntax.

This comment is non-blocking, but this could be a nice way for @archmoj to familiarize himself with glslify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The outOfBound function is now located in a separate glsl file (in the local path) which is included in the shaders by glslify. Thanks for the hint : )

"gl-mat4": "^1.2.0",
"gl-mesh3d": "^2.0.0",
"gl-mesh3d": "git://github.com/archmoj/gl-mesh3d.git#5828f6255d8c5360631d5feec65801bb104a88e8",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"gl-plot2d": "^1.3.1",
"gl-plot3d": "^1.5.5",
"gl-plot3d": "git://github.com/archmoj/gl-plot3d.git#ce601a50cd3057899f6074f8ea5fcf0ab77f417c",
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is also changes to gl-axes3d as a dependency of gl-plot3d here: gl-vis/gl-axes3d@master...archmoj:rev-bounds

"gl-pointcloud2d": "^1.0.1",
"gl-scatter3d": "^1.0.11",
"gl-scatter3d": "git://github.com/archmoj/gl-scatter3d.git#b649f8fb619242525b64ccf1def62cb2ed3f224f",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"gl-select-box": "^1.0.2",
"gl-spikes2d": "^1.0.1",
"gl-streamtube3d": "^1.0.0",
"gl-surface3d": "^1.3.5",
"gl-streamtube3d": "git://github.com/archmoj/gl-streamtube3d.git#f4f5a63ffb19704a1ab1cadcc7aa848d7b68f7bf",
Copy link
Contributor

Choose a reason for hiding this comment

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

"gl-surface3d": "git://github.com/archmoj/gl-surface3d.git#2455aad56d3727b940fad8d02727806abca0fdf4",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"gl-text": "^1.1.6",
"glslify": "^6.3.1",
"has-hover": "^1.0.1",
Expand Down
27 changes: 16 additions & 11 deletions src/plots/gl3d/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,13 @@ function computeTraceBounds(scene, trace, bounds) {
}
}

function isCloseToZero(a) {
if(Math.abs(a) > Number.MIN_VALUE) { // the smallest positive numeric value representable in JavaScript
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suppose that's a looser condition than if(a !== 0) but the numbers you're subtracting need to already be extremely small in order for their difference to be exactly Number.MIN_VALUE. I suspect we actually want to be substantially looser than that.

Exactly how that should happen I'm not sure, but I think the criterion should be something that depends on the magnitude of the numbers, to the effect of "there should be at least N representable numbers between a and b" where N is maybe 100.

see eg #179 and #1070

Copy link
Contributor

Choose a reason for hiding this comment

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

@archmoj did adding this isCloseToZero fix a particular bug? If so, could you provide the problematic "data" and "layout" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your detailed review and great input.
Because this PR touched on many shader programs, in the reviewed version of this PR, I decided to discard closeToZero range checking. This way it would be easier to investigate if other modifications may have any side effect.
Though we can consider this info in another PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

This way it would be easier to investigate if other modifications may have any side effect.

Great thinking. Thanks!

return false;
}
return true;
}

proto.plot = function(sceneData, fullLayout, layout) {

// Save parameters
Expand Down Expand Up @@ -435,17 +442,8 @@ proto.plot = function(sceneData, fullLayout, layout) {
}
var dataScale = [1, 1, 1];
for(j = 0; j < 3; ++j) {
if(dataBounds[0][j] > dataBounds[1][j]) {
dataScale[j] = 1.0;
}
else {
if(dataBounds[1][j] === dataBounds[0][j]) {
dataScale[j] = 1.0;
}
else {
dataScale[j] = 1.0 / (dataBounds[1][j] - dataBounds[0][j]);
}
}
var diff = dataBounds[1][j] - dataBounds[0][j];
if(!isCloseToZero(diff)) dataScale[j] = 1.0 / diff;
}

// Save scale
Expand Down Expand Up @@ -560,6 +558,13 @@ proto.plot = function(sceneData, fullLayout, layout) {
sceneBounds[0][i] -= d / 32.0;
sceneBounds[1][i] += d / 32.0;
}

if(axis.autorange === 'reversed') {
// swap bounds:
var tmp = sceneBounds[0][i];
sceneBounds[0][i] = sceneBounds[1][i];
sceneBounds[1][i] = tmp;
}
} else {
var range = axis.range;
sceneBounds[0][i] = axis.r2l(range[0]);
Expand Down