Jump to content
IGNORED

3D 'SOLID' graphics


Recommended Posts

I'm looking to see if anyone can give me a routine or method (doesn't matter in BASIC or M/C; preferably in BASIC, no matter how slow it runs, once I understand it then I can transfer it to M/C if I desire) that colour fills 3D wire frames. I do have a routine to do the 3d wire-graphics, but trying to fill in particular segments (for solid 3d graphics) is bemusing me. If you want me to give you the routine I use, I can, I was just hoping to see if someone has a routine thats a bit simpler than mine.

Edited by ac.tomo
Link to comment
Share on other sites

Hi!

4 hours ago, ac.tomo said:

I'm looking to see if anyone can give me a routine or method (doesn't matter in BASIC or M/C; preferably in BASIC, no matter how slow it runs, once I understand it then I can transfer it to M/C if I desire) that colour fills 3D wire frames. I do have a routine to do the 3d wire-graphics, but trying to fill in particular segments (for solid 3d graphics) is bemusing me. If you want me to give you the routine I use, I can, I was just hoping to see if someone has a routine thats a bit simpler than mine.

 

The idea is to split the 3D object in triangles, then draw each (filled) triangle in turn.

 

- If you draw triangles from the farthest to the nearest, you must paint each new triangle over the ones that are behind, removing them from view - this is the https://en.wikipedia.org/wiki/Painter's_algorithm

- If you draw triangles from nearest to farthest, you must only paint over background and avoid painting over the ones already painted - this is the "reverse painter's algorithm"

 

The first method is usually the faster, as you don't need to test each pixel before painting it.

 

After you made it work, a common optimization is to only paint triangles in which the normal (the direction which the triangle is facing) points toward you, as you can assume that triangles pointing away from you are not visible.

 

So, you only nee three algorithms:

 

- An algorithm to project all triangles in the scene, converting the coordinates to screen coordinates - this is called the Geometry Pipeline in modern graphics, and it is done by the "geometry shaders".

- An algorithm to sort all triangles by the distance to the observer.

- An algorithm to paint a triangle given its three points (in 2D, as those are already projected) - this is called the Rasterization Pipeline in modern graphics, and it is done by the "pixel shaders".

 

Modern 3D hardware you don't sort triangles, instead a buffer holds the distance from the observer for each point (the z-buffer), and the rasterization performs a test on each pixel before painting it.

 

Note that if you are only drawing a convex object, you don't need to paint the triangles, if you only draw the triangles with the normal pointing towards the camera the object will appear ok. But convex objects are not fun :P .

 

Have Fun.

 

  • Like 4
Link to comment
Share on other sites

The technique you want to read up on is rasterization/rasterfill, which used to all be done in software via CPU programs, but nowadays is usually done by a 3D card or a specialized CPU instructions.

 

https://www.golombeck.eu/index.php?id=34&L=1

 

This a machine language version for the Apple II, so in terms of output it has to go through weird Apple memory striping, but the principles of rasterizing a polygon are there.

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

Sorry for the time its taken, but thankyou both for the information. I know there are several ways of getting 3d wire graphics, but if one of you can confirm that this apple program is the way to progress to 'solid' graphics then i'll go further and delve into this link. I presume this apple method uses points and lines. Any further help much appreciated.

Link to comment
Share on other sites

20 hours ago, ac.tomo said:

Sorry for the time its taken, but thankyou both for the information. I know there are several ways of getting 3d wire graphics, but if one of you can confirm that this apple program is the way to progress to 'solid' graphics then i'll go further and delve into this link. I presume this apple method uses points and lines. Any further help much appreciated.

Depending on the type of graphics, there are a couple of tricks you can play. "Rescue of Fractalus" is such an example. It draws the wireframe of the mountains first, and then performs a "fill" by a series of "OR" (or "AND") instructions that combine the color of the row above with the color of the row below. Thus, one starts with A = 0 (for the "OR" example), then takes the OR of that with the current position on the screen, then write the result into the cell, and continue that way from top to bottom. Once a line is hit, the value in A receives a 1 bit that is, by the above algorithm, replicated into all lines below the current line.

 

With this trick, one can fill quickly large areas as you can fill 4 (for Gr.15) or 8 (Gr.8) pixels at once by a single operation.  For games like Rescue, this works as the bottom of the screen contains always solid areas (the mountains) and the top is always light (the sky).

 

Another trick is played by "Capture the flag". Essentially, the algorithm is the same, though only the upper half of the maze is drawn. The lower half is not drawn at all, the contents is just replicated by ANTIC by a specially prepared display list that just reflects the upper part into the lower part.

 

Link to comment
Share on other sites

Maybe read these Page 6 / Atari User articles and as an exercise combine the two, e.g. take the wireframe area but call to draw a polyfill instead?

 

https://archive.org/details/Atari-User-035-Mar88-Create-Stunning-3D-Wire-Graphics-GB

 

https://www.atariarchives.org/c2ba/page085.php

(I've attached listing as pasting into Altirra from the original had errors (spaces between YY)

 

Another approach is to use the XIO fill:

http://www.page6.org/archive/issue_08/page_28.htm

(listing & Basic Rev C file attached)

polygon.lst fire.bas fire.lst

Edited by Wrathchild
May->Maybe
Link to comment
Share on other sites

On 10/7/2020 at 6:31 PM, thorfdbg said:

Depending on the type of graphics, there are a couple of tricks you can play. "Rescue of Fractalus" is such an example. It draws the wireframe of the mountains first, and then performs a "fill" by a series of "OR" (or "AND") instructions that combine the color of the row above with the color of the row below. Thus, one starts with A = 0 (for the "OR" example), then takes the OR of that with the current position on the screen, then write the result into the cell, and continue that way from top to bottom. Once a line is hit, the value in A receives a 1 bit that is, by the above algorithm, replicated into all lines below the current line.

 

With this trick, one can fill quickly large areas as you can fill 4 (for Gr.15) or 8 (Gr.8) pixels at once by a single operation.  For games like Rescue, this works as the bottom of the screen contains always solid areas (the mountains) and the top is always light (the sky).

 

Another trick is played by "Capture the flag". Essentially, the algorithm is the same, though only the upper half of the maze is drawn. The lower half is not drawn at all, the contents is just replicated by ANTIC by a specially prepared display list that just reflects the upper part into the lower part.

 

RoF "ANDs" 00 as "pixels" of the mountains... uses a collum based "ORA" filler... the sky is filled "til" it hits a mountain edge. the colors are cleverly choosen.

 

it uses unrolled code for filling one collum and jumps into it by Ypos... and one of the index registers of the 6502 holds the collum (0-47)

Edited by Heaven/TQA
  • Like 1
Link to comment
Share on other sites

7 hours ago, ac.tomo said:

Yes, that's an excellent way to do tasks like that in Rescue o F, but I'm looking to, say, rotate a 3d solid cube for example.

Cube is a special case similar to pyramid... as you always see just 3 faces of the cube... so a lot of optimisations can be done here...

Link to comment
Share on other sites

On 10/8/2020 at 11:23 PM, Wrathchild said:

Maybe read these Page 6 / Atari User articles and as an exercise combine the two, e.g. take the wireframe area but call to draw a polyfill instead?

 

https://archive.org/details/Atari-User-035-Mar88-Create-Stunning-3D-Wire-Graphics-GB

 

https://www.atariarchives.org/c2ba/page085.php

(I've attached listing as pasting into Altirra from the original had errors (spaces between YY)

 

Another approach is to use the XIO fill:

http://www.page6.org/archive/issue_08/page_28.htm

(listing & Basic Rev C file attached)

polygon.lst 4.13 kB · 2 downloads fire.bas 2.7 kB · 4 downloads fire.lst 2.49 kB · 2 downloads

 

Thankyou for this, but I dont know how to transfer these attached files to my atari or load them on my atari emulator, I have 1 of those sdmax gadgets, will that help?

Edited by ac.tomo
Link to comment
Share on other sites

On 10/8/2020 at 11:23 PM, Wrathchild said:

Maybe read these Page 6 / Atari User articles and as an exercise combine the two, e.g. take the wireframe area but call to draw a polyfill instead?

 

https://archive.org/details/Atari-User-035-Mar88-Create-Stunning-3D-Wire-Graphics-GB

 

https://www.atariarchives.org/c2ba/page085.php

(I've attached listing as pasting into Altirra from the original had errors (spaces between YY)

 

Another approach is to use the XIO fill:

http://www.page6.org/archive/issue_08/page_28.htm

(listing & Basic Rev C file attached)

polygon.lst 4.13 kB · 6 downloads fire.bas 2.7 kB · 8 downloads fire.lst 2.49 kB · 7 downloads

 

That fire engine is cool, but how do I load the LiSTed files into Altirra?

Link to comment
Share on other sites

You should be able to open Altirra to the basic READY prompt and then simply right click and paste having copied it from notepad.

 

I would recommend however setting up the H: drive.

Use the menu 'System / Configure System' then select 'Peripherals / Devices'.

Choose 'Add...' and from there select the "H:" device.

Map the path to a convenient folder.

 

By loading/saving anything to H1-4 will be the same as saving to an Atari drive.

By loading/saving to H6-9 instead, any $9B (newline) characters are translated to CR/LF and so easier to edit in your editor of choice.

 

So the ".lst" files I attached were saved via: LIST "H6:FIRE.LST" and can be loaded via: ENTER "H6:FIRE.LST"

 

image.thumb.png.e7a27dff5a70a9949c6bb671318cd377.png

Edited by Wrathchild
  • Like 2
Link to comment
Share on other sites

On 10/21/2020 at 5:38 PM, Wrathchild said:

You should be able to open Altirra to the basic READY prompt and then simply right click and paste having copied it from notepad.

 

I would recommend however setting up the H: drive.

Use the menu 'System / Configure System' then select 'Peripherals / Devices'.

Choose 'Add...' and from there select the "H:" device.

Map the path to a convenient folder.

 

By loading/saving anything to H1-4 will be the same as saving to an Atari drive.

By loading/saving to H6-9 instead, any $9B (newline) characters are translated to CR/LF and so easier to edit in your editor of choice.

 

So the ".lst" files I attached were saved via: LIST "H6:FIRE.LST" and can be loaded via: ENTER "H6:FIRE.LST"

 

image.thumb.png.e7a27dff5a70a9949c6bb671318cd377.png

 

Can this also be accomplished on the Atari800win emulator?

 

Link to comment
Share on other sites

That Atari user program you (wrathchild) directed me to doesn't work properly, I did actually try this program several months ago and had problems with it, perhaps someone can work out what the problem is.

I did put INT functions on lines 190 and 200 and that let me put 3 'faces' in instead of 2, but if I put, say, 15 faces the program errors.

 

au35.lst

 

Any help much appreciated.

 

EDT: forgot to put the Atari user link in: http://www.atarimania.com/mags/pdf/Atari-User-Vol-3-No-11.pdf

 

EDT: here's a slightly modified listing

au35.lst

Edited by ac.tomo
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...