English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General > Coders. Tutorials

 
 
Thread Tools
Old 09 September 2009, 08:34   #121
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Quote:
Originally Posted by Vortex
Photon was ok with us using the Scoopex cruncher last time I checked...
Good stuff. I was just kidding regarding using Photon's cruncher - from what you say of your experience with it and from what I've seen so far it's a pretty handy piece of software.

Quote:
Originally Posted by Vortex
Haven't touched the mig for 2 weeks or so...
I've not really had any time for any real coding either, just little experiments with getting timers and pointers working fully PC relative style. Mainly been playing with my real A1200 with any spare time - I need to get the harddrive partioned / formatted / installed with Workbench etc. so we can use it for testing the megademo later on...

Quote:
Originally Posted by Vortex
Too busy preparing for IBC (www.ibc.org). Only 2 days left to get everything working. As usual there's stuff to finish before the show starts... (perhaps we should begin earlier next time... )
Good luck for the conference!
pmc is offline  
Old 26 September 2009, 23:43   #122
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Quote:
Originally Posted by StingRay
Also, it seems the movement of the cube is a bit jerky so you may want to increase the precision of your sine table and/or calculations a bit.
The reason for that jerky cube movement was that my code was shitty.

Now, admit it - you're not surprised.

I've rewritten both the build matrix and rotate points routines to use the minimum of swaps and rols with the result that the accuracy has now improved enough for the cube to be nicely smooth.

I just *had* to get it smooth before it got released in the megademo.

Anyways, check the attached source to see...

Last edited by pmc; 26 February 2010 at 12:23.
pmc is offline  
Old 21 October 2009, 21:40   #123
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Hello guys

My hidden lines routine has now been adapted into a demo part for the megademo. \o/

It can handle multiple objects - not just a cube now - and transitions between them.

Along with the other stuff that's going on in the part I've managed to get this routine up to rotating 48 points in one frame so I'm pretty pleased that it hasn't been so bad an effort after all.

After the megademo has been released I'll post the source code of the hidden line part here so anyone who's interested can check it out.

Last edited by pmc; 29 October 2009 at 00:16. Reason: Typo...
pmc is offline  
Old 28 October 2009, 11:28   #124
korruptor
TDI
 
korruptor's Avatar
 
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
Brilliant, can't wait to see it
korruptor is offline  
Old 05 January 2010, 17:58   #125
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Watcha boys.

There was a subtle error (so subtle in fact that I still can't find exactly what it is! ) in the previous blitter line draw code I posted in this thread.

It was causing a problem with just one of my objects in my vectors part for the megademo. The object looked perfect when running on WinUAE - the bug could only be noticed on real Amiga hardware. Very strange.

Anyways, I've now rewritten the line draw routine to be neater, take less memory (no octant tab + some other savings) and (hopefully) faster too.

This new version is bug free as far as I can tell on both WinUAE and real Amigas.

Enjoy.

EDIT: According to my testing, this rewrite shaves about a rasterline per line drawn off the execution time of the previously posted bugged version.

Last edited by pmc; 26 February 2010 at 12:23.
pmc is offline  
Old 05 January 2010, 23:45   #126
korruptor
TDI
 
korruptor's Avatar
 
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
Thanks man
korruptor is offline  
Old 06 January 2010, 09:21   #127
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by pmc View Post
There was a subtle error (so subtle in fact that I still can't find exactly what it is! ) in the previous blitter line draw code I posted in this thread.
Makes me smile for some reason, guess you know why. Nice that you fixed it (and apparently optimised it too :P). =)
StingRay is offline  
Old 06 January 2010, 09:35   #128
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Quote:
Originally Posted by korruptor
Thanks man
No worries mate - glad to be of service.

Quote:
Originally Posted by StingRay
Makes me smile for some reason, guess you know why.


Quote:
Originally Posted by StingRay
Nice that you fixed it (and apparently optimised it too :P). =)
Yeah, very nice - would have been far too lame to release an old skool megademo part that only ran 100% properly on an emulator!

Getting rid of non required octant tables, redundant checking (why did I check for is it less *as well as* is it equal instead of is it less or equal!? ) and redundant bitwise manipulations does tend to speed things up a bit!

Still, I'm learning all the time and you know what they say: you only learn from your mistakes...
pmc is offline  
Old 07 January 2010, 13:09   #129
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
Nice job on the new routine, and a further optimization you can do is to skip comparisons between values you will be subtracting anyway, as a comparison is essentially a subtraction operation, and tells you the result you're looking for. Then you can find the dX, dY and dY-dX values right away to find the line octant. Reducing memory accesses by keeping intermediate values in registers is a great optimization too.

Here's a spoiler attached:
Attached Files
File Type: txt drawline.txt (3.7 KB, 256 views)
Leffmann is offline  
Old 07 January 2010, 13:37   #130
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Nice one Leffman.

I'll take some time with what you've suggested here and look at your routine to round out what you've said.

Without getting all mushy on you () I've got a lot of time and respect for your coding knowledge both because of what you've posted in many threads here (not just mine) and because of the quality of those routines of yours you posted YouTube links to previously.

It's very much appreciated that you've taken time not only to look at my efforts but also to suggest other ways I can increase my understanding.

I've found the best way to learn is to think as much as I can for myself and write my own code then, when someone with more skills and experience (in this case you... ) tells me how I could have done it better, the lesson sinks in more.

Top man.
pmc is offline  
Old 07 January 2010, 13:54   #131
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Quote:
Originally Posted by Leffman
and a further optimization you can do is to skip comparisons between values you will be subtracting anyway, as a comparison is essentially a subtraction operation, and tells you the result you're looking for.
So, rather than:

compare, branch on result, do the subtration (to find dx / dy) ordered so that the result is always positive and store

I should do:

Subtract, correct result to positive as required and store, obviously preferrably in a data reg rather than a mem location.
pmc is offline  
Old 07 January 2010, 17:14   #132
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Quote:
Originally Posted by Leffman
Reducing memory accesses by keeping intermediate values in registers is a great optimization too.
Another speed question in relation to this:

Say I've run out of data registers and I've got no choice but to store a variable to memory temporarily.

Is it quicker to save the reg to memory with something like this:

Code:
move.w   d0,savereg(a5)
or push it on the stack like this:

Code:
move.w   d0,-(sp)
pmc is offline  
Old 07 January 2010, 20:23   #133
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,188
@pmc

IIRC, predecrements and postincrements are expensive on the '020+. Do the former especially if it's a single-byte offset.

BTW, are you subtracting -128 from the heap when you allocate it and all of the other heap accesses then adding -128 back on at the end when you deallocate it? That will insure that you're getting as many single-byte offsets as possible on the heap. Obviously this only helps if your heap is bigger than 127 bytes.
Samurai_Crow is offline  
Old 08 January 2010, 09:55   #134
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by pmc View Post
Code:
move.w   d0,savereg(a5)
or push it on the stack like this:

Code:
move.w   d0,-(sp)
Latter is faster (and shorter) since you don't have a 16 bit offset.

If you are sure that the upper part of d0.l is unused you could also do:

swap d0 and use d0.w for other things and to restore your value you'd just swap d0 again of course.
StingRay is offline  
Old 08 January 2010, 14:14   #135
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
OK chaps, after thinking on Leffman's advice I went away and coded another version of my linedraw routine (attached).

It now has no unnecessary sub.w / cmp.w combinations using only sub.w and neg.w as required instead.

Also it now no longer has any unnecessary moves to or from memory locations and does everything with data registers.

Judging from the speed tests I've run there's no real difference in execution time between this new version and the previous version I posted but I prefer this new version as it's much neater.

I've not checked the routine Leffman posted (that would've been cheating ) against this one so maybe there's still some optimising I could do but if there is I can't see how at the moment.

Of course, I'm always happy to be corrected and learn some more.

Quote:
Originally Posted by StingRay
Latter is faster (and shorter) since you don't have a 16 bit offset.
I thought so but thanks for confirming StingRay.

Quote:
Originally Posted by StingRay
If you are sure that the upper part of d0.l is unused you could also do:

swap d0 and use d0.w for other things and to restore your value you'd just swap d0 again of course.
Hmmm. That's a neat little trick - 8 longword data regs can be used as 16 word regs like that - providing, as you say, you do it carefully.

Nice one.

Last edited by pmc; 26 February 2010 at 12:23.
pmc is offline  
Old 19 January 2010, 15:39   #136
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Hello people.

Since fixing the linedraw code I've made a few additional, very minor, optimisations to the hidden line demo.

The demo as a whole seems to be able to handle rotating, transforming and drawing objects with around a maximum of 48 points in one frame. This number would probably increase slightly if *all* the demo was doing was the 3D objects but I can't imagine there would be time for a vast number of additional points.

So, my question is: how do the coders from way back when do routines that will handle literally hundreds of points (for example the hidden dot ball in Phenomena's Enigma demo) in one frame?

Are they always done with precalcs and other cheats or is there some kind of "secret" I've completely missed to speed the 3D calcs up massively?
pmc is offline  
Old 21 January 2010, 13:25   #137
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Quote:
Originally Posted by pmc
Are they always done with precalcs and other cheats or is there some kind of "secret" I've completely missed to speed the 3D calcs up massively?
Per my previous post, anyone...?
pmc is offline  
Old 21 January 2010, 19:24   #138
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
If you don't want to use any tricks or precalcs it's just a matter of optimization, and restricting the effect while still making it look good.

If you just want to do rotations then you can drop the matrix and vector multiplications and do planar rotations in the X and Y planes, and drop the Z rotation. Rotating in 2 axes will still look good as the Z rotation doesn't reveal any more of the object.

Now you can also convert from cartesian to polar coordinates and reduce the amount of calculations further, and if you're doing a sphere like in the Enigma demo then you can drop the perspective calculations as well. I can get down to 4 multiplications and 5 memory look-ups per point like this, 19 instructions for the entire loop, plotting included.

The next step (on a plain 68K) would be to unroll the loop, and to be able to do really many points you would go back to matrix and vector multiplications and quantize your object into f.ex a 256*256*256 grid, precalculate the 256 steps along your rotated X Y and Z axes and use the X Y and Z components of each point in your object as indices into these tables.
Leffmann is offline  
Old 21 January 2010, 19:36   #139
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Quote:
Originally Posted by Leffman
The next step (on a plain 68K) would be to unroll the loop, and to be able to do really many points you would go back to matrix and vector multiplications and quantize your object into f.ex a 256*256*256 grid, precalculate the 256 steps along your rotated X Y and Z axes and use the X Y and Z components of each point in your object as indices into these tables.
OK I understand this - this is the approach taken to do vectors on the C64. Precalc'ed tables and indexing into these from the object coords. This is, in other words, a multiplication shortcut which would obviously speed things up nicely. While there's no real alternative to this approach to produce vectors on the C64, to my mind, this is still cheating in the strict sense of the word on the Amiga due to the precalcs.

Quote:
Originally Posted by Leffman
Now you can also convert from cartesian to polar coordinates and reduce the amount of calculations further, and if you're doing a sphere like in the Enigma demo then you can drop the perspective calculations as wel
I don't understand this yet - mainly cos I can be slow on the uptake.

What are polar coordinates and how do they differ from x,y,z cartesian coords?

Also, why no perspective required for a sphere? Points that are "further away" still need to be drawn / plotted closer together no matter what the object don't they?
pmc is offline  
Old 21 January 2010, 20:17   #140
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
Quote:
Originally Posted by pmc View Post
OK I understand this - this is the approach taken to do vectors on the C64. Precalc'ed tables and indexing into these from the object coords. This is, in other words, a multiplication shortcut which would obviously speed things up nicely. While there's no real alternative to this approach to produce vectors on the C64, to my mind, this is still cheating in the strict sense of the word on the Amiga due to the precalcs.
It's a bit more complex than just precalculating a multiplication, basically you're precalculating 3 vectors multiplied by 3 scalars, and all added together. The code I mentioned of 19 instructions can do ~250 points per PAL frame on an unexpanded A500, and I doubt you can break 500 with a "generic" rotate and plot routine using no precalcs, so unrolling loops and precalculating code and/or tables, this method in particular, is the only way to get arbitrary objects of thousands of points in full frame rate.

Quote:
Originally Posted by pmc View Post
I don't understand this yet - mainly cos I can be slow on the uptake.

What are polar coordinates and how do they differ from x,y,z cartesian coords?

Also, why no perspective required for a sphere? Points that are "further away" still need to be drawn / plotted closer together no matter what the object don't they?
Polar coordinates consist of an angle and a distance. You can replace:

X' = X sin a - Y cos a
Y' = X cos a + Y sin a

with

X = D cos (A + a)
Y = D sin (A + a)

which is obviously faster.

You can add perspective to a sphere, but being what it is, especially when just made up of tiny points on the screen, it gives you a lesser impression of depth than perspective does on f.ex a cube. Try it and you'll see. At least it's the one shape that doesn't look completely wrong without perspective.
Leffmann is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Learning AMOS - Beginners Guide Disks Peter Retrogaming General Discussion 15 28 October 2015 17:17
DiskImage: When learning to read proves futile. XDelusion support.Apps 19 20 October 2012 23:57
Wanting to start learning to code amiga in asm fishyfish Coders. Asm / Hardware 5 03 March 2012 06:11
Playpower - 8 bit learning games for the developing world girv Retrogaming General Discussion 5 24 March 2009 22:00
Learning assembler bLAZER Coders. General 1 12 May 2007 05:00

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 00:34.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.13114 seconds with 13 queries