Types of Shading#
Comparison of default, flat shading vs. smooth shading.
import pyvista from pyvista import examples
PyVista supports two types of shading: flat and smooth shading that uses VTK’s Phong shading algorithm.
This is a plot with the default flat shading.
mesh = examples.load_nut() mesh.plot()
Here’s the same sphere with smooth shading.
Note how smooth shading makes edges that should be sharp look odd,
it’s because the points of these normals are averaged between two
faces that have a sharp angle between them. You can avoid this by
You can configure the splitting angle with the optional
feature_angle keyword argument.
We can even plot the edges that will be split using
# extract the feature edges exceeding 30 degrees edges = mesh.extract_feature_edges( boundary_edges=False, non_manifold_edges=False, feature_angle=30, manifold_edges=False ) # plot both the edges and the smoothed mesh pl = pyvista.Plotter() pl.enable_anti_aliasing() pl.add_mesh(mesh, smooth_shading=True, split_sharp_edges=True) pl.add_mesh(edges, color='k', line_width=5) pl.show()
split_sharp_edges keyword argument is compatible with
physically based rendering as well.
# plot both the edges and the smoothed mesh pl = pyvista.Plotter() pl.enable_anti_aliasing() pl.add_mesh(mesh, color='w', split_sharp_edges=True, pbr=True, metallic=1.0, roughness=0.5) pl.show()
Total running time of the script: ( 0 minutes 0.807 seconds)