home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 3585 < prev    next >
Encoding:
Text File  |  1996-08-05  |  5.0 KB  |  113 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: news.si.hhs.nl!news
  3. From: Patrick van Logchem <v912152@si.hhs.nl>
  4. Subject: Re: TMapping again!
  5. Content-Type: text/plain; charset=us-ascii
  6. Message-ID: <312990E8.5622@si.hhs.nl>
  7. Sender: news@si.hhs.nl
  8. Content-Transfer-Encoding: 7bit
  9. Organization: Haagse Hogeschool, Sector Informatica
  10. References: <38232371@kone.fipnet.fi> <4fntd3$g56@sunsystem5.informatik.tu-muenchen.de> <38232442@kone.fipnet.fi> <4fvqh6$na2@sunsystem5.informatik.tu-muenchen.de> <38232459@kone.fipnet.fi> <4gbb5a$104@sunsystem5.informatik.tu-muenchen.de>
  11. Mime-Version: 1.0
  12. Date: Tue, 20 Feb 1996 09:14:16 GMT
  13. X-Mailer: Mozilla 2.0 (X11; I; SunOS 5.3 sun4m)
  14.  
  15. Hi guys, I'm new on this subject, but I like those darn optimizations,
  16. and I think you goofed up on this gouraud-shading texturemapper-routine:
  17.  
  18. >       move.w  d1,d2           ;set texture ypos
  19. >       addx.l  d4,d1           ;step in texture
  20. >       move.b  d0,d2           ;set texture xpos
  21. >       move.l  d2,a0           ;texel adress
  22.                 ^^^^^ [1a]
  23. >       move.l  a2,d2           ;lighting table
  24.                 ^^^^^ [1b]
  25. >       addx.l  d3,d0           ;step in texture
  26. >       move.b  (a0),d2         ;Set texel in lighting table
  27. >       move.l  d2,a0           ;Get lighting*texel adr in a useable reg
  28.                 ^^^^^ [2]
  29. >       move.b  (a0),(a1)+      ; write lighted texel
  30. >       adda.l  a3,a2           ; next light value
  31.  
  32. The mistake is: your original [1a] d2 texture-high-word is overwritten
  33. [1b]. Changing this to:
  34.         move.w  a2,d2
  35. won't help, because the high-word is needed at [2] as a shading-table
  36. pointer.
  37.  
  38. Alas, there is only one solution: use an extra register. Here is my
  39. version, (in which I choose to use a4) _with_ pipe-line optimalization:
  40.  
  41.         move.w  d1,d2  ; Set y-position texture (fixed-point 16.8)
  42.         addx.l  d4,d1  ; ..and increase.
  43.         move.b  d0,d2  ; Set x-position texture (fixed-point 16.16)
  44.         addx.l  d3,d0  ; ..and increase.
  45.         move.w  d2,a0  ; Create texture-pointer.
  46.         move.l  a2,d2  ; Get shading-table pointer (fixed-point adres).        
  47.     ; only stall happens here (another write to d2):
  48.         move.b  (a0),d2  ; Get texel; use as index into shading table.
  49.         adda.l  a3,a2  ; Increase shading pointer (fixed-point adres).
  50.         move.l  d2,a4  ; Create shading-pointer.
  51.         move.b  (a4),(a1)+  ; Write shaded texel to screen.
  52.  
  53. As you can see, I use three different kinds of fixed-point math:
  54. - the y-position: 16 bits fraction, 8 counter, 8 (semi?) fraction
  55. - the x-position: 24 bits fraction, 8 counter.
  56. - the shading-table: 24 bits pointer, 8 fraction.
  57. This code still works on 68000.
  58.  
  59. But why don't you guys use this one (my invention, so reward me with a
  60. copy of the program you're using this in!), which only works 020+ :
  61.  
  62.         move.w  d1,d2      ; Set y-position texture.
  63.         addx.l  d4,d1      ; Increase y-position.
  64.         move.b  d0,d2      ; Set x-position texture.
  65.         move.l  a2,d5      ; Create a copy of the shading-table pointer.
  66.         addx.l  d3,d0      ; Increase x-position.
  67.         move.b  (d2),d5    ; Get texel; use as index into shading table.
  68.         adda.l  a3,a2      ; Increase shading pointer.
  69.         move.b  (d5),(a1)+ ; Write shaded texel to screen.
  70.  
  71. ...shorter program (instruction _and_ byte-wise), faster execution,
  72. less register-usage, no pipe-line stalls...
  73. (Note the "(dX)", this one should execute just as fast as an "(aX)",
  74. right?)
  75.  
  76. A little explanation for those who don't get it:
  77. Really needed:
  78.         d0 = x-position, 24.8 fixed-point
  79.         d1 = y-position, 16.8(8) fixed point
  80.         d2 = pointer to texture (on 64K boundary)
  81.         d3 = x-increase, 24.8 fixed-point
  82.         d4 = y-increase, 16.8(8) fixed-point
  83.         a1 = pointer to destination chunky buffer
  84.         a2 = pointer to shading-table (on 256 bytes boundary)
  85.         a3 = shading-increase 24 real, 8 fraction
  86. Extra used register:
  87.         d5 = a copy into shading-table, replacing low 8 bits with offset
  88. Free registers:
  89.         d6,d7,a0,a4,a5,a6 (a7)
  90.  
  91. About this 16.8(8) fixed-point math: It's only a hack, just roll your
  92. 24.8 fixed-point number 8 bits left E voila!
  93.  
  94. About the 24.8 bits fixed-point shading-pointer; Another hack: the
  95. shading-table should start on a 256 byte boundary so the low 8 bits can
  96. be used as an offset; enabling me to use the original 8 bits in this
  97. shade-table-pointer as the fixed-point part (!). Disadvantage is that
  98. spans with a width more than 256 get twisted (but they would do that
  99. anyways).
  100.  
  101. The math has high precision in the x and y texture-counters, only the
  102. shading is a little rude, but won't be noticed too much. Face it: it's
  103. only a table that shades 256 colors in 256 levels to another pallet of
  104. just 256 colors: not a really accurate shading indeed!
  105.  
  106. F E E D B A C K !   :)
  107.  
  108. --
  109. Patrick van Logchem                     | "... and there is madness in
  110. CD-i developer                          | their heart during their life,
  111. patrick@usn.nl patrick@pop3.dh.ixe.net  | and then - to the death!"
  112. http://www.si.hhs.nl/~v912152/home.html |               --  Preacher 9:3
  113.