Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 3 commits into from
Jan 6, 2019

Conversation

eric-wieser
Copy link
Contributor

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)

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

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)
# 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))
Copy link
Contributor Author

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

# 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))
Copy link
Member

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))

Copy link
Contributor Author

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.

@eric-wieser
Copy link
Contributor Author

@dstansby: PEP8 issues fixed

@timhoffm timhoffm merged commit 4897ffe into matplotlib:master Jan 6, 2019
@QuLogic QuLogic added this to the v3.1 milestone Jan 6, 2019
@eric-wieser eric-wieser deleted the uniform-shading branch March 23, 2019 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants