Тёмный

Animating Ellipses on a Vintage 386 Computer 

PCRetroTech
Подписаться 7 тыс.
Просмотров 3,6 тыс.
50% 1

I show implementations of ellipse routines, including horizontal ellipses and diagonal/general ellipses on a vintage 386 computer, all assembly optimised for maximum performance.
I talk about how scan conversion of lines, circles and ellipses actually works at a high level and talk about all the issues I ran into trying to get my final animation to work.
Code repository for this episode:
github.com/wbhart/ellipse
PC-Key-Draw:
www.pcjs.org/software/pcx86/s...
Minsky circle algorithm:
cabezal.com/misc/minsky-circle...
Da Silva Ellipse algorithm:
cs.brown.edu/research/pubs/th...
Van Aken's algorithm:
arxiv.org/pdf/2009.03434.pdf
Kappel's algorithm is unfortunately behind a paywall.

Наука

Опубликовано:

 

5 авг 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 80   
@Dinnye01
@Dinnye01 11 месяцев назад
I never thought I'll watch a 45 minute video of ellipses on long obsolete platform, and never imagined I'll enjoy it tgis much. Btw love your no nonsense presentation. No music, no bling, just to the point.
@PCRetroTech
@PCRetroTech 11 месяцев назад
Thanks. I'm really glad you enjoyed it!
@Dinnye01
@Dinnye01 11 месяцев назад
@@PCRetroTech also, using AI to enhance your content like this is not just smart, but fits into the tech aspect of the channel. I use AI to write routing tables when I don't have much time. Lets me do more work in a given amount of time.
@PCRetroTech
@PCRetroTech 11 месяцев назад
@@Dinnye01 Indeed, it's a handy tool.
@zachz96
@zachz96 11 месяцев назад
The display had a crazy high resolution too! 1024x1024 in 1959!
@JohnDlugosz
@JohnDlugosz 11 месяцев назад
Back in the day, I was one of the authors and the architect of the ViewPoint graphics library, which runs in 16-bit mode, for Hercules, Herc In-Color, CGA, EGA, VGA, and various super-VGAs. It even took on the then-new "high color" modes. It was _much_ faster than other libraries, while offering certain features like bounding boxes, dotted lines, and mixing modes. As I recall, the line drawing code was a thousand lines of assembly with over a hundred labels. It needed different code for each quadrent of slope, and basically prevented decision-making inside loops by having a different copy for each case. In C++, I generalized the filled shape code for polygons, ellipses, chords, pie slices, etc. The edges are scan-converted, and as long as each segment is for a single slope-quadrant, it doesn't matter whether they are lines or curves. Or, _any_ curve. So, a general ellipse (as you call it) can have its border chopped up where it crosses the coordinate axes, and just needs an object that each time you step it vertically it changes the horizontal position accordingly. This general ellipse segment was in C++ only, not asm, but it just keeps track of the endpoints for the filling routine. You could make it draw the outline as well, by doing a line-to each point it generates, but that's not as fast as an asm solution. It was just provided for completeness, and for showing off because other libraries could not do that at all.
@PCRetroTech
@PCRetroTech 11 месяцев назад
Wow! I'm really impressed to hear about that. You may or may not know that I have asm code for line drawing that sounds very similar to yours, though in my case only for CGA. I'm incredibly impressed that yours covered the other *GAs as well. I thought such a thing did not exist. One of the main issues with the general ellipse is dealing with narrow ellipses. The algorithms for scan conversion have a tendency to jump over the crossover points, leading to escape. The Da Silva algorithm solves this by computing one of the coordinates of each crossover point. There are still four problems with this however: 1) Da Silva got the maths wrong (he assumed the B coordinate could not be negative and that square roots could be negative, and he got one of the inequalities back-to-front), 2) one really needs to monitor both coordinates of the endpoint, due to possible accumulation of errors in the one being monitored (one checks whether one has reached the coordinate Da Silva computes, whilst checking if one will exceed the other), 3) for angles very close to certain ellipse orientations, the parameters he computes can go to infinity, exceeding the precision of the machine, 4) when converting to integer coordinates, rounding can cause overruns in very narrow ellipses (I found that truncation worked better, though didn't completely solve the issue for exceedingly narrow ellipses). It sounds as if you had a no-nonsense approach to the general ellipse. For the filled primitive, would you have simply used the equation of the ellipse to compute each coordinate in floating point, or did you use an integer algorithm for scan conversion? The former would work of course, but would be much slower without a maths coprocessor. The other approach that was common was to compute a small number of points on the boundary and draw lines between them. It sounds as if you might have been doing the latter for your outline routine? Anyway, thanks for stopping by and filling in some history!
@JohnDlugosz
@JohnDlugosz 11 месяцев назад
@@PCRetroTech For the asm aligned ellipse (outline) drawing, I read the classic papers I could find (this was pre-Internet, remember), ignored the garbage in the "popular" books about PC graphics, and did my own scan conversion with asm (and my other features) in mind. It's like the lines, but the "step" factor (represents the slope) itself is changing, so it adds another stage. The general code: I don't remember if it used floating point just to calculate the points where I needed to split it up; FP hardware was still optional at that time. But, it's a constant-time overhead and not part of the drawing loop. The outline-finding code then worked just like anything else using the difference algorithm with some number of stages: add a constant to the last one, which updates the number added to the one above that, etc. until the top one is the real value of interest. I realized that, just like the famous _Difference Engine_ , it was general purpose and could compute any function just by presetting the initial values for the various derivatives. Oh, I just remembered how I did the square root, on a fixed-point integer: Newton's method! The previous result in the same spot was used as the initial guess, and one iteration is enough to nail the correct value. In ASM of that vintage, conditional branching is slow! Don't expect me to remember how many clocks it takes for a branch taken.
@JohnDlugosz
@JohnDlugosz 11 месяцев назад
@@PCRetroTech Oh, hitting the registers on the card over the ISA bus (the IN and OUT statements) are also very slow. Running under a hypervisor might have settings that make them even slower.
@PCRetroTech
@PCRetroTech 11 месяцев назад
@@JohnDlugosz Ah that sounds like it was pretty impressive. By the way, is there anything on the web about the ViewPoint graphics library? There seem to have been other things by that name, so I'm having trouble finding it. RU-vid will kill links, but feel free to email me (email address on the channel page) or tell me how I could find it. I don't suppose there was a shareware version that is still on some ancient FTP server or something?
@ian_b
@ian_b 11 месяцев назад
All of this reminds me of a long abandoned project of mine from the 90s- I had this idea that instead of using polygons for 3D one could use 3D curves in particular ellipsoids. In those very low poly days, it seemed like a way to get organic looking curved surfaces in 3D renders. I remember many sheets of printer paper with me scribbling equations all over them and in the end had an equation for an ellipsoid with 2 different axes (so 2 axes are the same, creating a circular profile) at any orientation, but my maths wasn't up to having 3 different axes. I got stuck in that state where you know you're nearly there but can't get that last leap of insight... I could do 3D renders by a kind of ray tracing, which was pretty slow (writing in Visual Basic 3, and no help from the GPU etc) but I gave up in the end as it being out of my league.
@PCRetroTech
@PCRetroTech 11 месяцев назад
The maths puts a lot of people off computer graphics I think. I certainly didn't understand it well enough as a kid. I have an advantage these days doing maths as my day job.
@ian_b
@ian_b 11 месяцев назад
@@PCRetroTech The maths of ellipsoids was... challenging to me to say the least (I did A Level maths but failed due to a lack of revision, though I've learned a lot of what I should have learned then since). I had some very, very long equations although mostly they did gratifyingly collapse down to something simpler and more manageable!
@SianaGearz
@SianaGearz 11 месяцев назад
There was this game, Ecstatica. It cheats a little doesn't it. I wonder how its renderer works.
@ian_b
@ian_b 11 месяцев назад
@@SianaGearz Yes, as a result of my "project" I found the sequel Ecstatica II and played it. It looked very nice.
@PCRetroTech
@PCRetroTech 11 месяцев назад
@@SianaGearz It doesn't seem to have cheated much. The ellipsoids are not just ovals coloured in, but there is a per pixel z-buffer. It does use a pseudo Gouraud shading, though I don't know the details. The game required a 486 SX-25 to run, but it is certainly a work of art. Apparently the game engine itself was mostly developed by one guy over a period of years. I wonder if he developed it on a 386!
@andrewdunbar828
@andrewdunbar828 5 месяцев назад
Dude! This was something I tried to do so many times since the 8-bit era! Rotated ellipses, one of my old pet problems... Outline ellipses are quite a bit harder than filled ellipses. Another easy way to deal with some of these precision issues is to notice that it's fine for verticalish narrow ellipses but not horizontalish narrow ellipses, and then you just swap the way you uses the axes based on whether it's closer to vertical or horizontal.
@StuartCGadgetRev
@StuartCGadgetRev 11 месяцев назад
Brilliant video. I had the same foley, van dam et. Al. Book at Uni when I was studying graphics in the early 90’s I loved it for the pictures and the algorithms. Sadly lost it some time back..
@PCRetroTech
@PCRetroTech 11 месяцев назад
It's not hard to get secondhand copies. A great book for sure.
@ian_b
@ian_b 11 месяцев назад
Always glad to see you drop a new video, I know it's going to be interesting!
@procactus9109
@procactus9109 11 месяцев назад
Awesome, I could watch many hours of this kind of thing... Just being aware of how to find these algorithms is hard. When I was about 8 year old, I learnt myself how to draw circles pixel by pixel using Sin and Cos and found the value of pi before I knew what pi was, I'm kind of prowd of that :) But i could never get eclipses at all angles and spent hundred of hours trying. After watching this a few things clicked.. .. . thank you
@PCRetroTech
@PCRetroTech 11 месяцев назад
That's great to hear. Of course a full description of everything could fill an entire course of videos. I mainly just wanted to give some intuition in this video.
@procactus9109
@procactus9109 11 месяцев назад
@@PCRetroTech That would be an awesome entire course of videos though
@JohnDlugosz
@JohnDlugosz 11 месяцев назад
30:00 If memory serves, conic sections are closed under R2 linear transformations. So, a sheered ellipse is also a "proper" ellipse. What you note is that it has a different eccentricity than the original. You can compensate for that, as with the size, in the original. Note also that the non-square pixels further complicates things.
@andrewdunbar828
@andrewdunbar828 5 месяцев назад
Exactly. The way to do a scanline render of an ellipse is to first convert the rotated ellipse to a sheared ellipse. Another interesting thing is that a perspective projection of a sphere is always an ellipse. For nearly 40 years I've thought it would be fun to make a 3D game based on this principle using spheres as primitives. I suspect that any ellipsoid will become an ellipse under perspective projection too, but I'm not 100% certain since my maths is not good enough.
@nopus1
@nopus1 11 месяцев назад
old land survey textbooks is a great source for fast calculating ellipses
@superciliousdude
@superciliousdude 11 месяцев назад
Thank you for making this video. I thoroughly enjoyed the explanation of the fast but imperfect algorithms. Reminds me of the various hacks and shortcuts I had to implement in assembly to make my old qbasic programs work at a reasonable speed back in the day.
@HTMLEXP
@HTMLEXP 11 месяцев назад
It is great to see the fundamental principles behind creating computer graphics. The last animation reminds me of the image generated of Sagittarius A* black hole. At the end you mentioned that you had to use 64 bit values because it required that level of precision, presumably those do not fit in the cpu registers?
@PCRetroTech
@PCRetroTech 11 месяцев назад
That's right. I keep as much as possible in the registers, but have to use memory locations for the rest. But fortunately that is not such a terrible problem on the 386.
@fra4455
@fra4455 11 месяцев назад
Great video
@PCRetroTech
@PCRetroTech 11 месяцев назад
Thanks!
@SianaGearz
@SianaGearz 11 месяцев назад
I've actually learned some useful things today.
@OpenGL4ever
@OpenGL4ever 6 месяцев назад
Wow, this was a really great video. Thanks a lot!
@PCRetroTech
@PCRetroTech 6 месяцев назад
Thanks.
@joshm7769
@joshm7769 11 месяцев назад
Really nice vga graphics! I would have stared at hem for hours in de 90s.
@PCRetroTech
@PCRetroTech 11 месяцев назад
Thanks!
@R.-.
@R.-. 11 месяцев назад
Thanks for putting in so much effort to make these videos. Any thoughts on whether these algorithms can be easily modified to anti-alias the pixels - so the color intensity is proportional to how much of the line passes through each pixel? My guess is it depends on whether you want full anti-aliasing or an approximation. With full anti-aliasing you color multiple pixels for each horizontal step, according to how much of each pixel the line passes through. In computer graphics there is usually the "right way" to implement something, and many simpler approximations.
@PCRetroTech
@PCRetroTech 11 месяцев назад
I imagine you could use the decision variable to do antialiasing, though in the curve case, it doesn't quite measure how far you are from the curve. More like the square of how far if I recall correctly. Also, the distance is in one direction, not perpendicular to the line. But at least in principle you could do something. There are algorithms for anti-aliasing primitives in the Foley et al. book, but I didn't look into those in any detail at this point. My original goal was to get something working on CGA, until I discovered that was probably a fools errand (at least without cheating). Now that I'm on VGA, anti-aliasing becomes more of a consideration.
@rinner2801
@rinner2801 11 месяцев назад
Good stuff thank you!
@theALFEST
@theALFEST 11 месяцев назад
I like your videos very much
@PCRetroTech
@PCRetroTech 11 месяцев назад
I appreciate the feedback. Thanks!
@prozacgodretro
@prozacgodretro 11 месяцев назад
If your circles were restricted in size, could you use 8 bit registers and have enough? (in the original algorithm) I mean a special case for elipses that were known to be dimensionally small could be useful for graphics programming.
@PCRetroTech
@PCRetroTech 11 месяцев назад
You can in fact do ellipses up to some size with just 16 bit registers. I forget exactly what size. Something like radii 32, 32.
@thek3743
@thek3743 11 месяцев назад
nice job!
@JohnDlugosz
@JohnDlugosz 11 месяцев назад
Another speed tip: Access to video memory over the E-ISA bus is sloooooooow. The standard is 8MHz, and some machines allow individual slots to have the timing changed, so you can push the VGA card to 11MHz without messing up the other cards. Over the ISA bus, the newer (PC-AT) 16-bit memory transfer uses a better protocol so is actually one clock faster than an (original) 8-bit transfer! Minimize the touching of video memory. 256-color mode is much simpler with one byte per pixel, but if you wrote the short bursts of horizontal pixels 2 at a time with _aligned_ 16-bit writes, it would go faster. I'm supposing your code only writes a new color for the pixel -- it won't mix it with the previous value. With higher resolutions, it gets even more complex because the frame buffer is larger than the memory-mapped window. You have to bank-switch, and this occurs at 16K (or whatever) *memory* boundaries, without regard to how they fall on a scan line. Oh, and each brand of VGA card has its own way to do the bank switching.
@PCRetroTech
@PCRetroTech 11 месяцев назад
Thanks for the tips on the EISA bus. I was unaware it was so slow! In 256 colour mode it is of course just doing one pixel per byte. So in some sense the number of bytes written to memory is minimized. At present I don't have enough registers to keep track of multiple bytes at once. But that is definitely a possibility if moving horizontally. As for the SVGA cards, I was aware they all had different methods for switching banks. I've been doing some programming recently on the channel with XGA and this already comes up. The books that describe XGA the best also describe all the SVGA adapters, so I've done a bit of reading around that issue. It will be interesting to play with those at some point. I've considered doing a TsengLabs ET4000 video for example.
@JohnDlugosz
@JohnDlugosz 11 месяцев назад
@@PCRetroTech I'll see if I can find my* old code, if you're interested. I remember Tseung Labs now that you mention it. Also STB, which was local to me, was great to visit. You're following footsteps left >30 years ago -- I even have the same Folly, Van Dam, et al. book (I have both first and second editions actually). You should also look into Graphics Gems. * The assembly language portion was coded by my partner in ViewPoint, Mike Hoyt. His code has been described as "Wilton meets Abrash".
@elle305
@elle305 8 месяцев назад
wonderful video, clarity is great and fun exercises. was this given as a presentation somewhere? it seems odd that you record the screen while talking, rather than dubbing a track over the video
@PCRetroTech
@PCRetroTech 8 месяцев назад
The video was produced for RU-vid, not somewhere else. There probably are places I could give a talk of this kind, but life is too busy to get involved with them. I've always talked while recording the screen, as I find it hard to sync the talking with what's going on. I'm not sure how other RU-vidrs do that so convincingly.
@StoianAtanasov
@StoianAtanasov 8 месяцев назад
As the AI written code is the future and you have spent so much time hand programming ellipses, it would be amazing if you could evaluate GPT4 with your code, if for example it can help you solve the issues in the cases of the very high aspect ellipses.
@PCRetroTech
@PCRetroTech 8 месяцев назад
GPT4 has very little idea of how to do really optimised coding in 8088 assembly, unfortunately. It can do a few simple things, but that kind of deep analysis is impossible for it.
@OpenGL4ever
@OpenGL4ever 6 месяцев назад
@@PCRetroTech You could ask GPT4 for a fast algorithm in C that can draw generic ellipses on a 32 bit or 16 bit machine without an FPU.
@PCRetroTech
@PCRetroTech 6 месяцев назад
@OpenGL4ever I don't think it would manage that as there's nothing in its training data that would help it with that. The same circle algorithm is repeated hundreds of time online, plus a handful of standard ellipse algorithms, mostly incorrect, and that's it. GPT4 doesn't have the planning capability to come up with stuff it doesn't know. Instead it hallucinates, unless it is a fairly trivial generalisation of something it knows.
@PCRetroTech
@PCRetroTech 6 месяцев назад
As I suspected, the result, though ingenious, is not useful. It first produced a standard ellipse. When that was pointed out it produced a rotated standard ellipse with the rasterisation done before the rotation. When that was pointed out it produced *pseudocode* for an algorithm that looped over every pixel in a rectangle and checked whether it was in the rotated ellipse or not. When that is pointed out it goes back to rasterising before rotation, but doesn't notice it has done so. There's just no answer in its training data.
@OpenGL4ever
@OpenGL4ever 6 месяцев назад
@@PCRetroTech Thank you for trying it and your answer. Basically, this is still good news, because it means that GPT4 cannot yet replace programmers everywhere.
@techdistractions
@techdistractions 11 месяцев назад
Always a good day when you post new content. Congratulations on the outcome after some amazing work. On a side note when you showed the finished result I had to go watch donut by desire again 🎉 ..not ellipses but anyway!
@PCRetroTech
@PCRetroTech 11 месяцев назад
Glad you liked it. And pleased to have contributed to the view count of a Desire demo.
@desertfish74
@desertfish74 11 месяцев назад
Please consider changing your mouse pointer to a larger, different color one. It's very hard to see in the graphs.
@tomiluukkonen4035
@tomiluukkonen4035 11 месяцев назад
I have to agree about mouse cursor. Sadly. Double-sized red could work. As you might know, many followers are quite old 😭
@xenaretos
@xenaretos 11 месяцев назад
Well, technically, they did have a screen on PDP-1...
@PCRetroTech
@PCRetroTech 11 месяцев назад
Yes, technically I guess. Quite an impressive piece of tech for the era.
@TrashfordKent
@TrashfordKent 11 месяцев назад
I could be way off on this but it feels like some of the 8 bits machines were explored/exploited reasonably well where as PC graphics weren’t pushed sprite wise to the same extent until til later? Ps great video
@PCRetroTech
@PCRetroTech 11 месяцев назад
Sure, the 8 bit machines had sprite hardware, which made all the difference.
@JohnDlugosz
@JohnDlugosz 11 месяцев назад
BTW, how are you running 32-bit code under DOS?
@OpenGL4ever
@OpenGL4ever 6 месяцев назад
You can use DOS Extenders like DOS4G/W, DOS/32, CWSDPMI etc. to do this. That's at least the normal way to do it. You can also use a VCPI extender or use Unreal mode, but the latter two are not recommended, they are not compatible with Windows. Windows does provide its own DPMI host in Win9x/Me and inside a VM86 using NTVDM in 32 bit Windows NT like systems.
@FavoritoHJS
@FavoritoHJS 7 месяцев назад
You say you can't fit a tilted ellipse in 16 bits... Elite, as per usual, begs to differ. 17-bits ought to be enough for everybody. Check out Mark Moxon's commentary on Elite's source for details. From what I understood of it, use a shearing approach, but do the shearing _during_ circle rasterization. It uses vertices a la minsky and draws lines between them - straight lines, requiring lots of vertices to keep smoothness. You said in a comment that 32-bits are enough for an ellipse of up to 32 pixels, that means you'll only need to compute a new vertex that often. Subpixel precision for partial ellipses will be a must, but I suspect the nature of bresenham's makes that not as hard as it sounds. Result? Divide the ellipse up into small pieces, then faithfully raster each piece without trashing ram! (stack trashing not guaranteed) Repost count: 1
@FavoritoHJS
@FavoritoHJS 7 месяцев назад
wait this didn't get nuked by spam deterrance? nice.
@PCRetroTech
@PCRetroTech 7 месяцев назад
Drawing ellipses by joining lines doesn't result in pixel perfect ellipses and wouldn't be suitable for what I had in mind, as I mentioned at the beginning of the video. That's the way most people do it of course, but it doesn't result in a true ellipse.
@FavoritoHJS
@FavoritoHJS 7 месяцев назад
@@PCRetroTech ...but what if those lines just so happen to be segments of an ellipse? That should be an ellipse!
@p_mouse8676
@p_mouse8676 11 месяцев назад
I use chatgpt for the same reason, just get the bulk done, or let it spit out ideas. Than fix the bugs later. Only keep in mind, it is REALLY bad in math. I got it flat on its face many times for just some very basic calculus.
@zachz96
@zachz96 11 месяцев назад
5:20 a vertical line has "Undefined" slope.
@PCRetroTech
@PCRetroTech 11 месяцев назад
The limit is actually +infinity. It's perfectly reasonable to say the slope is infinite. Or if you make use of the extended reals, +infinity.
@Castaa
@Castaa 11 месяцев назад
So the main issue is that no one bothered to figured out how to draw arbitrary ellipses without using ieee floating point math? This is what you are trying to solve?
@PCRetroTech
@PCRetroTech 11 месяцев назад
Well, one can obviously do it with fixed point math that is high enough precision. But roughly speaking, that describes the issue.
@Castaa
@Castaa 11 месяцев назад
That's great you found a solution. I'm a bit surprised no one had done it before or at least made the solution public. You should turn this into a published paper. @@PCRetroTech
@PCRetroTech
@PCRetroTech 11 месяцев назад
@@Castaa It would simply be some corrections and implementation notes for Da Silva's thesis. Not really worthy of a publication.
Далее
These VGA Cards have a COPROCESSOR!
29:23
Просмотров 17 тыс.
2D Graphics Algorithms (part 2)
23:01
Просмотров 56 тыс.
XGA : King of IBM Graphics Standards (Part 1)
40:55
Просмотров 15 тыс.
100+ Linux Things you Need to Know
12:23
Просмотров 659 тыс.
Rescuing a REMARKABLE 386 DX-25 Made by Compaq
30:01
PC Graphics Programs of the 1980's
36:22
Просмотров 4,8 тыс.
I have TOO MANY Vintage PCs!
22:45
Просмотров 3,7 тыс.
Where Does Bad Code Come From?
42:21
Просмотров 185 тыс.
A Rare Paradise Pre-EGA Graphics Card that Plays Doom
36:13
ПОКУПКА ТЕЛЕФОНА С АВИТО?🤭
1:00
OZON РАЗБИЛИ 3 КОМПЬЮТЕРА
0:57
Просмотров 1,2 млн
Игровой Комп с Авито за 4500р
1:00