vedo
vedo copied to clipboard
Transparency Artifacts with Cone Slice Intersection
I am experiencing artifacts when rendering a semi-transparent cone intersected with a plane using the slice method. The artifacts appear as unwanted lines or distortions, especially when viewing the slice through the transparent cone. I have tried adjusting depth_peeling settings, setting alpha=1 for the slice, and using the latest version of vedo, but the issue persists. Attached are screenshots showing the problem.
My code:
import vedo as vd
import numpy as np
cone = vd.Cone(pos=(0, 0, 0), height=8, r=2, axis=(0, 0, 1), res=100).alpha(0.8).c('cyan')
plt = vd.Plotter(interactive=False, axes=1, bg='white')
n_steps = 120
angles = np.linspace(0, 120, n_steps)
cut_z = 0.2
initial_camera = None
for i, a in enumerate(angles):
plt.clear()
angle_rad = np.deg2rad(a)
normal = (0, np.sin(angle_rad), np.cos(angle_rad))
plane = vd.Plane(pos=(0, 0, cut_z), normal=normal, s=(8, 3)).alpha(1).c('brown')
intersection = cone.clone().intersect_with_plane(origin=(0, 0, cut_z), normal=normal)
intersection.c('gold').lw(6)
slice = cone.slice(origin=(0, 0, cut_z), normal=normal).c('green').alpha(1)
plt += [cone, plane, slice, intersection]
if i == 0:
plt.show(resetcam=True, viewup='z')
initial_camera = plt.camera
else:
plt.camera = initial_camera
plt.show(resetcam=False, viewup='z')
plt.render()
plt.interactive().close()`
How can I fix it?
Hi that happens because the resulting slice is coincident with the plane, so there no way to know which one should be rendered first. In fact I guess you don't need to plot slice at all. Just comment out the line.
PS: also consider this approach to do the loop
import vedo as vd
import numpy as np
cone = vd.Cone(pos=(0, 0, 0), height=8, r=2, axis=(0, 0, 1), res=100)
cone.alpha(0.8).c('cyan')
n_steps = 120
angles = np.linspace(0, 120, n_steps)
cut_z = 0.2
cam = dict( # press 'shift-C' to get the camera settings
pos=(5.6, -8.0, 19.0),
focal_point=(-0.257882, -0.216234, 0),
viewup=(0, 0, 1),
clipping_range=(11.7023, 33.9711),
)
plt = vd.Plotter(interactive=False)
plt.show(cone, camera=cam)
for i, a in enumerate(angles):
angle_rad = np.deg2rad(a)
normal = (0, np.sin(angle_rad), np.cos(angle_rad))
plane = vd.Plane(pos=(0, 0, cut_z), normal=normal, s=(8, 4))
plane.alpha(1).c('brown')
intersection = cone.intersect_with_plane(origin=(0, 0, cut_z), normal=normal)
intersection.c('gold').lw(6)
# print(intersection.name)
plt.remove("Plane", "PlaneIntersection").add(plane, intersection)
plt.render()
plt.interactive().close()