Abstract:
Method for shading 3D graphic models using 2D graphic tools, wherein the 3D graphic model is constructed of any number of polygons, according to which, each polygon is subdivided into triangles while mapping the spatial orientation and scaling of each triangle to a predetermined spatial orientation and scale, using a combination of rotation, scaling, and linear translation. Each mapped triangle is shaded using 2D linear or bi-linear coloring map shading tools and then remapped to its original spatial orientation and scale using, a corresponding combination of rotation, scale, and linear translation, such as an inverse combination.

Description:
FIELD OF THE INVENTION 
       [0001]    The present invention relates to the field of computer generated images. More specifically, this invention relates to a method for smooth shading and texture mapping using linear gradients. 
       BACKGROUND OF THE INVENTION 
       [0002]    3D computer graphics is the art of using digital computers and dedicated 3D software applications to create a collection of graphical objects that can be displayed on a suitable terminal device. Although many computer applications are currently implemented using 3D graphics, some environments, such as Macromedia Flash© Technology (MFT), are inherently two-dimensional (2D). 
         [0003]    Among the drawbacks of 2D graphics, in relation to 3D graphics, is the feature of coloring, shading and texture mapping of the displayed objects. 2D graphic tools allow one to fill the polygon with colors that change gradually. MFT, for example, allows two types of gradual painting, either along linear trajectories, or along circular trajectories. However, such 2D applications do not support shading or texture mapping of 3D graphic models. 
         [0004]    When creating computer graphic models, each shape in the model must be constructed by certain modeling techniques. Several modeling techniques are known in the art, including polygonal modeling (information related to polygonal modeling may be found, for example, at http://en.wikipedia.org/wiki/Polygonal_modeling). Models can be created with a wide variety of commercial modeling tools, such as AutoCAD© and Solid Works©. 
         [0005]    Polygons are simple primitives, virtually used by almost all rendering tools, as their basic primitives. Typically, polygons are approximated from other geometric representations such as spline (curved) surfaces. Then, scenes are typically converted into polygons, usually triangles. The main advantage of polygonal representation is that it is more efficient than other types of graphic representations for rendering and picture making needs. 
         [0006]    Rendering of 3D computer graphics consists of several stages that each individual polygon of the 3D model undergoes. First hidden surface removal, transformation and projection of the polygons are performed, thereby creating the desired image. These steps are followed by shading and/or texture mapping of the polygons. Finally, the polygons are painted according to their position in the image. 
         [0007]    The present invention is focused on the shading and texture mapping steps of the process described shortly above. Furthermore, since the polygons are usually triangular, all polygons are referred to as such, though, as would be understood by those familiar with the art, the method proposed by the present invention can be used for any polygon, disregarding its shape. 
         [0008]    The simplest shading technique of computer generated images is known in the art as flat shading. When a triangle T(p 1 ,p 2 ,p 3 ) is flat shaded, it is filled with a single fixed color, and thus, the polygon looks flat. However, although flat shading is computationally efficient, the quality of the generated images is relatively low. 
         [0009]    An improved shading technique is known in the art as Gouraud shading. Gouraud shading is used to simulate the differing effects of light and color across the surface of an object. It achieves smooth shading on polygon surfaces without requiring relatively heavy computational operations for calculating the shading for each pixel. 
         [0010]    According to the Gouraud shading technique, three different shading levels are assigned to the three vertices (p 1 ,p 2 ,p 3 ) of each triangle T(p 1 ,p 2 ,p 3 ). These shading levels are linearly interpolated in the interior of the triangle. The basic principle behind this technique is to calculate the surface normals at the vertices of the polygons in a 3D computer model. These normals can be computed as an average of all polygons&#39; normals that share this specific vertex in the model, or as the precise normal of the smooth model at that location. Lighting computations, usually based on the Lambertian diffuse lighting model, are then performed to produce color intensities at each point (information related to the Lambertian diffuse lighting model may be found, for example, at http://en.wikipedia.org/wiki/Lambertian_diffuselighting_model). 
         [0011]    The generated color values are then interpolated along the edges of the polygons. To complete the shading, the image is filled by lines drawn across the image that interpolate between the previously calculated edge intensities. 
         [0012]    In order to support Gouraud shading, modern computers typically include special hardware that is capable of performing all of the necessary color interpolations in the interior of the polygon. Furthermore, the Gouraud method, as known today, is inherently related to 3D graphics, and thus, applications supporting only 2D graphics cannot use Gouraud shading. 
         [0013]    It would therefore be highly desirable to allow any computer application to utilize the smooth Gouraud shading technique using 2D features. 
         [0014]    The present invention relates to the texture mapping of graphic models as well. One of the most common texture mapping techniques builds a bi-variate parameterization from a rectangular, i.e., parametric, domain, to the surface of the model. Such a technique is generally displayed in  FIG. 1 . 
         [0015]    Rectangle J, which is a 2D parametric domain mapped to the unit square [0,1]x[0,1], is filled with the texture which will ultimately be mapped onto model M. Parametric coordinates (u,v), u,vε[0,1] are assigned to every point P i  in triangle T in model M, in the 2D parametric domain J. This is true for all triangles in M, so that every triangle in M covers some triangular domain in J, and all of the triangles in M together capture all (or portions of) 2D parametric domain J. 
         [0016]    Although many contemporary personal computers support texture mapping using special hardware graphics which essentially paint model M, pixel by pixel, according to a 2D parametric domain J, not all computer applications support such texture mapping. MFT for example, does not provide such tools. MFT, and the like, provide graphic tools for texture mapping of 2D simple models only, but not 3D models. 
         [0017]    Therefore it would be highly desirable to be able to exploit 2D image processing applications in order to cover an entire 3D model with texture. 
         [0018]    It is an object of the present invention to provide a method by which Gouraud shading of 3D models can be performed using the ordinary features of 2D graphics packages. 
         [0019]    It is a further object of the present invention to provide a method by which the texture mapping of 3D graphic models can be performed using ordinary 2D tools. 
         [0020]    Additional purposes and advantages of this invention will become apparent as the description proceeds. 
       SUMMARY OF THE INVENTION 
       [0021]    The present invention is directed to a method for shading 3D graphic models using 2D graphic tools, wherein the 3D graphic model is constructed of any number of polygons. Each polygon is subdivided into triangles, while mapping the spatial orientation and scaling of each triangle to a predetermined spatial orientation and scale, using a combination of rotation, scaling, and linear translation. Each mapped triangle is shaded using 2D linear or bi-linear coloring map shading tools and then remapped to its original spatial orientation and scale using, a corresponding combination of rotation, scale, and linear translation, such as an inverse combination. 
         [0022]    Preferably, mapping and remapping of each triangle is performed according to the linear transformation matrix 
         [0000]    
       
         
           
             
               [ 
               
                 
                   
                     
                       rs 
                       11 
                     
                   
                   
                     
                       rs 
                       12 
                     
                   
                   
                     0 
                   
                 
                 
                   
                     
                       rs 
                       21 
                     
                   
                   
                     
                       rs 
                       22 
                     
                   
                   
                     0 
                   
                 
                 
                   
                     
                       t 
                       x 
                     
                   
                   
                     
                       t 
                       y 
                     
                   
                   
                     1 
                   
                 
               
               ] 
             
             , 
           
         
       
     
         [0000]    wherein rs ij  represent the rotation and scale, and t i  represents the translation. The linear transformation matrix can be derived by any appropriate method. 
         [0023]    The linear transformation matrix may be derived by stretching a line from one vertex of the triangle to a point on the opposite edge of the triangle, such that the intensity of the color of the vertex and the point are identical. Then the triangle is rotated, so that the line is parallel to the y axis, thereby setting x to be constant. The triangle is translated so that the line is located at x=0 and then scaled, so that the Euclidean distance between the vertex placed at x&lt;0 and the line equals the difference in the intensities of the vertex placed at x&lt;0 and the line. Finally, the triangle is translated, so that the line is positioned at the x with the desired intensity value of the line. 
         [0024]    The present invention is also directed to a method for texture mapping 3D graphic models using 2D graphic tools, wherein the 3D graphic model is constructed of any number of polygons. Each polygon is subdivided into triangles, while mapping the spatial orientation and scaling of each triangle to a predetermined spatial orientation and scale, using a combination of rotation, scaling, and linear translation. Texture mapping is performed on each mapped triangle using 2D linear or bi-linear coloring map shading tools and then remapped to its original spatial orientation and scale using, a corresponding combination of rotation, scale, and linear translation, such as an inverse combination. 
         [0025]    The linear transformation matrix may be derived according to a 2D parametric domain by translating the triangle so that one of its vertices is at the origin, translating the 2D parametric domain so that the point in the domain which is to be mapped onto the vertex is at the origin and then finding (2×2) linear transform that maps the correct vectors in the domain to the two vectors of the triangle which join at the vertex of the triangle, placed at the origin. 
         [0026]    All the above and other characteristics and advantages of the invention will be further understood through the following illustrative and non-limitative description of preferred embodiments thereof. 
     
    
     
       BRIEF DESCRIPTION OF DRAWINGS 
         [0027]      FIG. 1  schematically the general scheme of texture mapping a 3D model from a 2D parametric domain; 
           [0028]      FIG. 2   a  schematically shows a triangle representing one of the polygons of the 3D graphic model; and 
           [0029]      FIGS. 2   b - 2   e  schematically describe the steps of the method of shading a triangle, according to the present invention. 
       
    
    
     DETAILED DESCRIPTION OF PREFERRED EMBODIMENTS 
       [0030]    In light of the drawbacks of the prior art regarding 2D shading and texture mapping techniques (e.g., 2D linear or bi-linear coloring map shading tools), there is a need for an improved method by which 2D applications can be used for shading and texture mapping graphic models in a manner which will allow those models to appear to be 3D. 
         [0031]    The present invention relates to the implementation of the smooth Gouraud shading technique in computer environments which do not support 3D graphics. This is achieved by using linear gradients, where in the context of the present invention linear gradients are color maps that linearly interpolate between two different colors. 
         [0032]    In many applications, such as MFT, the color map is defined canonically in [−1,1]x[−1,1]. That is, when relating to the two colors C 1  and C 2 , color C 1  is mapped to x=−1 and color C 2  is mapped to x=1. In 2D applications such as MFT, a canonical linear gradient could be mapped to any location, orientation, and scaled within the graphical model via the following linear transformation: 
         [0000]    
       
         
           
             
               
                 
                   
                     [ 
                     
                       
                         
                           
                             rs 
                             11 
                           
                         
                         
                           
                             rs 
                             12 
                           
                         
                         
                           0 
                         
                       
                       
                         
                           
                             rs 
                             21 
                           
                         
                         
                           
                             rs 
                             22 
                           
                         
                         
                           0 
                         
                       
                       
                         
                           
                             t 
                             x 
                           
                         
                         
                           
                             t 
                             y 
                           
                         
                         
                           1 
                         
                       
                     
                     ] 
                   
                   , 
                 
               
               
                 
                   ( 
                   1 
                   ) 
                 
               
             
           
         
       
     
         [0000]    wherein rs ij  define the rotation and scale, and t i  define the translation. Since the model is a 2D model, it is rotated, scaled and translated only in the x-y plane. The present invention shows how such simple linear transformations can be used to implement Gouraud shading technique to any 3D (projected) graphic model using 2D tools, such as 2D linear or bi-linear coloring map shading tools. 
         [0033]      FIG. 2   a  shows a triangle T, wherein P 1 , P 2 , and P 3  are its three vertices. When shading triangle T, the intensity of the color of each point P i  in the triangle, including the points on its edges, is I i . Assuming, without loss of generality, that the intensity at P 1  is less than, or equal to, the intensity at P 2 , which in turn is less than, or equal to, the intensity at P 3 , meaning that I 1 ≦I 2  and I 2 ≦I 3 . Since vertices P 1  and P 3  are at the two ends of one edge of triangle T, and the color intensity changes gradually and continuously between them, there must be a point P 4  on edge P 1 P 3  with intensity I 2 . 
         [0034]    Point P 4  can be defined by P 4 =tP 3 +(1−t)P 1 , wherein t=(I 2 −I 1 )/(I 3 −I 1 ). Being on the line through edge P 1 P 3 , point P 4  could be expressed as the above linear combination of P 1  and P 3 , for some t. Since the intensity along edge P 1 P 3  changes linearly from I 1  to I 3 , the t selects the location along edge P 1 P 3  where the intensity assumes the value of I 2 . 
         [0035]    Once the transformation matrix and P 4  are defined as described hereinabove, the following transformation steps are performed, such that triangle T is gradually painted by the canonical linear gradient, so that every point P 1  is painted in intensity I i :
       1. rotate triangle T (along arc R, shown in  FIG. 2   a ) so that line P 2 P 4  is parallel to the y axis, thereby setting x to be constant;   2. translate triangle T so that line P 2 P 4  is at x=0;   3. scale triangle (possibly in x only) so that the Euclidean distance from point P 1  to line P 2 P 4  (shown in  FIG. 2   d  as h) equals the color/intensity distance I 2 −I 1 . In other words, transformation matrix (1), shown hereinabove, relates the x coordinates in the drawing space to intensities in the color gradient space, thus the x-axis has a dual relation, relating both to distance and to intensities;   4. translate triangle T so that line P 2 P 4  is positioned at x=I 2 .       
 
         [0040]    These four steps are schematically shown in  FIGS. 2   b - 2   e.    
         [0041]    Once the above steps are mapped into a product of several matrices yielding linear transform matrix (1), triangle P 1 P 2 P 4  will be properly shaded. That is, P 1  is shaded in intensity I 1 , P 2  is shaded in intensity I 2 , and P 4  is shaded in intensity I 4 . The shading is performed using a linear color gradient and all of the vertices of triangle P 1 P 2 P 4  are shaded correctly, so that any point P i  in triangle P 1 P 2 P 4  is shaded with an intensity of I i . 
         [0042]    However, according to steps 1-4 listed above, not only triangle P 1 P 2 P 4  will be shaded correctly, but also point P 3 , and with it triangle P 2 P 4 P 3 . To realize this result it is noted (as shown in  FIG. 2   a ) that edge P 1 P 4  (and hence edge P 1 P 3 ) is a line in the canonical linear color gradient. Therefore, the color along this line changes linearly, wherein the intensity at P 1  is I 1  and at P 4  the intensity rises to I 4 . As would be understood by those familiar with the art, in cases where the intensity is prescribed at two places along a line, in this case, at points P 1  and P 4 , it is fully prescribed along the entire line, including P 3 . 
         [0043]    The fact that the intensity at P 3 , I(P 3 ), is equal to I 3 , can be proven by using the definition of P 4  (with intensity I 4 =I 2 ) presented above: 
         [0000]    
       
         
           
             
               
                 
                   
                     I 
                      
                     
                       ( 
                       
                         P 
                         3 
                       
                       ) 
                     
                   
                   = 
                   
                     
                       I 
                       1 
                     
                     + 
                     
                       
                         ( 
                         
                           
                             I 
                             2 
                           
                           - 
                           
                             I 
                             1 
                           
                         
                         ) 
                       
                        
                       
                         
                            
                           
                             
                               P 
                               3 
                             
                             - 
                             
                               P 
                               1 
                             
                           
                            
                         
                         
                            
                           
                             
                               P 
                               4 
                             
                             - 
                             
                               P 
                               1 
                             
                           
                            
                         
                       
                     
                   
                 
               
             
             
               
                 
                   = 
                   
                     
                       I 
                       1 
                     
                     + 
                     
                       
                         ( 
                         
                           
                             I 
                             2 
                           
                           - 
                           
                             I 
                             1 
                           
                         
                         ) 
                       
                        
                       
                         
                            
                           
                             
                               P 
                               3 
                             
                             - 
                             
                               P 
                               1 
                             
                           
                            
                         
                         
                            
                           
                             
                               t 
                                
                               
                                   
                               
                                
                               
                                 P 
                                 3 
                               
                             
                             + 
                             
                               
                                 ( 
                                 
                                   1 
                                   - 
                                   t 
                                 
                                 ) 
                               
                                
                               
                                 P 
                                 1 
                               
                             
                             - 
                             
                               P 
                               1 
                             
                           
                            
                         
                       
                     
                   
                 
               
             
             
               
                 
                   = 
                   
                     
                       I 
                       1 
                     
                     + 
                     
                       
                         ( 
                         
                           
                             I 
                             2 
                           
                           - 
                           
                             I 
                             1 
                           
                         
                         ) 
                       
                        
                       
                         
                            
                           
                             
                               P 
                               3 
                             
                             - 
                             
                               P 
                               1 
                             
                           
                            
                         
                         
                            
                           
                             t 
                              
                             
                               ( 
                               
                                 
                                   P 
                                   3 
                                 
                                 - 
                                 
                                   P 
                                   1 
                                 
                               
                               ) 
                             
                           
                            
                         
                       
                     
                   
                 
               
             
             
               
                 
                   = 
                   
                     
                       I 
                       1 
                     
                     + 
                     
                       
                         
                           I 
                           2 
                         
                         - 
                         
                           I 
                           1 
                         
                       
                       t 
                     
                   
                 
               
             
             
               
                 
                   = 
                   
                     
                       I 
                       1 
                     
                     + 
                     
                       
                         
                           I 
                           2 
                         
                         - 
                         
                           I 
                           1 
                         
                       
                       
                         
                           
                             I 
                             2 
                           
                           - 
                           
                             I 
                             1 
                           
                         
                         
                           
                             I 
                             3 
                           
                           - 
                           
                             I 
                             1 
                           
                         
                       
                     
                   
                 
               
             
             
               
                 
                   = 
                   
                     
                       I 
                       1 
                     
                     + 
                     
                       I 
                       3 
                     
                     - 
                     
                       I 
                       1 
                     
                   
                 
               
             
             
               
                 
                   = 
                   
                     I 
                     3 
                   
                 
               
             
           
         
       
     
         [0044]    When I 1 =I 2 , or I 2 =I 3 , or I 1 =I 2 =I 3 , the mathematical treatment is a bit different. However, realizing that in those singular cases P 4  identifies with P 1  or P 3 , or both, it is understood that the mathematical procedure in those cases is simpler. Finally, edges P 1 P 2 , P 1 P 3 , P 2 P 3  all have colors that are linearly interpolated between the two end points, being merely lines inside the linear color gradient. 
         [0045]    As shown above, linear color gradients can be efficiently used to shade any triangle with any three intensities at its three vertices, using only one linear transformation. This is true whether the three intensities are all different from one another, or whether there are any identities between them. 
         [0046]    When attempting to shade the entire graphic model, one canonical linear color gradient is defined for the model, based on its color, and each polygon within the model is painted or shaded using a specific linear transform, as defined in Equation (1). If the viewer&#39;s eye moves around the objects of the model, while the light source remains fixed with respect to the object, the matrices, (i.e., the intensities), are computed only once. However, in cases where the intensity is dependent on the view direction, and thus is known only at run-time, it is necessary to reevaluate these matrices in every iteration. 
         [0047]    Although the above refers to Gouraud shading, the present invention is not limited only to this technique. Although currently MFT and similar applications support only linear color gradient, bi-linear color gradients that blend between orthogonal colors in the plane could also be used according to the present invention. The development of bi-color linear gradients would allow various types of more complex shading techniques using the method of the present invention. 
         [0048]    Another aspect of the present invention is that of texture mapping. According to the present invention, ordinary 2D tools, existing in applications such as MFT, are used to map texture onto 3D graphic models. 
         [0049]    Referring to  FIG. 1 , every point P 1  in triangle T(P 1 ,P 2 ,P 3 ) must be matched to the (u,v) coordinates of domain J so that point P 1  matches the coordinate UV i . In order to map texture correctly from 2D parametric domain J to model M, (UV 1 ,UV 2 ,UV 3 ) must be mapped to (P 1 ,P 2 ,P 3 ). 
         [0050]    According to the method of the present invention the correct texture mapping is achieved by the following steps:
       1. translate triangle T so that P 1  is at the origin (denoting this matrix transform M 1 );   2. translate the UV domain so that UV 1  is at the origin; (denoting this matrix transform M 2 ;   3. find the (2×2) linear transform, denoted M 3 , that maps 2D vectors       
 
         [0054]    UV 12 =UV 2 −UV 1  and UV 13 =UV 3 −UV 1  to 2D vectors P 12 =P 2 −P 1  and P 13 =P 3 −P 1 , respectively. As would be understood by those familiar with the art there are four degrees of freedom and four independent unknowns, in the general case of non-singular, degenerate, constraints, thus a unique solution exists. This solution could be found, for example, by posing this problem as the following linear system of constraints. Let 
         [0000]    
       
         
           
             
               M 
               3 
             
             = 
             
               
                 [ 
                 
                   
                     
                       
                         m 
                         3 
                         11 
                       
                     
                     
                       
                         m 
                         3 
                         12 
                       
                     
                   
                   
                     
                       
                         m 
                         3 
                         21 
                       
                     
                     
                       
                         m 
                         3 
                         22 
                       
                     
                   
                 
                 ] 
               
               . 
             
           
         
       
     
         [0055]    Then, solve for the four m 3   ij  coefficients of M 3  using the following four constraints: 
         [0000]    
       
         
           
               
             
               { 
               
                 
                   
                     
                       
                         
                           P 
                           12 
                         
                         = 
                         
                           
                             M 
                             3 
                           
                           · 
                           
                             UV 
                             12 
                           
                         
                       
                       , 
                     
                   
                 
                 
                   
                     
                       
                         P 
                         13 
                       
                       = 
                       
                         
                           M 
                           3 
                         
                         · 
                         
                           
                             UV 
                             13 
                           
                           . 
                         
                       
                     
                   
                 
               
             
           
         
       
     
         [0056]    The above steps of translation and linear (2×2) mapping are described as a product of matrices M i , i=1, 2, 3, yielding linear transform matrix (1), as M=M 2  M 3  M 1   −1 . M 2  maps the UV i  coordinates into the origin, M 3  deforms the plane so the vectors points to the proper direction, and finally M 1   −1  brings the coordinates back from the origin to P i . Following the above steps ensures that triangle T, seen in  FIG. 1 , will be properly painted with the texture as prescribed by the texture triangle (UV 1 ,UV 2 ,UV 3 ), defined in 2D parametric domain J. 
         [0057]    In light of the above, it would be understood to those familiar in the art that the present invention enables the handling and display of 3D geometry generated by software applications, such as Maya© and 3D Studio Max©, in pure 2D graphic systems, such as MFT. 
         [0058]    Although the above refers to the shading and texture mapping of triangles it would be understood by those familiar with the art that the method of the present invention can be applied to any n-sided shaped polygon, which can be subdivided by any suitable graphics algorithm into n−2 (or more) triangles. 
         [0059]    Although embodiments of the present invention have been described by way of illustration, it will be understood that the invention may be carried out with many variations, modifications, and adaptations, without departing from its spirit or exceeding the scope of the claims.