[Tex/LaTex] Gray shaded sphere with tikz-3dplot

3dtikz-3dplottikz-pgf

How do I draw a grayscale shaded sphere with tikz-3dplot? I tried using \tdplotsphericalsurfaceplot with radius equal to 1, and parametricfill depending on the spherical angles. However, it looks like I can only prescribe the color's hue (in HSB space), according to the following post, which does not suit me. I could go all the way and redefine \tdplotdosurfaceplot, but that seems overkill.

Let me emphasize that I want true 3D drawing (the rest of my picture requires 3D coordinates: I need to draw arcs), so I cannot use 2D tricks such as

\draw [ball color=white] (0,0,0) circle (1) ;

so this is not a duplicate of how-to-draw-a-shaded-sphere. I explicitly want a 3d drawing, preferably with tikz-3dplot, though I'm open to other 3d packages.

Here are two MWEs: the first sphere uses uniform coloring, while the second uses a linear combination of the spherical angles:

\begin{tikzpicture}[tdplot_main_coords]
\tdplotsphericalsurfaceplot[parametricfill]{24}{24}{1} {black}{50}{}{}{}
\begin{scope}[xshift=4cm]
\tdplotsphericalsurfaceplot[parametricfill]{24}{24}{1} {black}{\tdplottheta+\tdplotphi}{}{}{}
\end{scope}
\end{tikzpicture}

I would also like to get rid of the parametric lines… Maybe this is not the right package to work with, or the right command in the package.
enter image description here

Best Answer

Better use pgfplots (adapted from this post). The parametric fill with \theta+\phi looks pretty weird in my opinion.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
  \begin{axis}
    [
      width=6cm,height=6cm,
      axis equal,enlargelimits=false,
      axis lines=none,
      domain=0:180,samples=21,
      y domain=0:360,samples y=21,
      colormap/blackwhite,
      view={100}{10},
    ]
    \addplot3
      [
        surf,
        z buffer=sort,
        shader=flat,
        point meta={acos(z/sqrt(x*x+y*y+z*z)) + atan2(y,x)}
      ] (
        {sin(x)*cos(y)},
        {sin(x)*sin(y)},
        {cos(x)}
      );
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here