Abstract:
An apparatus for shading a polyhedron at high speed is disclosed which includes the combination of a polygon-scan line conversion processor and an inner product interpolation processor for obtaining a pair of inner products of vectors indicative of a relation among the direction of a normal, the direction of a light source and the direction of a view point each viewed at a point within a polygon having a plurality of vertices, on the basis of the position of said point in the polygon and the direction of a normal at each of the vertices, a table searched on the basis of the inner products of vectors and holding a series of brightness data which have previously been calculated for a series of values of each of the inner products of vectors, a buffer for storing the result of table search for the above table, and a D/A conversion circuit for converting the result of table search into a signal which is used as a brightness control signal in a display device.

Description:
BACKGROUND OF THE INVENTION 
     The present invention relates to an image processing apparatus, and more particularly to the shading of a displayed body in the processing of three-dimensional image data. 
     It has been well known that when a three-dimensional body is displayed on a display device of a pattern processing apparatus, such as a CRT display, the displayed body is shaded on the basis of a light reflection model, to display the body just as it would appear in reality. Such a shading technique is described, for example, in the following publications. 
     Bui Tuong Phong, &#34;Illumination for Computer Generated Pictures&#34;, Communications of ACM, 18(6), June 1975, pages 311 to 317. 
     J. D. Foly and A. Van Dam, &#34;Fundamentals of Interactive Computer Graphics&#34;, Addison Wesely Publishing Company. 
     James F. Blinn, &#34;Models of Light Reflection for Computer Synthesized Pictures&#34;, SIGGRAPH &#39;77 Proceeding. 
     Although details of the shading technique are described in the above publications (particularly in the book by J. D. Foly and A. Van Dam), the principle of shading based upon a reflection model will be summarized below. FIG. 2 shows a reflection model used by J. F. Blinn. In FIG. 2, reference symbol N designates a unit vector normal to a reflecting surface (namely, the unit normal vector of the reflecting surface), L a unit vector starting from a reflecting point P and directed to a light source, V a unit vector starting from the reflecting point P and directed to a view point, and H a unit vector in the direction of the sum vector of the vectors L and V. Accordingly, the unit vector H is the bisector of an angle between the vector L and the vector V. According to this model, the light intensity I at the view point is expressed by the following equation: 
     
         I=I.sub.a K.sub.a +I.sub.p {K.sub.d (N·L)+K.sub.s (N·H).sup.n }                                    (1) 
    
     when I a  indicates the intensity of ambient light, K a  a reflection coefficient for ambient light, I p  the intensity of light from a light source, K d  a diffuse reflection coefficient, K s  a specular reflection coefficient, and n a numeral value varying in a range from 10 to 1,000, depending upon the roughness of the reflecting surface. Incidentally, a mark &#34;.&#34; in the equation (1) indicates the inner product of vectors. 
     A three-dimensional body which is bounded by a curved surface and is to be displayed, is first approximated by a polyhedron having a plurality of polygonal facets each called a patch surface, and then a unit normal vector at each vertex of the polyhedron is determined. FIG. 3 shows a polyhedron, by which a to-be-displayed body is approximated. Referring to FIG. 3, a polyhedron 1 has patch surfaces 11 to 13, and the unit normal vectors of the patch surfaces 11, 12 and 13 are expressed by N 11 , N 12  and N 13 , respectively. A unit normal vector N v  at a vertex 14 is obtained by forming a unit vector along the average vector of the unit normal vectors N 11 , N 12  and N 13  of the patch surfaces 11, 12 and 13 which share the vertex 14. After the unit normal vectors at all vertices of the polyhedron have been determined in the above-mentioned manner, a unit normal vector at each point on an original curved surface corresponding to each patch surface is determined by the interpolation of a unit normal vector among vertices which define the patch surface. Then, the intensity of light reflected from each point on the surface of the to-be-displayed body toward the view point, that is, the brightness of each dot (namely, each pixel) on a display screen can be calculated from the equation (1). Thus, the surface of the displayed body can be shaded. Although the vector H is used in the above shading method, the vector V may be used instead of the vector H. In this case, substantially the same result as in the above method is obtained, but the calculation of light intensity at the view point becomes complicated. 
     In a conventional shading apparatus, the inner products (N·L) and (N·H) have been calculated for each dot, and then the equation (1) has been calculated. Accordingly, it takes a lot of time to complete a displayed pattern. 
     SUMMARY OF THE INVENTION 
     A main object of the present invention is to provide a pattern shading apparatus which can shorten the processing time required for shading the displayed surface of a three-dimensional body. 
     In order to attain the above object, according to an aspect of the present invention, the brightness corresponding to various values of each of the inner products (N·L) and (N·H) is previously calculated and stored in tables. For example, the quantities I a  and I p  in the equation (1) can be considered to be constant for one patch surface. Accordingly, the equation (1) can be divided into two parts, one of which includes the first and second terms of the equation (1) and the other part includes only the third term. Thus, each part of the equation (1) can be treated as the function of one inner product of vectors. Accordingly, the equation (1) can be readily calculated by using two tables, one of which stores values of the inner product (N·L) and the other of which stores values of the inner product (N·H). 
     Further, according to another aspect of the present invention, in order to carry out the interpolation of inner product of vectors between two points, each vector is represented by a polar coordinate system. The vector L and the vector V (or H) can be considered to be constant for one patch surface. Therefore, each of the inner products (N·L) and (N·H) necessary for calculating the brightness of each dot is a function of only the vector N. Further, when an appropriate polar coordinate system is used, each of the above inner products can be expressed by a trigonometric function of a coordinate angle θ of the vector N. Accordingly, instead of calculating the inner products (N·L) and (N·H) after having determined the vector N at each point by interpolation, the inner products themselves can be directly determined by interpolation, using the coordinate angle θ as a parameter. 
    
    
     BRIEF DESCRIPTION OF THE DRAWINGS 
     FIG. 1 is a block diagram showing an embodiment of a pattern shading apparatus according to the present invention. 
     FIG. 2 is a schematic diagram showing a light reflection model. 
     FIG. 3 is a schematic diagram showing a polyhedron, by which a to-be-displayed body is approximated. 
     FIG. 4 is a schematic diagram for explaining the polygon-scan line conversion. 
     FIGS. 5 and 6 show the polar coordinate representation of vectors. 
     FIG. 7 shows the relation between component values of a vector X in a polar coordinate system and a quadrant where the projection of the vector X onto a N L  -J plane is present. 
     FIG. 8 shows formulae which are used for calculating a coordinate angle θ x  of the vector X in accordance with a quadrant where the above projection is present. 
     FIG. 9 is a block diagram showing the inner product interpolation processor of FIG. 1. 
    
    
     DESCRIPTION OF THE PREFERRED EMBODIMENT 
     FIG. 1 shows the whole construction of an embodiment of a pattern shading apparatus according to the present invention. 
     Referring to FIG. 1, a coordinate transformation processor 2 receives position coordinates of each vertex of a polyhedron, by which a to-be-displayed body is approximated, from a host computer (not shown), to perform coordinate transformation, such as the rotation or parallel displacement of coordinate axes, if necessary. Since such coordinate transformation has no direct connection with the present invention and is explained in detail in the previously-referred book by J. D. Foly and A. Van Dam, the explanation of the coordinate transformation processor 2 will be omited. A polygon-scan line conversion processor 3 determines the positional coordinates, unit normal vector and polar coordinate representation of the inner products (N·L) and (N·H) for the starting and end points of each scan line, on the basis of coordinate information on the polyhedron, and then produces parameters which are to be supplied to inner product interpolation processors 41 and 42, on the basis of the above data. The function and operation of the polygon-scan line conversion processor 3 will be explained later in more detail. Although details of the inner product interpolation processor 41 will be described later, the processor 41 receives the above parameters, to calculate the inner product (N·L) for each dot on each scan line by interpolation. similarly, the inner product interpolation processor 42 calculates the inner product (N·H) for each dot by interpolation. Brightness tables 51 to 56 hold values of the brightness I ad  =I a  K a  +I p  K d  (N·L) corresponding to values of the inner product (N·L) and based upon the reflection of ambient light and the diffuse reflection of light from the light source, and values of the brightness I s  =I p  K s  (N·H) n  corresponding to values of the inner product (N·H) and based upon the specular reflection of light from the light source. Further, the tables 51 and 52 corespond to the red component of reflected light, the tables 53 and 54 correspond to the green component, and the tables 55 and 56 correspond to the blue component. The brightness information read out of the tables 51 to 56 is sent to adders 61 to 63, and values of I ad  and I s  which are read out of the above tables for the same color component are added to each other by a corresponding one of the adders 61 to 63. The outputs of the adders 61 to 63 are stored in frame buffers 71 to 73 dot by dot, and then respective contents of the buffers 71 to 73 are sent to a CRT display 9 through D/A converters 81 to 83, to control the brightness of the display screen of the CRT, thereby shading a displayed body. 
     FIGS. 4 to 8 serve to explain the processing carried out by the polygon-scan line conversion processor 3. The processor 3 determines a side vector indicative of each side of a patch surface, on the basis of position coordinates of each vertex of a polyhedron, determines the unit normal vector of the patch surface as the vector product of two side vectors, and then calculates a unit normal vector at each vertex in the previously-mentioned manner. Thereafter, the processor 3 determines the starting and end points of each scan line in the same manner as in an ordinary polygon-scan line conversion method, and then calculates the unit normal vectors at points on each scan line successively. 
     In more detail, referring to FIG. 4 which shows a patch surface 30, a unit normal vector N L  at a starting point S of a scan line 31 is calculated, by interpolation, from unit normal vectors N 1  and N 2  at two vertices which serve as respective ends of a side 32 containing the point S. Similarly, a unit normal vector N R  at end point T of the scan line 31 is calculated, by interpolation, from unit normal vectors N 3  and N 4  at two vertices which serve as respective ends of a side 33 containing the point T. Further, in order to make it easy to calculate the inner products (N·L) and (N·H) at each point on a scan line, a special coordinate system, that is, a polar coordinate system shown in FIG. 5 is used. In this polar coordinate system, the vector N L , the vector product G of the vectors N L  and N R , and the vector product J of the vectors G and N L  are used as coordinate axes. According to this coordinate system, a unit normal vector N at each dot position on the scan line is considered to change from the vector N L   to the vector N R  on the N L  -J plane through a shorter path. In other words, an angle θ between the vector N L  and the vector N is changed from 0 to θ R  (where -π&lt;θ R  &lt;π) in a direction in which the angle between the vector N L  and the vector N R  is less than π. Incidentally, in the above coordinate system, a given unit vector X can be represented by two polar coordinates, that is, an angle θ Y  between the vector X and the vector G and an angle θ X  between the projection of the vector X onto the N L  -J plane and the vector N L . In FIG. 5, angles φ H  and θ H   are polar coordinates of the vector H, and angles φ L  and θ L  are polar coordinates of the vector L. 
     Now, detailed explanation will be made of how to determine the polar coordinates φ X  and θ X  of a given unit vector X. First, the angle φ X  between the vector G and the vector X is given by the following equation: 
     
         φ.sub.X =cos.sup.-1 (G·X) 
    
     where 0≦φ X  ≦π. 
     Since the coordinate angle θ of the vector N, as mentioned above, changes from zero to θ R  through a shorter path, the angle θ X  can take a value satisfying a formula -π&lt;θ x  &lt;π. For example, a vector X 1  shown in FIG. 6 is considered to be rotated from the vector N L  in a positive direction through an angle θ 1  and a vector X 2  is considered to be rotated from the N L  in a negative direction through an angle θ 2 . 
     FIG. 7 shows the relation between a quadrant where the projection of the vector X onto the N L  -J plane is present, and values of inner products (X·N L ) and (X·J), and FIG. 8 shows those formulae for calculating an angle θ X  which are used in accordance with a quadrant where the projection of the vector X onto the N L  -J plane is present, and depending upon whether or not the absolute value of the inner product (X·N L ) is smaller than the absolute value of the inner product (X·J). In other words, the angle θ X  can be calculated by one of the above formulae. In a case where the value of at least one of the inner products (X·N L ) and (X·J) is equal to zero, the angle θ X  can be determined directly from the relation shown in FIG. 7. In the above explanation, a relation N L  ≠N R  is assumed. However, in a case where N L  =N R , that is, N L  ×N R  =0, a given vector perpendicular to the vector N L  can be used as the vector G. In a case where N L  =-N R , unit normal vectors at opposite ends of a patch surface are anti-parallel. Such a case scarcely happens, and can be avoided by increasing the patch surfaces of the polyhedron. 
     The angles φ H , φ L , θ H  and θ L  shown in FIG. 5 can be determined in the above-mentioned manner. Further, the angle θ for each dot on a scan line is increased from 0 to θ R  in such a manner that the angle θ is incremented by a small angle Δθ at intervals of one dot. Accordingly, the angle Δθ can be obtained by dividing the angle θ R  by a numerical value equal to the difference between the number of dots on a scan line and one (1). 
     In brief, the polygon-scan line conversion processor 3 calculates the above-mentioned angles φ H , φ L , θ H , θ L  and Δθ, which are supplied to the inner product interpolation processors 41 and 42. 
     Next, explanation will be made of the inner product interpolation processors 41 and 42. Referring back to FIG. 5, the inner product (N·L) can be expressed by the following equation: 
     
         (N·L)=cos θ·sin φ.sub.L ·cos θ.sub.L +sin θ·sin φ.sub.L ·sin θ.sub.L =1/2{ sin (φ.sub.L +θ.sub.L -θ)+sin (φ.sub.L -θ.sub.L +θ)}                    (2) 
    
     Similarly, the inner product (N·H) can be expressed by the following equation: 
     
         (N·H)=1/2{ sin (φ.sub.H +θ.sub.H -θ)+sin (φ.sub.H -θ.sub.H +θ)}                    (3) 
    
     Usually, the distance between a patch surface and each of the light source and the view point is far larger, as compared with dimensions of the patch surface, and hence the vectors L and H are considered to be constant for all points on one patch surface. Accordingly, each of the equations (2) and (3) is a function of only the angle θ, and the angle θ is successively incremented by Δθ, to change from 0 to θ R . 
     FIG. 9 shows the construction of the inner product interpolation processor 41 for calculating the inner product (N·L). Referring to FIG. 9, a latch circuit 411 holds an angle Δθ which is supplied from the polygon-scan line conversion processor 3, and supplies a value -Δθ and another value Δθ to one input terminal of an adder 412 and one input terminal of an adder 413, respectively. The other input terminal of the adder 412 receives the output of a latch circuit 414. A value φ L  +θ L  from the polygon-scan line conversion processor 3 is applied, as an initial value, to the latch circuit 414. The other input terminal of the adder 413 receives the output of a latch circuit 415. A value φ L  -θ L  from the polygon-scan line conversion processor 3 is applied, as an initial value, to the latch circuit 415. The outputs of the adders 412 and 413 are applied to the latch circuits 414 and 415, respectively. Accordingly, the contents of the latch circuits 414 and 415 are successively decremented and incremented by Δθ, respectively, for a series of dots on a scan line. Thus, the latch circuits 414 and 415 can hold values (φ L  =θ L  -θ) and (φ L  -θ L  +θ) for a dot now scanned, respectively. Sine tables 416 and 417 are searched on the basis of the outputs of the latch circuits 414 and 415, and deliver sine values of the above outputs. The sine values from the tables 416 and 417 are added to each other by an adder 418. A shifter 419 performs a shifting operation for the output of the adder 418 so as to deliver one-half of this output, namely, a value given by the equation (2). 
     The inner product interpolation processor 42 for the inner product (N·H) is used for calculating the equation (3). The processor 43 has the same construction as shown in FIG. 9, excepting that the angles φ H  and θ H  are used in place of the angles θ L  and θ L . 
     The output of the inner product interpolation processor 41 is used for searching the brightness tables 51, 53 and 55, and the output of the inner product interpolation processor 42 is used for searching the brightness tables 52, 54 and 56. The equation (1) can be divided into the following two equations: 
     
         I.sub.ad =I.sub.a K.sub.a +I.sub.p K.sub.d (N·L)  (4) 
    
     
         I.sub.s =I.sub.p K.sub.s (N·H).sup.n              (5) 
    
     The equation (4) indicates the light intensity based upon the reflection of ambient light and the diffuse reflection of light from the light source, and the equation (5) indicates the light intensity based upon the specular reflection of light from the light source. That is, the equations (4) and (5) correspond to two components of the brightness of a displayed body. The values of the equations (4) and (5) with respect to each of red-, green- and blue-components are previously calculated for those values of the inner products (N·L) and (N·H) which are given at an appropriate interval, using reflection coefficients of a to-be-displayed body with respect to the above-mentioned three kinds of reflection, the intensity of ambient light, the intensity of light from the light source, and the value of n. The values of the equation (4) for each of the red-, green- and blue-components are stored in the tables 51, 53 and 55, respectively, and the values of the equation (5) for each of the red-, green- and blue-components are stored in the tables 52, 54 and 56, respectively. For example, in a case where the values of each of the inner products (N·L) and (N·H) are given at intervals of 1/256, the number of entries included in each of the tables 51 to 56 is made equal to 257. That is, the value of the equation (4) or (5) obtained when the value of the inner product (N·L) or (N·H) is zero, is stored in the first entry, the value of the equation (4) or (5) corresponding to the value of the inner product equal to 1/256 is stored in the second entry, the value of the equation (4) or (5) corresponding to the value of the inner product equal to 255/256 is stored in the two hundred fifty sixth entry, and the value of the equation (4) or (5) corresponding to the value of the inner product equal to 1 (one) is stored in the two hundred fifty seventh entry. The values of each of the equations (4) and (5) may be calculated by the host computer or may be calculated by a processor attached to the display device. 
     According to the present embodiment, the brightness tables are used, and hence the calculation of the equation (1) can be achieved only by one table searching process and one adding process after the values of the inner products (N·L) and (N·H) have been determined. While, according to a conventional method, even when the values of I a  K a , I p  K d  and I p  K s  have previously been calculated, two multiplying operations and two adding operations are required for calculating the equation (1). Further, even when a time required for calculating the values stored in the tables 51 to 56 is taken into consideration, the present invention is superior to the conventional method, since a displayed body generally includes a large number of dots having the same values of the inner products (N·L) and (N·H). 
     Further, according to the present embodiment, the calculation of the inner products (N·L) and (N·H) at each dot includes two adding processes and one table searching process. While, according to the conventional method, six multiplying operations and four adding operations are required for calculating the above inner products. 
     As has been explained in the foregoing, a pattern shading apparatus according to the present invention includes a brightness table. Thus, a time necessary for obtaining the brightness of each dot on the basis of the values of the inner products is greatly reduced. Further, according to the present invention, a time required for calculating the inner products by interpolation can be greatly shortened by using a polar coordinate system.