home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: news.si.hhs.nl!news
- From: Patrick van Logchem <v912152@si.hhs.nl>
- Subject: Re: TMapping again!
- Content-Type: text/plain; charset=us-ascii
- Message-ID: <312990E8.5622@si.hhs.nl>
- Sender: news@si.hhs.nl
- Content-Transfer-Encoding: 7bit
- Organization: Haagse Hogeschool, Sector Informatica
- 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>
- Mime-Version: 1.0
- Date: Tue, 20 Feb 1996 09:14:16 GMT
- X-Mailer: Mozilla 2.0 (X11; I; SunOS 5.3 sun4m)
-
- Hi guys, I'm new on this subject, but I like those darn optimizations,
- and I think you goofed up on this gouraud-shading texturemapper-routine:
-
- > move.w d1,d2 ;set texture ypos
- > addx.l d4,d1 ;step in texture
- > move.b d0,d2 ;set texture xpos
- > move.l d2,a0 ;texel adress
- ^^^^^ [1a]
- > move.l a2,d2 ;lighting table
- ^^^^^ [1b]
- > addx.l d3,d0 ;step in texture
- > move.b (a0),d2 ;Set texel in lighting table
- > move.l d2,a0 ;Get lighting*texel adr in a useable reg
- ^^^^^ [2]
- > move.b (a0),(a1)+ ; write lighted texel
- > adda.l a3,a2 ; next light value
-
- The mistake is: your original [1a] d2 texture-high-word is overwritten
- [1b]. Changing this to:
- move.w a2,d2
- won't help, because the high-word is needed at [2] as a shading-table
- pointer.
-
- Alas, there is only one solution: use an extra register. Here is my
- version, (in which I choose to use a4) _with_ pipe-line optimalization:
-
- move.w d1,d2 ; Set y-position texture (fixed-point 16.8)
- addx.l d4,d1 ; ..and increase.
- move.b d0,d2 ; Set x-position texture (fixed-point 16.16)
- addx.l d3,d0 ; ..and increase.
- move.w d2,a0 ; Create texture-pointer.
- move.l a2,d2 ; Get shading-table pointer (fixed-point adres).
- ; only stall happens here (another write to d2):
- move.b (a0),d2 ; Get texel; use as index into shading table.
- adda.l a3,a2 ; Increase shading pointer (fixed-point adres).
- move.l d2,a4 ; Create shading-pointer.
- move.b (a4),(a1)+ ; Write shaded texel to screen.
-
- As you can see, I use three different kinds of fixed-point math:
- - the y-position: 16 bits fraction, 8 counter, 8 (semi?) fraction
- - the x-position: 24 bits fraction, 8 counter.
- - the shading-table: 24 bits pointer, 8 fraction.
- This code still works on 68000.
-
- But why don't you guys use this one (my invention, so reward me with a
- copy of the program you're using this in!), which only works 020+ :
-
- move.w d1,d2 ; Set y-position texture.
- addx.l d4,d1 ; Increase y-position.
- move.b d0,d2 ; Set x-position texture.
- move.l a2,d5 ; Create a copy of the shading-table pointer.
- addx.l d3,d0 ; Increase x-position.
- move.b (d2),d5 ; Get texel; use as index into shading table.
- adda.l a3,a2 ; Increase shading pointer.
- move.b (d5),(a1)+ ; Write shaded texel to screen.
-
- ...shorter program (instruction _and_ byte-wise), faster execution,
- less register-usage, no pipe-line stalls...
- (Note the "(dX)", this one should execute just as fast as an "(aX)",
- right?)
-
- A little explanation for those who don't get it:
- Really needed:
- d0 = x-position, 24.8 fixed-point
- d1 = y-position, 16.8(8) fixed point
- d2 = pointer to texture (on 64K boundary)
- d3 = x-increase, 24.8 fixed-point
- d4 = y-increase, 16.8(8) fixed-point
- a1 = pointer to destination chunky buffer
- a2 = pointer to shading-table (on 256 bytes boundary)
- a3 = shading-increase 24 real, 8 fraction
- Extra used register:
- d5 = a copy into shading-table, replacing low 8 bits with offset
- Free registers:
- d6,d7,a0,a4,a5,a6 (a7)
-
- About this 16.8(8) fixed-point math: It's only a hack, just roll your
- 24.8 fixed-point number 8 bits left E voila!
-
- About the 24.8 bits fixed-point shading-pointer; Another hack: the
- shading-table should start on a 256 byte boundary so the low 8 bits can
- be used as an offset; enabling me to use the original 8 bits in this
- shade-table-pointer as the fixed-point part (!). Disadvantage is that
- spans with a width more than 256 get twisted (but they would do that
- anyways).
-
- The math has high precision in the x and y texture-counters, only the
- shading is a little rude, but won't be noticed too much. Face it: it's
- only a table that shades 256 colors in 256 levels to another pallet of
- just 256 colors: not a really accurate shading indeed!
-
- F E E D B A C K ! :)
-
- --
- Patrick van Logchem | "... and there is madness in
- CD-i developer | their heart during their life,
- patrick@usn.nl patrick@pop3.dh.ixe.net | and then - to the death!"
- http://www.si.hhs.nl/~v912152/home.html | -- Preacher 9:3
-