Any good examples of 3D vector programming?

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Art
Manic Miner
Posts: 206
Joined: Fri Jul 17, 2020 7:21 pm

Re: Any good examples of 3D vector programming?

Post by Art »

Thanks! Exactly, so I hope that my assembler skills will be good enough. But if it takes 4 seconds per frame in HiSoft Basic using only PLOT to draw everything, I think it should be possible to make it significantly faster. I will add one more little perspective correction and then I will return to the assembler version (still in very early stage).
User avatar
patters
Manic Miner
Posts: 471
Joined: Thu Apr 11, 2019 1:06 am

Re: Any good examples of 3D vector programming?

Post by patters »

Wow, it's surprising how effective that dither pattern is at softening the attribute block stepping. I bet it will be even nicer when it's in motion.
Art
Manic Miner
Posts: 206
Joined: Fri Jul 17, 2020 7:21 pm

Re: Any good examples of 3D vector programming?

Post by Art »

Yes, now it looks quite well. Probably because all background colours are similar and dark, and all lines are bright. But it's interesting that it doesn't work nearly as well, when I try a daylight version with a bright background (cyan and yellow) and dark lines. I was thinking about alternating day and night in the game, but finally I dropped the idea.
User avatar
Joefish
Rick Dangerous
Posts: 2063
Joined: Tue Nov 14, 2017 10:26 am

Re: Any good examples of 3D vector programming?

Post by Joefish »

I think what makes that better are that the colours stay inside the building (vertical) lines.
Art
Manic Miner
Posts: 206
Joined: Fri Jul 17, 2020 7:21 pm

Re: Any good examples of 3D vector programming?

Post by Art »

Yes, it helps.

Just for fun - a little daylight test. White with yellow works, but white with cyan doesn't work and yellow with cyan neither (I also tested yellow buildings). Probably they are too different, so roofs look a bit ugly. But in any case, it looks a bit empty, because we expect more details than during night. And I added bottom dots, so maybe it would be too slow anyway.

Image
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: Any good examples of 3D vector programming?

Post by RMartins »

You probably need to use patterns like a checkers board, to "paint" the walls, so that the transitions are smoothed out from different background colors.
And you need to make sure that you either:
1 - never paint the background with the building background color unless it's completely filled.
or
2 - never paint the background when the building background is below a specific percentage of coverage.

If you want it to look good in every case, you need to use case 1, because of highly contrasting colors.

NOTE: you can also limit your level to a specific set of color combinations and transitions that work nice with each other.


Another Idea you can try is to pattern the sky and/or the floor, and leave the buildings with a clear wall (without pattern).
just try it on an ZX image editor, until you get something that you like, and then try to implement it in code.

Color and free pixel line drawing will always be a struggle, it will always be a compromise.
User avatar
Sol_HSA
Microbot
Posts: 162
Joined: Thu Feb 04, 2021 11:03 am
Location: .fi
Contact:

Re: Any good examples of 3D vector programming?

Post by Sol_HSA »

Be careful though, soon we're talking about error diffusion.. ;)
Art
Manic Miner
Posts: 206
Joined: Fri Jul 17, 2020 7:21 pm

Re: Any good examples of 3D vector programming?

Post by Art »

Yes, it will always be a compromise on the Spectrum. Not only concerning lines and colours, but also concerning details and speed. I agree that there is still a room for some improvement, there are good ideas in this thread and I will experiment with some possibilities. But for my first 3D vector game, I will probably use only the night version, which works quite well with dark background colours, it is quite simple and probably it can be reasonably fast, because I've never done such a big project in assembler. Maybe later I will try to make something graphically more complicated.
alx
Drutt
Posts: 8
Joined: Thu Sep 30, 2021 7:05 pm

Re: Any good examples of 3D vector programming?

Post by alx »

First you just need to rotate a points of object in 3D. I recommend you to revers research in 3d part of Echology megademo. Also you can try google translate some articles with math and code examples:
- Algorithms - rotation in a three-dimensional coordinate system. Matrices.
- Programming - 3D on the Spectrum: rotation of the wire object (without cutting off the lines that have gone out of the screen).
- Spectrum programming - Fast 3D calculations: advanced algorithm.

The second question is how to build lines fast enough. Take a look at Peter16 gift by Flash Inc in debugger. Here is an ASCII text near the 'fast line routines'. Not so fastest, but fast enough and it's good to see the whole idea.

Then finally to fill these objects is not so easy and fast. Are you planning this?
Art
Manic Miner
Posts: 206
Joined: Fri Jul 17, 2020 7:21 pm

Re: Any good examples of 3D vector programming?

Post by Art »

Thanks for the hints. I already finished the 3D system in August, but most of it was in Basic. It needs to be converted to assembler, but I didn't have enough time for it yet, so I just re-learn assembler now and make plans for the whole game. As for filling objects, I made some tests using lines or patterns, but it wasn't suitable for my project, so I used 1D-buffers to cut hidden objects. By the way, the most difficult part was clipping object parts which are off-screen and behind the camera.
TheSnark
Drutt
Posts: 1
Joined: Sat Oct 09, 2021 7:25 am

Re: Any good examples of 3D vector programming?

Post by TheSnark »

Some really excellent stuff in this thread.

I appreciate that you likely won't want to go back and do too much tinkering, but just thought I might drop a thought for anyone else who might be reading and getting ideas.

(height) span buffers are really good for basic terrain but can really interfere with the cool arbitrary geometry that wireframe graphics are often used for.

A possible alternative:

If you have implemented raster colour filling, then you can piggyback a masking algorithm off that.
Due to its 'Bright' bit, the spectrum has two identical shades of black in its palette (...Yes, I am aware that they can apparently appear visually different in a few Eastern European clones... Don't @ me, Russians).

1. Initially set all of the attribute blocks 'paper' to 'dark black'

2. draw the faces from near-to-far (traditionally sorted using centroids)

3. After you've finished drawing a face, raster fill it with colour - if you want it to remain black, change it to 'bright black'

4. When drawing subsequent lines/faces, check the 'paper' colour of the attribute block you are writing to. If it's anything but 'dark black', then this section is masked and you shouldn't write to it.

This has a couple of obvious problems:
Mask artifacting due to the 8x8 size of the attribute blocks, and the constant attribute look-ups will slow your line algorithm (though probably no more than a span buffer)
These can both be minimised through lazy evaluation: i.e. only check every 4-6 pixels drawn.

I'm not sure if this will necessarily be faster than using a simple span buffer, but it will definitely use less memory and should allow for more complex geometry.
Art
Manic Miner
Posts: 206
Joined: Fri Jul 17, 2020 7:21 pm

Re: Any good examples of 3D vector programming?

Post by Art »

An interesting idea. I am not sure if I can use it, but it can be useful in some cases with different types of objects.
Alone Coder
Manic Miner
Posts: 401
Joined: Fri Jan 03, 2020 10:00 am

Re: Any good examples of 3D vector programming?

Post by Alone Coder »

Speed-up version of 3D engine with a small flyby demo (added by Dragons' Lord): https://cdn.discordapp.com/attachments/ ... 14_fun.zip
Video: https://disk.yandex.ru/d/aAGZ6U1grLCASw
User avatar
rastersoft
Microbot
Posts: 151
Joined: Mon Feb 22, 2021 3:55 pm

Re: Any good examples of 3D vector programming?

Post by rastersoft »

Alone Coder wrote: Tue Oct 12, 2021 6:21 pm Speed-up version of 3D engine with a small flyby demo (added by Dragons' Lord): https://cdn.discordapp.com/attachments/ ... 14_fun.zip
Video: https://disk.yandex.ru/d/aAGZ6U1grLCASw
Is that a "normal" spectrum, or is it in a speeded up model (like a Next working at 7/14/28 MHz)?
Alone Coder
Manic Miner
Posts: 401
Joined: Fri Jan 03, 2020 10:00 am

Re: Any good examples of 3D vector programming?

Post by Alone Coder »

rastersoft wrote: Wed Oct 13, 2021 9:43 am
Alone Coder wrote: Tue Oct 12, 2021 6:21 pm Speed-up version of 3D engine with a small flyby demo (added by Dragons' Lord): https://cdn.discordapp.com/attachments/ ... 14_fun.zip
Video: https://disk.yandex.ru/d/aAGZ6U1grLCASw
Is that a "normal" spectrum, or is it in a speeded up model (like a Next working at 7/14/28 MHz)?
This video shows Unreal Speccy emulator. You can run the SCL or TAP on any machine (with FPS like 5-6 at 3.5 MHz). Of all extensions, the engine supports turbo mode, Kempston mouse, and ATM-Turbo screen (if you recompile it with ATM=1).
User avatar
4thRock
Manic Miner
Posts: 415
Joined: Thu Nov 09, 2017 9:35 am
Location: Portugal

Re: Any good examples of 3D vector programming?

Post by 4thRock »

Alone Coder wrote: Tue Oct 12, 2021 6:21 pm Speed-up version of 3D engine with a small flyby demo (added by Dragons' Lord): https://cdn.discordapp.com/attachments/ ... 14_fun.zip
Video: https://disk.yandex.ru/d/aAGZ6U1grLCASw
Impressive at the default CPU speed, especially the mouse support! Great work ! :D
Art
Manic Miner
Posts: 206
Joined: Fri Jul 17, 2020 7:21 pm

Re: Any good examples of 3D vector programming?

Post by Art »

Yes, very nice! I tried the demo TAP file on a 3.5 MHz emulator and it works very well.
+3code

Re: Any good examples of 3D vector programming?

Post by +3code »

I agree, really nice, I've tested it on standard Spectrum mode at normal speed; I used to play a lot Driller back in the day and that thing looks awesome.
omega
Drutt
Posts: 6
Joined: Fri Jul 23, 2021 9:41 pm

Re: Any good examples of 3D vector programming?

Post by omega »

This is the most impressive 3D engine I've seen so far on ZX! I love the open world approach. It has potential in variety of games. Great work [mention]Alone Coder[/mention]. There are glitches here and there that are probably caused by simplification and fixed point math to meet high framerate. But that's not an issue to be honest. Amazing technical achievement,

Big thumbs up for sharing the source code too.
Alone Coder
Manic Miner
Posts: 401
Joined: Fri Jan 03, 2020 10:00 am

Re: Any good examples of 3D vector programming?

Post by Alone Coder »

The engine was described in detail in Info Guide #12 and #13. The new version has faster object filtering (with two available view distances) and fake lighting. It also allows to jump (Space). https://cdn.discordapp.com/attachments/ ... _atm17.zip
Alone Coder
Manic Miner
Posts: 401
Joined: Fri Jan 03, 2020 10:00 am

Re: Any good examples of 3D vector programming?

Post by Alone Coder »

A new demo by Dragons' Lord shows the bad sides of the engine (and a little of DOOM): https://disk.yandex.ru/i/bGAJknM9P0QbwA
Art
Manic Miner
Posts: 206
Joined: Fri Jul 17, 2020 7:21 pm

Re: Any good examples of 3D vector programming?

Post by Art »

After several months, i had some time to continue on my 3D game. Since the last month, I finally learn Z80 assembler and I try to convert my Basic program to a machine code version. It's my first real assembler program (except some little 10-byte routines in the past), so I am sure it can be smaller and faster, but I am quite satisfied. It looks a bit simpler than my previous Basic version, but I will continue to improve it. I made it in the MRS 09/2 assembler on an emulated Spectrum and it was a surprisingly comfortable experience. MRS doesn't work in the Fuse emulator (I don't understand why), but it works in old emulators, so I used X128 in a DOS emulator. Yes, a bit crazy, but I wanted to experience the programming style of the Spectrum era.

In the present version, I have the screen buffer below 32768, so if I understand well, I copy 6912 bytes from contended memory to contended memory, which is probably slow. I don't really understand how condended and uncontended memory work and which part of a program should be used in which part of a memory. I also tried to copy the buffer using PUSH/POP, but when it worked, the vector graphics were wrong for some reason (some lines had wrong coordinated). So the buffer copying is probably quite slow and some tearing can be seen when the game is moving.

http://phoenix.inf.upol.cz/~rachunl/test/3d13.mp4
User avatar
patters
Manic Miner
Posts: 471
Joined: Thu Apr 11, 2019 1:06 am

Re: Any good examples of 3D vector programming?

Post by patters »

Impressive! Looks good in action.
dfzx
Manic Miner
Posts: 685
Joined: Mon Nov 13, 2017 6:55 pm
Location: New Forest, UK
Contact:

Re: Any good examples of 3D vector programming?

Post by dfzx »

Fabulous work! Wish I could do stuff like that!
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
Art
Manic Miner
Posts: 206
Joined: Fri Jul 17, 2020 7:21 pm

Re: Any good examples of 3D vector programming?

Post by Art »

Thank you! A year ago, I wouldn't believe that I could do it. I am not a professional programmer, I don't know much about programming languages and tricks. I am still a beginner in assembler and I have no idea how to make a real game. But I will try to learn.
Post Reply