-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
BUG: Ensure that distinct polygon collections are shaded identically #12792
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
Conversation
Right now, shading ratios are computed by computing a shade in [-1, 1] for each face from the normal vector, and then normalizing across the polygon collection so that the brightest face has shade=1, and the dimmest shade=0.5. This behaves poorly with multiple polygon collections, as the normalization is internal to each. This results in two polygons with the same orientation but in different collections ending up with different shadings. Notably, this obstructs the shading of `ax.voxels()`. This approach instead scales `[-1, 1]` to `[0.4, 1]`, ignoring the local brightness minima and maxima within a collection. Some more noticeable effects of this change: * Highlights will be darker, unless they were already directly facing the light source * Contrast between extreme highlights and shadows will be slightly greater (from 1:0.5 to 1:0.4)
lib/mpl_toolkits/mplot3d/axes3d.py
Outdated
# convert dot product to allowed shading fractions | ||
in_norm = Normalize(-1, 1) | ||
out_norm = Normalize(0.3, 1).inverse | ||
norm = lambda x: out_norm(in_norm(x)) |
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.
0.3 was chosen to roughly give the same shading in the test-cases as before
lib/mpl_toolkits/mplot3d/axes3d.py
Outdated
# convert dot product to allowed shading fractions | ||
in_norm = Normalize(-1, 1) | ||
out_norm = Normalize(0.3, 1).inverse | ||
norm = lambda x: out_norm(in_norm(x)) |
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.
PEP 8 doesn't like assigning a variable to a lambda. I'm kind of indifferent but I guess it would be possible to do
def norm(x):
return out_norm(in_norm(x))
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.
Has the extra requirement that it needs blank lines around it, which IMO makes the grouping less clear.
I guess I'll just drop the lambda
, and substitute out_norm(in_norm(x))
at the call site.
@dstansby: PEP8 issues fixed |
Right now, shading ratios are computed by computing a shade in [-1, 1] for each face from the normal vector, and then normalizing across the polygon collection so that the brightest face has shade=1, and the dimmest shade=0.5.
This behaves poorly with multiple polygon collections, as the normalization is internal to each.
This results in two polygons with the same orientation but in different collections ending up with different shadings.
Notably, this obstructs the shading of
ax.voxels()
.This approach instead scales
[-1, 1]
to[0.4, 1]
, ignoring the local brightness minima and maxima within a collection.Some more noticeable effects of this change:
PR Summary
PR Checklist