RE: Re: OT: Z-buffering was Re: So long 2002, here comes 2003....

2003-01-14 Thread Tobermory
Thomas Harte wrote:
If you
store a table of square roots for the Pythagoras, it speeds up
nicely (big table, but hell, you'll already be storing
perspective correction tables and SINE tables, so you won't be
bothered about memory).

 There is an entire web page somewhere dedicated to getting fast
 sqrts. I've seen one  which uses only a 256 or 512 byte table but
 can do a 16bit sqrt in less than 100 cycles.

Have you got the URL for this??? I'm quite interested in how it's done.

-Howard




Re: Re: OT: Z-buffering was Re: So long 2002, here comes 2003....

2003-01-14 Thread Simon Cooke
Tobermory [EMAIL PROTECTED] scribbled:

 Thomas Harte wrote:
 If you
 store a table of square roots for the Pythagoras, it speeds up
 nicely (big table, but hell, you'll already be storing
 perspective correction tables and SINE tables, so you won't be
 bothered about memory).
 
 There is an entire web page somewhere dedicated to getting fast
 sqrts. I've seen one  which uses only a 256 or 512 byte table but
 can do a 16bit sqrt in less than 100 cycles.
 
 Have you got the URL for this??? I'm quite interested in how it's
 done. 

Prolly uses log tables and then iterates on the solution. Well, maybe :)

Simon


Re: Re: OT: Z-buffering was Re: So long 2002, here comes 2003....

2003-01-14 Thread Ian Collier
On Sun, Jan 12, 2003 at 01:46:52AM +0100, Thomas Harte wrote in widescreen:
 There is an entire web page somewhere dedicated to getting fast sqrts. I've 
 seen one 
 which uses only a 256 or 512 byte table but can do a 16bit sqrt in less than 
 100 cycles.

Don't know how that works, but just out of interest, the fastest
pure-code integer sqrt routine I know (producing an 8-bit number
from a 16-bit input) has a loop of a bit over 100 cycles executed
8 times.  It's based on this:

x=arg(1)/2**16
p=0
do 8 
   x=4*x  
   p=p+p
   if x = p+1 then do
  x=x-(p+1)
  p=p+2
   end
end
p=p/2
return p

imc (who isn't here really)


RE: Re: OT: Z-buffering was Re: So long 2002, here comes 2003....

2003-01-12 Thread Thomas Harte
 Just like PowerVR's gfx chips with tile rendering, which process
 the z-buffering for the screen in small blocks and render only
 what is visible.

This is common practice across all modern cards. A hierarchical approach is 
taken - there 
is a full z-buffer for all pixels, then a version with the farthest z for each 
group of 4 
pixels, a version with the farthest z for each group of 16, and so on, with the 
effect that 
large portions of triangles can often be thrown away, especially if the 
programmer has 
followed the modern convention of doing a loose front to back sort before 
drawing.

If you
store a table of square roots for the Pythagoras, it speeds up
nicely (big table, but hell, you'll already be storing perspective
correction tables and SINE tables, so you won't be bothered about
memory).

There is an entire web page somewhere dedicated to getting fast sqrts. I've 
seen one 
which uses only a 256 or 512 byte table but can do a 16bit sqrt in less than 
100 cycles.

You could also try doing a view frustum cull beforehand to reduce
the list to just visible objects, or take the easy route and just
make sure the objects are forward of the camera.  You count the
T-States and take your choice!

Elite has the very bad habit of culling all objects that even intersect the 
front plane. You 
don't usually notice, but try flying over the front of a space station.

Right now I'm tinkering with adding 'building block' sector coords
to each object, like a vague grid reference.  Then you could easily
apply a 'bitmapped' view frustum to search the main area for
potentially visible objects.  I'm not convinced yet, but it may
work

An octree does more or less this. Its a recursive structure, with the parent 
being a 
rectangle (the root node being the rectangle enclosing 'all' of space) and the 
children 
being 8 smaller rectangles. The game is that if a particular parent is entirely 
outside of 
the view frustum then you don't recurse, and if it is entirely inside the view 
frustum then 
you draw everything immediately. If it intersects the frustum (and the node has 
children) 
then you recurse.

By the way, with respect to Elite, I once partially reverse engineered the ZX 
Spectrum 
version, which is visibly identical to the SAM version implying that all that 
is running is the 
Spectrum code and a mode 1 screen. In which case we are seeing the following 
abuses 
of the SAM hardware :

- mode 1 display, with obvious effects on running speed
- software double buffering, even though in the SAM (and 128kb Spectrum, I 
believe) 
this can be achieved in hardware

If someone is planning on writing a new implementation of Elite for the SAM, 
then it might 
be worth noting that the original BBC Micro 6502 source has been released by 
Ian Bell 
but is nearly illegible. It has subsequently been converted into C using the 
Allegro 
graphics library by Christian Pinder, the source for which is available via 
http://www.newkind.co.uk (see Elite : The New Kind, rather than the other). I 
contributed the anti-aliased drawing routines, and a few other modifications 
regarding 
subpixel accuracy for that purpose!

-Thomas

When words aren't enough - Vodafone live! A new world of colour, sounds, 
picture messages and information on your mobile. a 
href=http://ad.doubleclick.net/clk;4909903;7724245;q?http://www.vodafone.co.uk/live;
Click here/a to find out more.