Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}

enter image description here

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

share|improve this question
2  
look at tex.stackexchange.com/questions/54193/… –  Alain Matthes Jun 5 '12 at 12:01

1 Answer 1

up vote 17 down vote accepted

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

\pgfdeclareradialshading{sphere}{\pgfpoint{0cm}{0cm}}% 
{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)}

\pgfdeclareradialshading{sphere1}{\pgfpoint{0.5cm}{0cm}}% 
{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)}


\pgfdeclareradialshading{sphere2}{\pgfpoint{0.5cm}{0.5cm}}% 
{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)}


\pgfdeclareradialshading{sphere3}{\pgfpoint{0cm}{0.5cm}}% 
{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)}

\pgfdeclareradialshading{sphere4}{\pgfpoint{-0.2cm}{0.5cm}}% 
{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)}



\pgfuseshading{sphere}\pgfuseshading{sphere1}\pgfuseshading{sphere2}\pgfuseshading{sphere3}\pgfuseshading{sphere4}

\end{document}

This leads to:

enter image description here


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

\pgfdeclareradialshading{sphere}{\pgfpoint{0cm}{0cm}}% 
{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)}

\pgfdeclareradialshading{sphere1}{\pgfpoint{0.5cm}{0cm}}% 
{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)}


\pgfdeclareradialshading{sphere2}{\pgfpoint{0.5cm}{0.5cm}}% 
{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)}


\pgfdeclareradialshading{sphere3}{\pgfpoint{0cm}{0.5cm}}% 
{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)}

\pgfdeclareradialshading{sphere4}{\pgfpoint{-0.2cm}{0.5cm}}% 
{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)}


\pgfuseshading{sphere}\pgfuseshading{sphere1}\pgfuseshading{sphere2}\pgfuseshading{sphere3}\pgfuseshading{sphere4}

\end{document}

which gives you:

enter image description here

share|improve this answer
    
Thanks, I found it and in the subsequent section 83.3. My bad! but it still has lesser options than what I expected to have for flexible 3D lighting. –  All Jun 5 '12 at 12:00
1  
I'll edit my question to further customize the lighting. –  Claudio Fiandrino Jun 5 '12 at 12:09
    
That's something useful that I was unable to find in the manual. –  All Jun 5 '12 at 13:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.