6
Shaded surfaces in molecular raster graphics Jiirgen Brickmann Institut fur Physikalische Chemie, Technische Hochschule Darmstadt, PetersenstraBe 20, D-6100 Darmstadt, FRG Some simple algorithms for the display of arbitrary surfaces on colour raster display systems are described. The random light scattering or diffuse reflection of the surface and its geometrical reflection properties are treated independently. Some examples from molecular dynamics and from molecular graphics are given. The computational economics are discussed. Keywords: algorithms, surface display, shading received 30March, revised 15 June 1983 The evolution of hardware technology during the last few years has led to an increasing interest among many scientists, particularly those in molecular graphics, in colour RDS (raster display systems). These systems are available now with a resolution which is nearly that of VGDS (vector graphics display systems). The response times approach those of standard VGDS. Even for RDS’s with low resolution (128 x 128 pixels or 128 X 256 pixels) there is a great advantage relative to vector systems. Molecules and other objects of interest can be displayed more ‘realistically’. Graphics representation can replace real molecular models. As in all computer interactive strategies, there are two divergent objectives to take into account. The first is to refine the optical quality of the computer-generated picture in order to produce a representation which really looks like the ‘object’ of interest. This is particularly necessary for representations of complicated 3D objects with heterogenous surface materials. The second objective is related to the velocity of the interactive man-machine communication. In most cases one is interested in having a response time on a scale of seconds or even faster when the fourth dimension - time - comes into play. There are, in principle, no problems in producing pictures of well-defined objects on high resolution raster graphics systems (1024 x 1024 pixels or greater) with a quality close to that of real photography ‘** but such pict ures require large amounts of computer time, as well as extensive programming. However, in molecular graphics it is not necessary a priori to use highly sophisticated formalisms to mimic a photographic process, since the objects under consideration have no prototype in real macroscopic nature. The aim is to create a model image which stimulates the imagination of experimental working chemists without a large time delay. In this paper, we present simple algorithms which are incorporated in display methods which themselves can be seen as compromises between high quality of the display and short execution time. The scattering intensity (or diffuse reflection) of a rough surface is treated while later additional reflection intensity is discussed. Mainly spheres are given as examples since these ‘objects’ are the most common ones in molecular graphics. In the last section some conclusions are drawn with respect to the economics of the simple algorithms discussed. NOTATION I IR I eff PR eff I”R eff A R RDR P=(x,y,z) P,,PI P2 L=(L,L,,L) e = (e,, er, e,l eL=(exL-,eyL,e,‘-) d d.7 8 (x A B intensity of a light source intensity of reflected light at the reflection point P effective light intensity at the position of the spectator effective light intensity at the spectator’s position after diffuse reflection at a surface effective light intensity at the position of the spectator after geometrical reflection absorption coefficient reflection coefficient reflection coefficient for diffuse reflection coordinate vector of a surface point coordinate vectors of different surface points coordinates of the light source normal vector on a surface normal vector pointing from a surface point to the light source distance between light source and a surface point P distance between spectator and a surface point P angle between the direction of an incident light beam and the normal vector e on a surface angle between the direction of the incident light beam and the direction of the spectator from a surface point P lowest value of brightness an object appears to the spectator (no reflected light from the light source) highest value of brightness an object appears to the spectator (maximally reflected light from the light source) 62 0263-7855/83/030062-06 $03.00@ 1983 Butterworth & Co (Publishers) Ltd Journal of Molecular Graphics

Shaded surfaces in molecular raster graphics

Embed Size (px)

Citation preview

Page 1: Shaded surfaces in molecular raster graphics

Shaded surfaces in molecular raster graphics

Jiirgen Brickmann

Institut fur Physikalische Chemie, Technische Hochschule Darmstadt, PetersenstraBe 20, D-6100 Darmstadt, FRG

Some simple algorithms for the display of arbitrary surfaces on colour raster display systems are described. The random light scattering or diffuse reflection of the surface and its geometrical reflection properties are treated independently. Some examples from molecular dynamics and from molecular graphics are given. The computational economics are discussed.

Keywords: algorithms, surface display, shading

received 30March, revised 15 June 1983

The evolution of hardware technology during the last few years has led to an increasing interest among many scientists, particularly those in molecular graphics, in colour RDS (raster display systems). These systems are available now with a resolution which is nearly that of VGDS (vector graphics display systems). The response times approach those of standard VGDS. Even for RDS’s with low resolution (128 x 128 pixels or 128 X 256 pixels) there is a great advantage relative to vector systems. Molecules and other objects of interest can be displayed more ‘realistically’. Graphics representation can replace real molecular models.

As in all computer interactive strategies, there are two divergent objectives to take into account. The first is to refine the optical quality of the computer-generated picture in order to produce a representation which really looks like the ‘object’ of interest. This is particularly necessary for representations of complicated 3D objects with heterogenous surface materials. The second objective is related to the velocity of the interactive man-machine communication. In most cases one is interested in having a response time on a scale of seconds or even faster when the fourth dimension - time - comes into play. There are, in principle, no problems in producing pictures of well-defined objects on high resolution raster graphics systems (1024 x 1024 pixels or greater) with a quality close to that of real photography ‘** but such pict ures require large amounts of computer time, as well as extensive programming. However, in molecular graphics it is not necessary a priori to use highly sophisticated formalisms to mimic a photographic process, since the objects under consideration have no prototype in real macroscopic nature. The aim is to create a model image which stimulates the imagination of experimental working chemists without a large time delay.

In this paper, we present simple algorithms which are

incorporated in display methods which themselves can be seen as compromises between high quality of the display and short execution time. The scattering intensity (or diffuse reflection) of a rough surface is treated while later additional reflection intensity is discussed. Mainly spheres are given as examples since these ‘objects’ are the most common ones in molecular graphics. In the last section some conclusions are drawn with respect to the economics of the simple algorithms discussed.

NOTATION

I

IR

I eff

PR eff

I”R eff

A R RDR

P=(x,y,z) P,,PI P2

L=(L,L,,L)

e = (e,, er, e,l

eL=(exL-,eyL,e,‘-)

d

d.7

8

(x

A

B

intensity of a light source intensity of reflected light at the reflection point P effective light intensity at the position of the spectator effective light intensity at the spectator’s position after diffuse reflection at a surface effective light intensity at the position of the spectator after geometrical reflection absorption coefficient reflection coefficient reflection coefficient for diffuse reflection coordinate vector of a surface point coordinate vectors of different surface points coordinates of the light source normal vector on a surface normal vector pointing from a surface point to the light source distance between light source and a surface point P distance between spectator and a surface point P angle between the direction of an incident light beam and the normal vector e on a surface angle between the direction of the incident light beam and the direction of the spectator from a surface point P lowest value of brightness an object appears to the spectator (no reflected light from the light source) highest value of brightness an object appears to the spectator (maximally reflected light from the light source)

62 0263-7855/83/030062-06 $03.00@ 1983 Butterworth & Co (Publishers) Ltd Journal of Molecular Graphics

Page 2: Shaded surfaces in molecular raster graphics

LIGHT SCATTERING INTENSITY ON A ROUGH SURFACE

The coloured image of a surface is related to the fact that the incident light is partly reflected and partly absorbed. In general the reflection (reflection coefficient R) and absorption (coefficient A, with R + A = 1) is dependent on the wave length of the incident light. A body is seen as blue if the reflection coefficient R for short wave lengths is larger than for Ionger wave lengths’.2. A rough surface is, by definition, characterized by the fact that the direction of the re-emitted light is independent of the direction of the incident beam. We will use the term ‘random scattering’ or ‘diffuse reflection’ (DR) for this type of behaviour. It is easy to verify (see Figure 1) that in the case of random scattering the intensity 1, of the re-emitted light coming from a point source with intensity I is given by the relation

IR =, I, Ron. cos Qld’ (1)

where 8 is the angle between the incident beam and the normal vector e on the surface and d is the distance between the light source and the considered surface point P. Let us assume that the spectator is a distance d, from P then a surface element appears with an effective intensity

IDN eff = Inldzs = I Ron. cos 8 /(d2d2s) (2)

For small objects like small spheres the variation of d and ds for the whole object can be neglected and I,., becomes

zDR & = c, cos % (3)

with the constant

C, = I Ro,J(d*d*s)

(A + (B - A) cos 0 for - a-12 d 0 d 7r/2

(5) otherwise

and a linear colour map scale as described by Brickmann and Raab” can be directly applied interpreting X as an address of the colour map. The most time-consuming step in the calcufation of X is the calculation of cos 8. This problem is treated in the appendix.

The calculation of the effective brightness on a raster screen according to equation (5) leads to a uniform value of the brightness A in those areas of the surface considered with /81>7rr/2, ie if the light is falling ‘on the back’ of the surface. The brightness A may originate from some random light but not from the point light source under consideration. For some ap lications it is very convenient not to suppress the range 81>7r/2 and to P replace equation (5) by the simpler relation

X=A + (B-A)cosQ (6)

for all values of 8. This is particularly true for the display of small convex objects like spheres (small relative to the size of the screen). It produces an image as if there were a second light source (or a reflector) opposite to the first one (see Figures 1, 2 (right) and 3 (right).

The display of spheres can be further simplified if the direction of the light source is exactly that of the spectator. In parallel projection the spheres with radius p occur then as full circles on the screen of exactly this radius and the effective brightness distribution is symmetrical. Let r be the distance from the location of the centre of the circle on the screen then the brightness becomes (see Figure 4 (left))

X = A + (&A)( l-(rip)*) ) “2 (7) which can be chosen as a scaling factor in practical applications. If, for example, the brightness is scaled between 0 and 100 (per cent scale) two values A and B for the lowest and highest value of brightness can be chosen (0 d A < B 6 100) and all values A G X < B for the brightness X of a particular surface point P (with given cos 8) can be calculated by the linear approximation

The treatments described above are based on a model assuming random scattering of light and on the

Light source

Figure 1. Diffuse reflection of a rough surface. e and e’ Figure 2. Shading of a rough sphere without ‘back are normal vectors on the surface S at the points P and P’ reflection’ (left) and with ‘back reflection (right). The respectively. The point P’ is related to the imaginary ‘back shading was calculated according to the linear cosine reflection ’ (see text) relationship of equation (5) and equation (6), respectively

Volume 1 Number 3 September 1983 63

Page 3: Shaded surfaces in molecular raster graphics

Figure 3. Shading of a rough sphere without ‘back reflection’ (left) and with ‘back reflection’ (right). The shading was calculated according to the quadratic cosine relation of Evans and Romney et al4 (equation (8))

assumption of linearity between minimal and maximal scattering intensity and brightness. The linearity assumption is, however, not fulfilled with respect to the subjective impression of brightness by a spectator. It was demonstrated by Evans, Romney et aZ4 that the subjective impression of brightness of scattering light from a model surface may be quite well modelled by a cos20 - law instead of a linear relation between the effective brightness and the cosine. Instead of equation (2) these authors used the relation

I,t’ = I RD, cos201d4 (8)

to get a more realistic impression of the surfaces. Indeed, it is to be seen from Figure 3 (left) and (right) that this empirical correction gives a better impression of a sphere. This fact may be related to the subjective expectation that there is always some directed reflection on real spheres which can be partly included in the approximation of the above named authors.

The main advantage, however, is again found in the representation of spheres which are illuminated from the position of the spectator. Instead of equation (7) we find for this case for the effective brightness X (see Figure 4 (right))

X=A + (B-A) {1-(rP)2}

which is a relation that can be easily programmed and which needs a minimum of computional steps (see Table 1 and the discussion in the last section).

Before discussing the numerical economics of the algorithms described above we will present some details on the directed reflection in the next section.

HIGHLIGHTS ON A SURFACE

The diffuse reflection approximations described in the preceding section are very useful in calculating the shading on rough surfaces, ie where there is no brilliancy on the surfaces under consideration. To take this latter quality into account one has not only to consider random

Figure 4. Shading of a rough sphere as illuminated from the position of the spectator according to the linear cosine relation in equation (5) (left) and according to equation (3) (right)

scattering but also direct geometrical reflection (CR). While the position of a spectator relative to the surface points does not enter into the calculation for diffuse shading, we now have to include his position in the formalism.

A lot of work has been done on calculations of the geometrical reflection intensities of real materials in the last few years ‘-2,s-h and it has been demonstrated therein that there is, in principle, no restriction on generating as realistic an image as desired. The algorithms, however, necessarily become increasingly time-consuming with increasing image accuracy. In molecular graphics no natural images of the objects under consideration exist. Consequently our work does not deal with this aspect but with the aim of generating images of artificial objects which give a maximum of information on their 3D arrangements. The geometrical reflection properties are simplified in order to speed up the numerical calculations.

Again, a point light source is considered as a first step (see Figure 5). The intensity of the geometrically reflected light I”R eff as a function of the angle 01 between the reflected light beam and the direction of the spectator is given analogously to equation (2)

ZoRCff = 1. Rc;R 6 ( (X )/(d2d2s) (10)

where 6 ((Y ) is the Dirac 6 - function. For real materials, the reflection coefficient Ron is a function of the angle 8 of the incident beam’x2. It approaches unity as 8 goes to zV2. Since the objects in molecular graphics are not made

Table 1. Minimum intensities A and maximum intensities B (in per cent) for the colour components r (red), g (green), and b (blue) for the colour fields in the colour map as was used for the shading of the spheres in Colour plate 1

Blue spheres Red spheres

A 20 20 20 35 15 0 B 60 70 80 80 60 80

64 Journal of Molecular Graphics

Page 4: Shaded surfaces in molecular raster graphics

Light source

Figure 5. Geometrical reflection of a surface (notation as in Figure I). B is the position of the observer

of real materials and since transparency effects are excluded here we will omit this reflection coefficient in the following discussion, ie, we put Ron = constant.

Equation (10) describes the reflection properties of a perfectly reflecting surface, ie only an infinitely small highlight occurs for example on the image of a sphere. Now, no real surface is perfectly reflecting nor are any light sources infinitely small. Both light sources of finite extension and distorted surfaces lead to an effective highlight function g ((u) instead of the o-function which is much smoother than the latter one. Let us assume that the light source remains pointlike. Then g(or) is expected to have its maximum at 6 = 0 and decreases with increasing 101 I. Like other authorsr, we have modelled g( oL ) as a power of cos OL but we only used even exponents, ie

cosZn

(

(a) for 1 (Y [<a/2

&z(K) = (11) 0 otherwise

The highlight functions are shown in Figure 6 for different n-values. The larger the value of n the smaller become the highlight areas of the images. The colour and the intensity of a pixel on the screen on which the image of an object is mapped depend on both IDReff and rcR eff but while the first quantity is wavelength- dependent (and so determines the colour of the object) the second is not under the considerations made above’. It reflects the colour of the light source.

For simplicity we will restrict our considerations to the case of white light sources. For these the highest intensity in the highlights also has this colour. For large values of I(Y 1, however, (I a(=rr/2) the object has a colour which is only determined by ZDR,rf. In principle, the colour and the intensity have to be calculated independently ie the red, green, and blue components have to be determined. This time-consuming procedure can be circumvented using the colour map technique described by Brickmann and Raab3. Therein only the total intensity Z,, is to be determined

leff= $$--(RDn jcos @/m+RGR~~~2n~) (12)

S

with m = 1 or m = 2 corresponding to equation (2) or Figure 7. Shading of a reflecting sphere without diffuse equation (B), respectively (see Figures 7 and 8). For refiection, (left) without ‘back reflection and (right) with coloured images the intensity is mapped to an address X ‘back reflection (see equation (IO), RDR= I, n = 8)

1.0

3 g 0.5

C

_

/ -TV2 0

a

Figure 6. Highlight functions g, (CX) = CO.?’ (Y for different values of n

in a colour map3 within the lower address limit A and the upper one B

X = A + (B-A)

X { RDR~cos Blrn+RGR~~~ 0~ 2n } (13)

where Rbu+Rou=l has to be chosen in order not to exceed the upper limit of the range. Since we do not deal with real objects, Rbn and RGn can be chosen arbitrarily within the restriction given above. The wave length dependence of Ron can be simulated by the choice of the red-green-blue components of the colour corresponding to the lower address limit A. For a white light source the upper limits colour have to be chosen of equal intensity to guarantee highlights of approximately white colour. An application of this procedure is shown

Volume 1 Number 3 September 1983 65

Page 5: Shaded surfaces in molecular raster graphics

Figure 8. Shading of a reflecting sphere according to equation (20) without ‘back reflection’ (left) and with ‘back reflection (right). the parameters are m = 1, n = 8, RDR = 112, RGR = 112

in Colour plate 1 (on centre spread) with colour map values from Table 1.

The computation time for the calculation of the shading on a surface can be reduced (see earlier in the paper) if the direction of the incident light is the spectator’s direction. In this case one has (X = 2 8 (see Figure 5) instead of equation (13) one obtains

X=A+(B-A) R&OS 81”+R,, x(2cos*exl)*” (14)

Again the display of spheres can be substantially sim lified with this particular arrangement. With cos 4 8=1-(r/p)* one has

(15)

Figure 9. Shading of a reflecting sphere calculated according to equation (14) with n = 8 and m = 1 (left), m = 2 (right)

Table 2. The explicit calculations of the surface point coordinates (x,y,z) and their projection onto the coordinates of the screen is generally not included in the calculations of the numbers in this table. In many cases, the latter may be the most time-consuming step in the .calculation. For these the choice of a particular shading algorithm is less important. For simple objects, however, such as spheres, the shading and the calculation of the surface points can be performed simultaneously, leading to a drastic reduction of computer time. If, for example, the surface normal vector can be calculated easily (as in the case of a sphere) and the direction of the incident light is the same for all surface points (parallel beams) the computational speed . Table 2. Numerical expenses for different shading algorithms. S is the number of Fortran statements, M is the number of floating point multiplications, and A is the number of elementary additions of floating point numbers

wherein the ‘back reflection’ was suppressed in the second term (see Figure 9).

NUMERICAL EXPENSES FOR SHADING

As has been mentioned above, in molecular raster graphics there are two diverging principles to be applied. On the one hand, one is interested in generating images of microscopic objects which look as ‘realistic’ as possible, and, on the other hand, the computational expense for the image processing should be small to guarantee short response times. The algorithms described in the preceding sections do not iepresent shading procedures for surfaces of real materials since these ‘materials’ do not exist for the objects under consideration. Nevertheless, it is also possible to generate images which are sufficiently realistic for coloured objects (see Colour plate 1). Even in the simplified shading algorithms, however, different degrees of sophistication are possible. The numerical expenses for these are roughly estimated and listed in

Calculated property Equation S A M* Nos

1 DRt+NV+LD& 5,6,7,10 12 24 19 2 DRt+NV+(eLgiven) 5,lO 9 20 18 3 DRt (e”, e given) V3 2 4 3 4 DRt of a sphere (e” given) 58.9 5 7 6 5 DRt of a sphere (e”=es) 12 1 3 6 6 DRllof asDhere (eL=e.‘) 14 1 3 4 7 DRt+Gd”+Nc#+Ld***) 18,6,7,10 17 27 30 8 DRt+GR’T+hV$ (eL=eS) 19.10 9 21 ‘2 9 DRt+GR”ofaspiere ’

(e”=e”) 20 3 4 11

* a square root and an exponential expression with integer exponent are counted as two multiplications t diffuse reflection as described in the section on flight scattering intensity on a rough surface $ numerical determination of the normal vector when the surface points are given *** explicit calculation of the light direction if the light source is relatively close to the surface. This vector can be replaced by a constant normal vector when the light source approaches infinity 11 diffuse reflection calculated with the empirical co?0 law of Brickmann and Raab3 7 geometrical reflection as described in the section on ‘Highlights on a surface’

66 Journal of Molecular Graphics

Page 6: Shaded surfaces in molecular raster graphics

can be increased by a factor 5 - 10. The fastest procedure is obtained in parallel projection when the direction of the spectator and that of the light source is identical.

ACKNOWLEDGEMENTS

I have to thank Dr W Fischer and Dr H-U Raab for helpful comments and Dr R Pfeiffer for proof-reading the manuscript. This work was supported by the Deutsche Forschungsgemeinschaft, Bonn, and the Fonds der Chemischen Industrie, Frankfurt, FRG.

REFERENCES

Newman, W M and Sproull, R F, Principles of interactive computer graphics McGraw Hill Vol 1 (1979), P 7 Cook, R L and Torrance, K E ACM Trans. on Graphics Vol 1, No 7 (1982) Brickmann, J and Raab, H-U ‘A colour editor for use in molecular graphics’ J. Mol. Graphics (see p 78 of this issue) Wyllie, G, Romney, G, Evans, D and Erdahl, A Proc. FJCC (1967), p 49 Bui-Tuong, P CACM Vol 18 (1975), p 311 Blinn, J F Comput. Graphics Vol 11(1977), p 192, Vol 12 (1978), p 286

APPENDIX

Calculation of cos 0

Let L = (L,, LY, L,) be the coordinates of the light source and P = (x,y,z) the surface point. One simply has

cos 8 = (L-P) e/IL-PI

={(L,-x) e,+(L,-y) ei+(L,-z) e,}\L-PI (16)

with

IL-P12= (Lx-x)2+(LY-y)2+(L,-z)2 (17)

For light sources far away from the surface point the vector L-P can be replaced by a unity length vector eL indicating the direction of the light source from the surface point. Instead of equation (16) we then have

cost3=eL e=eL, e,+eLYeY+eL,e, (18)

and the calculation is reduced to a determination of the normal vector e. The latter can be calculated analytically or approximated numerically. For a sphere with radius R and centre at PO=(xO,yO,z,) one has

e=(P-P) / R (19)

but for more complex surfaces the analytical calculation of e is much more time-consuming than a numerical method. The latter can be easily done. For a full display of an extended surface many surface points are to be determined. One takes two points PI = (x1 ,yl ,z,) and P2 = (Q,Y~,zz) adj acent to the one considered P with the three points non-colinear, and uses the properties of the vector product

e,=[ (yl-y>(z2-z)-Cv2-y)(zI-z)llN

ey= [ (zl-z)(x2-x)-(z2-z)(xl-x) ]lN eZ=[h-4CY2-~)-(~2-~)CY~-~)VN

(20)

with the norm N of the vector pointing in the direction of e. The calculation of e with respect to equation (20) may be error prone in practical applications if the curvature of the surface drastically changes as a function of the position vector.

Volume 1 Number 3 September 1983 67