<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Perspective-Correct Computation Pixels Color for Systems of Three-Dimensional Rendering</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Oleksandr Romaniuk</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Oleksandr Dudnyk</string-name>
          <email>dudnyk@vntu.edu.ua</email>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Serhii Pavlov</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Olena Tsikhanovska</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Biomedical Engineering, Vinnytsia National Technical University, UKRAINE</institution>
          ,
          <addr-line>Vinnytsia, 95 Khmelnytske shose</addr-line>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Department of Economics of Enterprises and Corporations, The Vinnytsyia Educational and Research Institute of Economics</institution>
        </aff>
        <aff id="aff2">
          <label>2</label>
          <institution>Department of Software Engineering, Vinnytsia National Technical University, UKRAINE</institution>
          ,
          <addr-line>Vinnytsia, 95 Khmelnytske shose str.</addr-line>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2018</year>
      </pub-date>
      <fpage>1</fpage>
      <lpage>3</lpage>
      <abstract>
        <p>In computer graphics, the projections of three-dimensional images are considered on a twodimensional picture plane. Flat geometric projections are divided into two main classes: central and parallel. The difference between them is determined by the relationship between the center of the projection and the projection plane. If the distance between them is finite, then the projection will be central, and if it is infinite, then the projection will be parallel. In real space reflection of rays from objects is perceived at the location of the observer, that is, on the principle of central projection. Correct reproduction of colors takes place provided that the components of the color intensities of the corresponding surface points in the global (object) and screen coordinate systems coincide. The authors propose methods to improve the performance of texture mapping and realism of shading, in particular, the methods perspective-correct texturing and Phong shading.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>I. INTRODUCTION</title>
      <p>When forming graphical images is solved by a twofold
task – improve performance and enhance realism. Today the
performance of graphical tools sufficient for the formation of
images according to their visual properties similar to the
photos, you have achieved photographic quality.</p>
      <p>To ensure high realism is important to consider the
perspective transformation of polygons in the determination
of pixel colors: in the texture mapping and shading.</p>
      <p>The perspective-correct formation of colors is used both
for shading and texture mapping.</p>
      <p>When coloring the surfaces of three-dimensional objects,
the methods of Gourund and Phong are most often used. The
question of the prospective correct reproduction of colors
according to these methods is considered, respectively, in [1,
2, 3].</p>
      <p>In the tasks of texturing, you need to find the relationship
between the screen coordinates and texture coordinates. In
order to ensure high productivity, the linear and quadratic
functions are often used in perspective-correct texture
mapping [4, 5]. In such approaches, a molded image may
have artifacts and does not always faithfully reproduce the
perspective of an object. In order to increase the realism of
perspective-correct texturing [4, 5, 6], use of nonlinear
functions, the calculation of which involves the
implementation of labor-intensive operations.</p>
      <p>II. SHADING WITH THE PERSPECTIVE</p>
      <p>Ignoring the depth of the object in the calculation of the
vectors leads to error computing its orthogonal components,
which can be calculate by the formula
∆ I = I A + ( I B − I A ) ⋅</p>
      <p>u ⋅ z1
z2 − u ⋅ ( z2 − z1 )</p>
      <p>
        − I A −
u ⋅ z1
z2 − u( z2 − z1 )
1
),
−( I B − I A ) ⋅ u = ( I B − I A ) ⋅ ( u −
) =
(
        <xref ref-type="bibr" rid="ref1">1</xref>
        )
= ( I B − I A ) ⋅ u ⋅ ( 1 −
z z
2 + u(
        <xref ref-type="bibr" rid="ref1">1 − 2</xref>
        )
z1 z1
replacing the intensity value of the color value of the
orthogonal component.
      </p>
      <p>For perspective-correct reproduction of colors using Phong
shading it is necessary to use non-linear interpolation of
normal vectors using a variable tw . Unfortunately, the
calculation tw according to the formula [1]
tw =</p>
      <p>Z Àw ⋅ tv
Z Bw − tv ( ⋅Z Bw − Z Aw )
(2)
provides for the execution of a division operation for each
current value of tv . Consider the approximation of tv to
simplify the hardware implementation. Since the dependence
is nonlinear, using linear interpolation on the whole interval
variable is excluded.</p>
      <p>Approximation tw second degree
polynomial a ⋅ tv2 + b ⋅ tv + c. Find unknown a , b, c .
To do this we set up a system of equations using three points
=1, tv
=1 / 2.

c = 0 ,

a + b + c =1,
</p>
      <p>1
 ⋅ a +
 4
1
2
⋅ b + c =</p>
      <p>Z Àw
Z Bw
+ Z Aw
.</p>
      <p>The system has such a solution
a</p>
      <p>2 ⋅ ( Z Bw − Z Aw ) , b
=
( Z Bw + Z Aw )</p>
      <p>( 3 ⋅ Z Aw − Z Bw ) ,
=</p>
      <p>( Z Bw + Z Aw )
Z</p>
      <p>Z Aw
If  =</p>
      <p>Bw , then a
only for  ≤ 3 . In figure 1 shows a graph of change of the
absolute error of the approximation from tv ,  .</p>
      <p>error of the approximation from tv , </p>
      <p>Higher accuracy of approximation can be achieved if the
use of piecewise quadratic interpolation on two periods of
change tv . For 0 ≤ tv ≤ 0 ,5
For 0 ,5 &lt; tv ≤ 1
a =
8 ⋅ Z Aw ⋅ ( Z</p>
      <p>Bw − Z Aw )
( Z</p>
      <p>Bw + Z Aw ) ( 3 ⋅ Z
Âw + Z Aw )
,
b</p>
      <p>( 3 ⋅ Z Aw + Z Bw )
=
( Z Bw + Z Aw ) ( 3 ⋅ Z Âw + Z Aw )
, c
a =</p>
      <p>−8 ⋅ Z Bw ⋅ ( Z Aw − Z Bw )
( Z</p>
      <p>Bw + Z Aw ) ( 3 ⋅ Z
Âw + Z Aw )</p>
      <p>Bw ,
Âw + Z Aw )
3 ⋅ ( Z Aw − Z Bw )2
( Z</p>
      <p>Bw + Z Aw ) ( 3 ⋅ Z
Âw + Z Aw )
.</p>
      <p>The analysis showed that in this case  = 2, 3, 4 , 5 the
maximum modulus of the relative error does not exceed, 1% ,
4%, 8%, 13%. With regard to three-dimensional objects,  ,
as a rule, does not exceed 3.</p>
      <p>Consider using approximation by third-order polynomial
of the form a ⋅ tv3 + b ⋅ tv 2 + ct + d . For finding the
unknown we set up a system of four equations. To do this,
make the value of the polynomial equal tw (see formula 2) in
points tv = 0 , 1 / 3, 2 / 3, 1 . Find:
a =
b =
c =
9 ⋅ ( Z</p>
      <p>Bw − Z Aw )2
( 2 ⋅ Z Bw + Z Aw ) ⋅ ( Z</p>
      <p>Bw + 2 ⋅ Z Aw )
−9 ⋅ ( Z Bw − Z Aw ) ( Z
( 2 ⋅ Z Bw + Z Aw ) ⋅ ( Z</p>
      <p>Bw − 2 ⋅ Z Aw ) ,</p>
      <p>Bw + 2 ⋅ Z Aw )
( 2 ⋅ Z 2 Bw − 4 ⋅ Z Aw ⋅ Z Bw + 11 ⋅ Z Aw )
( 2 ⋅ Z Bw + Z Aw ) ⋅ ( Z</p>
      <p>Bw + 2 ⋅ Z Aw )</p>
      <p>.
ipniteTecrhepewoilaseati-noqanulyasdirasacthicisehvoeiwsnetedrbpeottlhtaeatriton.wachceFunorarcuyseixnacgmomptlpheae,redcwuhbetinoc
 = 2, 3, 4 , 5 the maximum modulus of the relative error
does not exceed, 0,64 %, 2,9 %, 6,3 %, 10,6 %.</p>
      <p>III. IMPROVING THE PERFORMANCE OF TEXTURING</p>
    </sec>
    <sec id="sec-2">
      <title>WITH PERSPECTIVE</title>
      <p>Finding texture coordinates is a time consuming procedure
because it requires the execution of complex operations for
each pixel according to the formula [4, 5].</p>
      <p>u =</p>
      <p>Ax + By + C
Gx + Hy + I
, v =</p>
      <p>Dx + Ey + F
Gx + Hy + I
=0.ui+1 =++11))++ AD1⋅⋅((xxii BE1 ⋅⋅ yyii ++ FC1
( A1 ⋅ xi + B1 ⋅ yi + C1 ) + A1 .
=
( D ⋅ xi + E ⋅ yi + F ) + D
u1
=1) A1 ⋅ ( x0 + + B1 ⋅ yi + C1</p>
      <p>D ⋅ ( x0 + 1) + E ⋅ yi + F
=A1+ A1 ⋅ x0 + B1 ⋅ yi + C1 .</p>
      <p>D ⋅ x0 + D + E ⋅ yi + F
A similar formula can be written for vn.</p>
      <p>v = A2 ⋅ xi + B2 ⋅ y0 + B2 ⋅ n + C
n D ⋅ xi + E ⋅ y0 + E ⋅ n + F</p>
      <p>wn = ut + A1 ⋅ n , vn = ub + D ⋅ n ,
then the division operation to calculate the coordinates
w
un =</p>
      <p>n .</p>
      <p>Since for each x, n is increased by 1, there is such a
formula:
wn
=wn−1 + A1 , vn
=vn−1 + D .</p>
      <p>(4)</p>
      <p>In accordance with the formulas (4), we can offer a
consistent algorithm for calculating texture coordinates: wn
and vn for each х calculated by adding to wn-1 and vn-1, that
was calculated for х-1, А1 and D. The sequence of operations
of the algorithm shown in figure 3.
=
(2)
(3)</p>
      <p>From the given formulas it is visible that for calculation
of each texel computer needs to perform 2 operations of
division, 8 operations of addition and 8 multiplications.</p>
      <p>As can be seen from formulas (2), the value of the
expressions A1 ⋅ x0 + B1 ⋅ yi + C1 and D ⋅ x0 + E ⋅ yi + F
for each n remain unchanged, and therefore can be calculated
once for each rasterization line using formula:</p>
      <p>
        ut = A1 ⋅ x0 + A1 ⋅ n + B1 ⋅ yi + C1 , ub = D ⋅ x0 + E ⋅ yi + F.
where ut and ub constant part of the numerator and
denominator of formula (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) in accordance.
      </p>
      <p>Therefore, un can be calculated according using the
formula
u + A1 ⋅ n
un = utb + D ⋅ n
.</p>
      <p>Thus, for calculating coordinates of all texels, variables,
u1t and u1b are constant, and their value is sufficient to
calculate once. Similarly you can calculate vn.</p>
      <p>This simplification reduces the number of operations of
addition and multiplication to 4 for each.</p>
      <p>Based on these mathematical relationships it is possible to
offer algorithm of parallel calculation of texels coordinates:
for each rasterization line at first calculates the parameters ut
and ub, then calculate values of the numerator and
denominator in parallel by the formula:
The computing of texture coordinates by this algorithm
can also be accelerated using parallel computing. One
possible approach to parallelization is the parallel
rasterization of several lines simultaneously. However, this
approach will not be productive enough in cases when the
number of pixels per row is much higher than the number of
rows. Therefore, it is advisable to use means of parallel
calculations within a single line.</p>
      <p>Let's consider parallel computing of cordiant texels for
pixels located at even and odd positions in the rasterization
line (fig. 4).
If wn
=w
n−1 + A1 , а vn</p>
      <p>=vn−1 + D then:
wn+1 = (wn−1 + A1 ) + A1 , vn+1 = (vn−1 + D) + D .</p>
      <p>Thus, parallel computation of the texture coordinates of
pixels on odd and even positions is possible according to the
formulas:</p>
      <p>wn =wn−2 + 2 A1 , vn =vn−2 + 2D . (5)</p>
      <p>In this case, the coordinates texels for the first two points
are defined by the formula (3).</p>
      <p>Based on the formulas (5) and (5) to establish the
relationship which allows parallel rasterization the line in an
random number of threads using formulas:
wn
=wn−k + kA1 , vn
=vn−k + kD ,
whre k – the number of concurrent threads.</p>
      <p>It is also possible a parallel calculation of the coordinates
in two streams by simultaneous rasterization of line in two
directions (fig. 5). From right to left according to the formula
(4), and from left to right according to the formula:
wn
=wn+1 − A1, vn
=vn+1 − D .</p>
      <p>Fig. 5. Parallel computation of the coordinates in the two streams
with a counter direction of rasterization</p>
      <p>The figure 6 show that the proposed method makes it
possible to increase productivity perspective-correct texturing
26%. Testing was conducted on the Intel i7 2600K CPU and
GPU AMD RX460.</p>
      <p>Proposed methods to improve the performance of texture
mapping and realism of shading, in particular, the methods
perspective-correct texturing and Phong shading.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          <source>[1] [2] [3] [4] [5]</source>
          [6]
          <string-name>
            <given-names>G. F.</given-names>
            <surname>Ahmed</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Barskar</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Bharti</surname>
          </string-name>
          , and
          <string-name>
            <given-names>N. S.</given-names>
            <surname>Rajput</surname>
          </string-name>
          , “
          <article-title>Content Base Image Retrieval Using Fast Phong Shading</article-title>
          ,”
          <source>2010 International Conference on Computational Intelligence and Communication Networks</source>
          ,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          <string-name>
            <given-names>R. F.</given-names>
            <surname>Lyon</surname>
          </string-name>
          , “
          <article-title>Phong Shading Reformulation for Hardware Renderer Simplification”</article-title>
          ,
          <source>Apple Technical Report #43, August</source>
          <volume>2</volume>
          ,
          <year>1993</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          <string-name>
            <given-names>D. A.</given-names>
            <surname>Kulagin</surname>
          </string-name>
          ,
          <article-title>"Models of shading. Flat model</article-title>
          .
          <source>Shading on Guro and Fong "</source>
          ,
          <source>Computer graphics. Theory</source>
          , algorithms, examples on C+
          <article-title>+</article-title>
          and OpenGL. [Online]. Available http://compgraphics.info/3 D/lighting/shading_model.php P. S. Heckbert, “Survey of Texture Mapping,
          <source>” IEEE Computer Graphics and Applications</source>
          , vol.
          <volume>6</volume>
          , no.
          <issue>11</issue>
          , pp.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          <string-name>
            <given-names>F.</given-names>
            <surname>Tsai</surname>
          </string-name>
          and
          <string-name>
            <given-names>H. C.</given-names>
            <surname>Lin</surname>
          </string-name>
          , “
          <article-title>Polygon‐ based texture mapping for cyber city 3D building models</article-title>
          ,”
          <source>International Journal of Geographical Information Science</source>
          , vol.
          <volume>21</volume>
          , no.
          <issue>9</issue>
          , pp.
          <fpage>965</fpage>
          -
          <lpage>981</lpage>
          ,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          <string-name>
            <given-names>X. U.</given-names>
            <surname>Ying</surname>
          </string-name>
          , “
          <article-title>An Improved Texture Rendering Technique Based on MipMap Algorithm”</article-title>
          ,
          <source>Journal of Mianyang</source>
          Normal University,
          <year>2013</year>
          ,
          <volume>5</volume>
          :
          <fpage>017</fpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>