2 \section{Lighting by a point light source}
4 Two parameters, the first one positions the \Index{light source}, the second one sets the \Index{light intensity}:
6 \item \Lkeyword{lightsrc}=20 30 50 in Cartesian coordinates, or
7 \texttt{\Lkeyword{lightsrc}=\Lkeyval{viewpoint}} to put the light source at the view point.
8 \item \texttt{\Lkeyword{lightintensity}=2} (default value).
11 \newcommand\LIGHTSRC[3]{%
17 /THETA yLIGHTSRC xLIGHTSRC atan def
18 /DISTANCE xLIGHTSRC dup mul yLIGHTSRC dup mul add zLIGHTSRC dup mul add sqrt def
19 /PHI zLIGHTSRC DISTANCE div arcsin def
20 /ALPHA RADIUS DISTANCE div arccos def
21 /OH ALPHA cos RADIUS mul def
22 /radius_cone ALPHA sin RADIUS mul def
23 /Hauteur_cone DISTANCE OH sub def
24 /X_C xLIGHTSRC OH mul DISTANCE div def
25 /Y_C yLIGHTSRC OH mul DISTANCE div def
26 /Z_C zLIGHTSRC OH mul DISTANCE div def
27 /rotX_axe_cone PHI 90 sub def
28 /rotZ_axe_cone THETA 90 sub def
30 \psset{Decran=50,viewpoint=50 10 15}
31 \psSolid[object=sphere,r=RADIUS,fillcolor=blue,ngrid=18 36,
32 lightsrc=xLIGHTSRC yLIGHTSRC zLIGHTSRC](0,0,0)
33 \psPoint(xLIGHTSRC,yLIGHTSRC,zLIGHTSRC){LS}
35 \psSolid[object=cone,r=radius_cone,h=Hauteur_cone,fillcolor=yellow!50,
36 ngrid=1 36,RotX=rotX_axe_cone,RotZ=rotZ_axe_cone,opacity=0.5,
37 linecolor=yellow](X_C,Y_C,Z_C)
40 \begin{pspicture}(-2,-2.5)(5,5)
43 \uput[45](LS){Light Source}
44 \axesIIID(4,4,4)(6,6,6)
46 \begin{pspicture}(-4,-2.5)(5,2.5)
49 \uput[l](LS){Light Source}
50 \axesIIID(4,4,4)(6,6,6)
53 \begin{pspicture}(-1,-2.5)(9,2.5)
56 \uput[r](LS){Light Source}
57 \axesIIID(4,4,4)(6,6,6)
61 As you can see, the intersecting \Index{plane} (section of the sphere with the cone of
62 \Index{light}) divides the object into two half spaces: the first half space
63 (the one on the side of the \Index{light source}) is illuminated and the other half space is the shadow region referring to this light source position.
65 Now it is clear, that if the view point is setup with the same coordiates as the light source, the object is illuminated uniquely.
67 \encadre{In order to get some shadow regions to appear in the graphic---which emphasises the 3D character---we would suggest choosing the light source and the view point differently.}
70 Here follow a few examples:
72 \begin{pspicture}(-3,-2)(3,3)
76 lightsrc=10 20 30,mode=3}
77 \psSolid[object=sphere,r=5,fillcolor=blue](0,0,8)
78 \rput(0,-3.5){\texttt{lightsrc=10 20 30}}
80 \begin{pspicture}(-3,-2)(3,3)
84 lightsrc=-10 -20 30,mode=3}
85 \psSolid[object=sphere,r=5,fillcolor=blue](0,0,8)
86 \rput(0,-3.5){\texttt{lightsrc=-10 -20 30}}
88 \begin{pspicture}(-3,-2)(3,3)
92 lightsrc=30 -20 30,mode=3}
93 \psSolid[object=sphere,r=5,fillcolor=blue](0,0,8)
94 \rput(0,-3.5){\texttt{lightsrc=30 -20 30}}
97 When the option \verb+[lightsrc=value1 value2 value3]+
98 is not specified, the object is uniformly illuminated.
101 \begin{pspicture}(-6,-2)(6,2)
102 %\psframe(-6,-4)(6,4)
103 \psset{viewpoint=50 50 30 rtp2xyz,Decran=40,unit=0.6}
104 \psSolid[object=datfile,file=./tore1836,deactivatecolor]
105 %\psSolid[r1=3.5,r0=1,object=tore,ngrid=18 36,fillcolor={[rgb]{.372 .62 .628}}]%
106 \axesIIID(0,4.5,0)(6,6,4)
112 Here are some examples, where we always keep the same object, the same view point, the same light
113 source coordinates and just vary the \Lkeyword{lightintensity} value:
115 \begin{pspicture}(-3,-2)(3,3)
118 viewpoint=500 0 1000,
119 lightsrc=-10 -20 30,mode=4,lightintensity=1}
120 \psSolid[object=sphere,r=5,fillcolor=green](0,0,8)
121 \rput(0,-3.5){\texttt{lightintensity=2}}
123 \begin{pspicture}(-3,-2)(3,3)
126 viewpoint=500 0 1000,
127 lightsrc=-10 -20 30,mode=4,lightintensity=3}
128 \psSolid[object=sphere,r=5,fillcolor=green](0,0,8)
129 \rput(0,-3.5){\texttt{lightintensity=3}}
131 \begin{pspicture}(-3,-2)(3,3)
134 viewpoint=500 0 1000,
135 lightsrc=-10 -20 30,mode=4,lightintensity=8}
136 \psSolid[object=sphere,r=5,fillcolor=green](0,0,8)
137 \rput(0,-3.5){\texttt{lightintensity=8}}
140 Here we can see, that by increasing the \Lkeyword{lightintensity} value, the shading nuances of the solid are decreasing.