# How to create a ball shading and to customize 3D lighting manually?

TikZ shading=ball will create a perfect 3D ball perspective, but it has no option to change the lighting angle, the contract, radius of light, etc (or I am not aware of). I tried to create a 3D ball by radial shading. However, I still do not know how to change the place of inner color.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}

\begin{tikzpicture}
\node[circle,shading=ball,minimum width=3cm] (ball) at (0,0) {};
\node[circle,outer color=blue!60!black,inner color=white,minimum width=3cm] (radial) at (4,0) {};
\end{tikzpicture}

\end{document}


Which is the standard method to customize the 3D lighting?

-
–  Alain Matthes Jun 5 '12 at 12:01

You should go to section 83.2.2 Radial Shadings of the pgfmanual (version October 25, 2010).

Here is a solution in which the color of that example is a bit changed and different center points are used:

\documentclass{article}
\usepackage{pgf}
\begin{document}

% spheres definitions

{rgb(0cm)=(1,1,1);
rgb(0.7cm)=(0.7,0.1,0); rgb(1cm)=(0.5,0.05,0); rgb(1.05cm)=(1,1,1)}

{rgb(0cm)=(1,1,1);
rgb(0.7cm)=(0.7,0.1,0); rgb(1cm)=(0.5,0.05,0); rgb(1.05cm)=(1,1,1)}

{rgb(0cm)=(1,1,1);
rgb(0.7cm)=(0.7,0.1,0); rgb(1cm)=(0.5,0.05,0); rgb(1.05cm)=(1,1,1)}

{rgb(0cm)=(1,1,1);
rgb(0.7cm)=(0.7,0.1,0); rgb(1cm)=(0.5,0.05,0); rgb(1.05cm)=(1,1,1)}

{rgb(0cm)=(1,1,1);
rgb(0.7cm)=(0.7,0.1,0); rgb(1cm)=(0.5,0.05,0); rgb(1.05cm)=(1,1,1)}

\end{document}


To further customize the lighting you should play with:

• the coloring;
• the coloring position.

To be more clear, rgb(0.7cm)=(0.7,0.1,0); it's saying that you want the color (0.7,0.1,0) at 0.7cm.

Here is a slightly different example:

\documentclass{article}
\usepackage{pgf}
\begin{document}

% spheres definitions

{rgb(0cm)=(1,1,1);
rgb(0.7cm)=(0.7,0.1,0); rgb(1cm)=(0.5,0.05,0); rgb(1.05cm)=(1,1,1)}

{rgb(0cm)=(1,1,1);
rgb(0.4cm)=(0.7,0.1,0); rgb(0.6cm)=(0.5,0.05,0); rgb(1.05cm)=(1,1,1)}

{rgb(0cm)=(1,1,1);
rgb(0.9cm)=(0.7,0.1,0); rgb(1cm)=(0.5,0.05,0); rgb(1.05cm)=(1,1,1)}

{rgb(0cm)=(1,1,1);
rgb(0.5cm)=(0.7,0.1,0); rgb(0.75cm)=(0.6,0.075,0); rgb(1cm)=(0.5,0.05,0); rgb(1.05cm)=(1,1,1)}

{rgb(0cm)=(1,1,1);
rgb(0.2cm)=(0.7,0.1,0); rgb(0.9cm)=(0.5,0.05,0); rgb(1.05cm)=(1,1,1)}