home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / FAQSYS18.ZIP / FAQS.DAT / VOXEL.TXT < prev    next >
Internet Message Format  |  1994-08-09  |  12KB

  1. From rc1.vub.ac.be!ub4b!EU.net!uknet!pipex!howland.reston.ans.net!news.intercon.com!digex.net!digex.net!not-for-mail Thu Mar 10 10:07:04 1994
  2. Path: rc1.vub.ac.be!ub4b!EU.net!uknet!pipex!howland.reston.ans.net!news.intercon.com!digex.net!digex.net!not-for-mail
  3. From: kmccorm@access1.digex.net (Kevin McCormick)
  4. Newsgroups: comp.sys.ibm.pc.demos
  5. Subject: How in the world did they do MARS.EXE?
  6. Date: 28 Feb 1994 20:16:05 -0500
  7. Organization: Express Access Online Communications, Greenbelt, MD USA
  8. Lines: 35
  9. Message-ID: <2ku50l$9lo@access1.digex.net>
  10. NNTP-Posting-Host: access1.digex.net
  11.  
  12. Whew!  After downloading and running MARS.EXE, I find myself stunned by how
  13. fast it worked and how realistic it looked....
  14.  
  15. I'm into programming my own demo now with a couple of friends.  Our new group
  16. is called Mindware, and our demo should be finished within the next month or
  17. so.  (No name yet)  I'm now fairly experienced with graphics manipulation (3d,
  18. X-mode, VGA registers, etc.), but I still am amazed how smooth MARS is.
  19.  
  20. Now I've pondered quite a bit how it's done.  My first impression would be a
  21. ray-tracing like algorithm, where a ray is traced (quickly, of course) from the
  22. viewpoint, through the screen, and over the heightfield, testing for
  23. intersections along the way.  But this seems like it would be far too slow for
  24. practical use (but it would certainly deal with the smoothness of the landscape
  25. and the order of mountains).
  26.  
  27. My next impression was a polygon subdivision algorithm.  Take four points from
  28. the heightfield that form a square, and draw that polygon.  Go from front to
  29. back on the heightfield, drawing only if that area hasn't been drawn on before.
  30. But this seems like too much time would be spent on calculating the edges of
  31. the polygon and filling it.
  32.  
  33. My final idea again involves going from front to back on the heightfield, but
  34. instead of drawing accurate polygons, just draw a rectangular region from the
  35. current point to the next point, with a flat top, descending down until the
  36. non-filled area ends.  (This is probably not a very good explanation. :)
  37.  
  38. So... any ideas anyone?  Tell me if my ideas are really naive :)  I might try
  39. coding some of these things to see if they work.
  40.  
  41. Thanks in advance, and watch for our forthcoming demo!
  42. -- 
  43. Kevin McCormick                           | "The more we try to control, the
  44. kmccorm@access.digex.net                  |  less we are really in control."
  45. IRC: Xenophon                             |        - Robert J. Oppenheimer
  46. This message is costing the net hundreds if not thousands of dollars to send.
  47.  
  48. From rc1.vub.ac.be!ub4b!EU.net!sun4nl!wtrlnd!tess!postmaster Tue Mar 15 11:23:54 1994
  49. Path: rc1.vub.ac.be!ub4b!EU.net!sun4nl!wtrlnd!tess!postmaster
  50. From: michiel@tess.wlink.nl (Michiel Ouwehand)
  51. Newsgroups: comp.sys.ibm.pc.demos
  52. Subject: Mars.uue (1/1)
  53. Message-ID: <762760829.AA03471@tess.wlink.nl>
  54. Date: Wed, 02 Mar 1994 09:12:01
  55. Sender: postmaster@tess.wlink.nl
  56. Lines: 19
  57.  
  58. Hello M.D.Griffiths!
  59.  
  60. [─∙· 28 Feb 94, M.D.Griffiths wrote to All: ·∙─]
  61.  
  62.  MDG> Yes it is a much more difficult proposition, since as it stands,
  63.  MDG> no rotation is done, you simply move left or right. I would
  64.  MDG> imagine that rotation would complicate things somewhat, perhaps
  65.  MDG> the original algorithm might not be applicable? It makes a nice
  66.  MDG> demo though :-). Would the author like to comment?
  67.  
  68. I am not hte author, but I would like to comment. What the author is doing (as I
  69. see it) is calculate a fractal (this will be the height map) and calculate
  70. light-rays over it (this will be the colour map). Then, when drawing, each point
  71. on the screen is an interpollated version ofmore of the heights and colours in
  72. the map. Rotating will take some time, but isn't impossible as I see it.
  73.  
  74. Groetjes,   _    (Icarus / T∙R∙I∙A∙L)   InterNet: michiel@tess.wlink.nl
  75. )\/(ichiel (_)uwehand                    FreeNet: 2:2802/108.11
  76.  
  77.  
  78. From rc1.vub.ac.be!ub4b!EU.net!sunic!news.funet.fi!network.cc.jyu.fi!network.cc.jyu.fi!not-for-mail Thu Mar 10 10:07:29 1994
  79. Path: rc1.vub.ac.be!ub4b!EU.net!sunic!news.funet.fi!network.cc.jyu.fi!network.cc.jyu.fi!not-for-mail
  80. From: ap@network.cc.jyu.fi (Patrick Aalto)
  81. Newsgroups: comp.sys.ibm.pc.demos
  82. Subject: Re: How in the world did they do MARS.EXE?
  83. Date: 1 Mar 1994 14:28:59 +0200
  84. Organization: University of Jyvaskyla, Finland
  85. Lines: 171
  86. Message-ID: <2kvceb$rjr@tukki.cc.jyu.fi>
  87. References: <2ku50l$9lo@access1.digex.net>
  88. NNTP-Posting-Host: tukki.cc.jyu.fi
  89.  
  90. In article <2ku50l$9lo@access1.digex.net> kmccorm@access1.digex.net (Kevin McCormick) writes:
  91. >Now I've pondered quite a bit how it's done.
  92.  
  93.     Why bother pondering, since the person who created the demo was
  94.     kind enough to post a description of the mothod, too. He did
  95.     this at least in the 'rec.games.programming' and 'comp.graphics.
  96.     algorithms' newsgroups. I think it might be a good idea for all
  97.     the readers of this conference to visit those two, too (at least
  98.     I do that).
  99.  
  100.     In any case, here's the description. I hope Tim Clarke don't mind...
  101.  
  102.     Patrick Aalto
  103.     ap@jyu.fi
  104.  
  105. --------
  106.  
  107.         Voxel landscapes and How I did it
  108.         ---------------------------------
  109.  
  110.  This document describes the method I used in my demo of a Martian terrain,
  111. which can be found at garbo.uwasa.fi:/pc/demo/mars10.zip.
  112.  It's similar to a floating horizon hidden line removal algorithm, so you'll
  113. find discussion of the salient points in many computer graphics books. The
  114. difference is the vertical line interpolation.
  115.  
  116.  
  117. First, some general points:
  118. ---------------------------
  119.  
  120.  The map is a 256x256 grid of points, each having and 8-bit integer height
  121. and a colour. The map wraps round such that, calling w(u,v) the height at
  122. (u,v), then w(0,0)=w(256,0)=w(0,256)=w(256,256). w(1,1)=w(257,257), etc.
  123.  
  124.  Map co-ords: (u,v) co-ordinates that describe a position on the map. The
  125. map can be thought of as a height function w=f(u,v) sampled discretely.
  126.  
  127.  Screen co-ords: (x,y) co-ordinates for a pixel on the screen.
  128.  
  129.  
  130. To generate the map:
  131. --------------------
  132.  
  133.  This is a recursive subdivision, or plasma, fractal. You start of with
  134. a random height at (0,0) and therefore also at (256,0), (0,256), (256,256).
  135. Call a routine that takes as input the size and position of a square, in the
  136. first case the entire map.
  137.  This routine get the heights from the corners of the square it gets given.
  138. Across each edge (if the map has not been written to at the point halfway
  139. along that edge), it takes the average of the heights of the 2 corners on that
  140. edge, applies some noise proportional to the length of the edge, and writes
  141. the result into the map at a position halfway along the edge. The centre of
  142. the square is the average of the four corners+noise.
  143.  The routine then calls itself recursively, splitting each square into four
  144. quadrants, calling itself for each quadrant until the length of the side is
  145. 2 pixels.
  146.  This is probably old-hat to many people, but the map is made more realistic
  147. by blurring:
  148.  
  149.      w(u,v)=k1*w(u,v)+k2*w(u+3,v-2)+k3*w(u-2,v+4) or something.
  150.  
  151.  Choose k1,k2,k3 such that k1+k2+k3=1. The points at which the map is sampled
  152. for the blurring filter do not really matter - they give different effects,
  153. and you don't need any theoretical reason to choose one lot as long as it
  154. looks good. Of course do everything in fixed point integer arithmetic.
  155.  The colours are done so that the sun is on the horizon to the East:
  156.  
  157.      Colour=A*[ w(u+1,v)-w(u,v) ]+B
  158.  
  159. with A and B chosen so that the full range of the palette is used.
  160.  The sky is a similar fractal but without the colour transformation.
  161.  
  162.  
  163. How to draw each frame
  164. ----------------------
  165.  
  166.  First, draw the sky, and blank off about 50 or so scan lines below the
  167. horizon since the routine may not write to all of them (eg. if you are on top
  168. of a high mountain looking onto a flat plane, the plane will not go to the
  169. horizon).
  170.  Now, down to business. The screen is as follows:
  171.  
  172.      ---------------------------
  173.      |                         |
  174.      |                         |
  175.      |           Sky           |
  176.      |                         |
  177.      |                         |
  178.      |a------------------------| Horizon
  179.      |                         |
  180.      |                         |    Point (a)=screen co-ords (0,0)
  181.      |          Ground         |     x increases horizontally
  182.      |                         |     y increases downwards
  183.      |                         |
  184.      ---------------------------
  185.  
  186.  Imagine the viewpoint is at a position (p,q,r) where (p,q) are the (u,v)
  187. map co-ordinates and r is the altitude. Now, for each horizontal (constant v)
  188. line of map from v=r+100 (say) down to v=r, do this:
  189.  
  190.     1. Calculate the y co-ordinate of map co-ord (p,v,0) (perspective transform)
  191.  
  192.     2. Calculate scale factor f which is how many screen pixels high a mountain
  193. of constant height would be if at distance v from q. Therefore, f is small
  194. for map co-ords far away (v>>r) and gets bigger as v comes down towards r.
  195.  
  196.     3. Work out the map u co-ord corresponding to (0,y). v is constant along
  197. each line.
  198.  
  199.     4. Starting at the calculated (u,v), traverse the screen, incrementing the
  200. x co-ordinate and adding on a constant, c, to u such that (u+c,v) are the map
  201. co-ords corresponding to the screen co-ords (1,y). You then have 256 map
  202. co-ords along a line of constant v. Get the height, w, at each map co-ord and
  203. draw a spot at (x,y-w*f) for all x.
  204.  
  205.  Sorry, but that probably doesn't make much sense. Here's an example:
  206. Imagine sometime in the middle of drawing the frame, everything behind a
  207. point (say v=q+50) will have been drawn:
  208.  
  209.          ---------------------------
  210.          |                         |
  211.          |                         |
  212.          |                         |
  213.          |           ****          |
  214.          |        *********        | <- A mountain half-drawn.
  215.          |-----**************------|
  216.          |*************************|
  217.          |*********       *********|
  218.          |******             ******|
  219.          |.........................| <- The row of dots is at screen co-ord y
  220.          |                         |   corresponding to an altitude of 0 for that
  221.          ---------------------------   particular distance v.
  222.  
  223.  Now the screen-scanning routine will get called for v=q+50. It draws in a
  224. point for every x corresponding to heights at map positions (u,v) where u
  225. goes from p-something to p+something, v constant. The routine would put points
  226. at these positions: (ignoring what was there before)
  227.  
  228.      ---------------------------
  229.      |                         |
  230.      |                         |
  231.      |                         |
  232.      |                         |
  233.      |                         |
  234.      |-------------------------|
  235.      |          *****          |
  236.      |       ***     ***       |
  237.      |*******           *******|
  238.      |.........................|
  239.      |                         |
  240.      ---------------------------
  241.  
  242.  So, you can see that the screen gets drawn from the back, one vertical
  243. section after another. In fact, there's more to it than drawing one pixel
  244. at every x during the scan - you need to draw a vertical line between
  245. (x,y old) to (x,y new), so you have to have a buffer containing the y values
  246. for every x that were calculated in the previous pass. You interpolate
  247. along this line (Gouraud style) from the old colour to the new colour also,
  248. so you have to keep a buffer of the colours done in the last pass.
  249.  Only draw the vertical lines if they are visible (ie. going down,
  250. y new>y old). The screen is drawn from the back so that objects can be drawn
  251. inbetween drawing each vertical section at the appropriate time.
  252.  
  253.  If you need further information or details, mail me or post here... Posting
  254. will allow others to benefit from your points and my replies, though.
  255.  
  256.  Thank you for the response I have received since uploading this program.
  257.  
  258.  Tim Clarke, tjc1005@hermes.cam.ac.uk
  259.  
  260.  
  261.  
  262.