I have a question regarding the Asymptote module "Smoothcontour3" which is used to create implicitly defined surfaces. In general, the module works well for me, but I have a small issue when drawing transparent surfaces. When the implicitly defined surface is transparent, the gridlines on the surface become very visible (much more visible than I would like them to be).

I have included my Asymptote code below. This is essentially the example of an implicitly defined surface from the Asymptote tutorial by Charles Staats (section 4.6.1 on page 97 in the tutorial). When I disable transparency by setting opac = 1, everything looks beautiful. If I enable transparency by setting opac = 0.75, the image still looks pretty good, but now the gridlines on the surface are very apparent. I can remove the gridlines by setting overlapedges=false, but then I am missing out on the attractive benefits of the overlapedges functionality.

Can anybody provide some advice on this issue? Is it possible to get rid of the gridlines while still having both transparency and overlapedges enabled? Any help would be greatly appreciated.

import smoothcontour3;
size(5cm, 0);
real tuberadius = 0.69;
real opac = 0.75;
// Convert to cylindrical coordinates to draw
// a circle revolved about the z axis.
real toruscontour(real x, real y, real z) {
real r = sqrt(x^2 + y^2);
return (r-2)^2 + z^2 - tuberadius^2;
// Take the union of the two tangent tori (by taking
// the product of the functions defining them). Then
// add (or subtract) a bit of noise to smooth things
// out.
real f(real x, real y, real z) {
real f1 = toruscontour(x - 2 - tuberadius, y, z);
real f2 = toruscontour(x + 2 + tuberadius, y, z);
return f1 * f2 - 0.1;
// The smoothed function extends a bit farther than the union of
// the two tori, so include a bit of extra space in the box.
triple max = (2*(2+tuberadius), 2+tuberadius, tuberadius) + (0.1, 0.1, 0.1);
// Draw the implicit surface.
surface s = implicitsurface(f, -max, max, overlapedges=true, nx=20, nz=5);
draw(s, surfacepen=palegreen + opacity(opac));

To illustrate my question, I have included the graphics generated from the code above. The first image is without transparency, and the second is with transparency enabled (opac = 0.75). As seen in the pictures, the gridlines are quite apparent for a transparent surface (and absent on the opaque surface).

100 percent opacity

75 percent opacity

1 Answer 1


Is it possible to get rid of the gridlines while still having both transparency and overlapedges enabled?

Not really, no. The overlapedges option works by enlarging all the patches slightly. The renderer sees all the patches as distinct surfaces. When the renderer sees two layers of transparent surface instead of one, the result is darker. So overlapped edges get translated into darker regions, i.e. gridlines.

The only way I can imagine fixing this is if Asymptote had the capability to tell the renderer to group patches together to be "opaque relative to each other", so that only one of these patches would contribute to any one pixel. Unfortunately Asymptote does not have this capability -- at least, not so far as I know.

You could try playing with the overlapedges scaling by modifying your copy of smoothcontour3.asy as in this commit: https://github.com/vectorgraphics/asymptote/commit/ff41f2060c00278a13512dd66ca7424d697342c5 But I'm guessing you will end up with the worst of both worlds rather than a satisfactory solution.

  • Thank you very much for your reply, I appreciate your help.
    – Henrik
    Oct 20, 2017 at 20:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .