Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 04:01 29 Mar 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : The Great Colour Maximite 2 Octahedron Prize Challenge

     Page 1 of 11    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8516
Posted: 05:13pm 06 Nov 2020
Copy link to clipboard 
Print this post

I'm interested to see how the CMM2 can facilitate 3D graphics and what additional features might be useful to help.

I'd therefore like to challenge everyone to see how fast they can rotate a solid octahedron on-screen

The rules are:

CMM2 V5.05.06RC14
MODE 1,8
No CSUBS or other assembler by the backdoor
No GOSUBs or GOTOs
No ON ERRORs
X, Y , Z vertices at 0,250,0,   250,0,0,   -250,0,0,  0,-250,0,   0,0,250,   0,0,-250
Each face should be coloured differently and the correct faces should be hidden.
Assume the viewer is at 0,0,0 and the octahedron centred on 0,0,1000 with a viewplane at 0,0,800
Each iteration should rotate the octahedron 2 degrees about the x axis (pitch), 1 degrees about the y axis (yaw) and 0.5 degrees about the z axis (roll) around the centre of the octahedron.
Timing is from starting the program to completion of a complete rotation around Z (720 iterations)

The final position must be visually indistinguishable from the starting position
Code to be posted to this forum for me to test on the same CMM2 to establish the winner.

Please post your times (use TIMER) on this thread as you develop. 480MHz users can multiply their times by 1.18 to allow comparison with 400MHz CMM2 (my benchmark ratio from a similar application)

The competition closes at 17:00UTC on Friday 20th November.
The judges (me) decision is final
The judge cannot compete but will post reference times when available

Prize for fastest program

 
johnd
Newbie

Joined: 22/10/2020
Location: United States
Posts: 30
Posted: 06:44pm 06 Nov 2020
Copy link to clipboard 
Print this post

During each iteration, do we rotate the x, then y, then z separately; or can we do a combined single rotation for each iteration?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8516
Posted: 06:45pm 06 Nov 2020
Copy link to clipboard 
Print this post

  Quote  During each iteration, do we rotate the x, then y, then z separately; or can we do a combined single rotation for each iteration?


Whatever you want as long as you fully update the display after every iteration
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 432
Posted: 07:34pm 06 Nov 2020
Copy link to clipboard 
Print this post

I loved this challenge.  

As probably you know I'm working on a 3D API for the CMM2. There are some features we can incorporate into the CMM2 API that will help a lot with 3D rendering.

* Copying arrays with different dimensions... something like MATH COPY In(), Start,End,Out()
* Calculate 2 vectors intersection


This is my last code with the polygon clipping algorithm (not optimized):

https://github.com/leonicolas/cmm2-3d-api/blob/master/api-3d.bas
Edited 2020-11-07 05:35 by LeoNicolas
 
qwerty823
Newbie

Joined: 30/07/2020
Location: United States
Posts: 30
Posted: 10:12pm 06 Nov 2020
Copy link to clipboard 
Print this post

Peter,

Are there any other rules then what you've outlined above?

At a bare minimum, I can probably get this down to around ~720ms for all 720 iterations (give or take a few... and that's on a 400mhz).

Granted, it would be cheating IMHO, but within the rules as you've laid them out.

My idea is to precalc all the data in another program, then just iterate over the precalc data and draw triangles to the screen, although I assume that goes against the spirit of the challenge.  

Obviously, depending on if we write directly to page 0, or write to page 1 and do a copy to 0, can vary this greatly depending on if we pass B, I or D.

Any thoughts on a minimal set of "must haves" for this? Maybe a simple basic program outlining how this should be done, perhaps?

option explicit
option default none
option base 0

timer=0

Mode 1,8

'' Define any variables or other subs

Sub Init
 ' Add any initialization code here
End Sub

Sub Rotate
 ' Rotate your octahedron here
End Sub

Sub Draw
 ' Draw your octahedron here
End Sub

Init
Page Write 1
For i = 0 To 720
  Rotate
  Draw
  Page Copy 1 To 0, B
Next i

Print timer
End


Something like that? Feel free to adapt this to something you think makes more sense, or if you feel like you want this to be more open ended, then that is fine too. :)

I assume at a bare minimum that we want this to do the compute work in real time.
 
johnd
Newbie

Joined: 22/10/2020
Location: United States
Posts: 30
Posted: 10:21pm 06 Nov 2020
Copy link to clipboard 
Print this post

Can you just draw on page 0 as fast as you can, even if the display can't keep up.  Technically, that would still be updating the display.  However, if we have to wait for vertical sync every iteration, then we can't do any faster than 720*(frame-draw-time), even if the algorithm is much faster.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8516
Posted: 10:43pm 06 Nov 2020
Copy link to clipboard 
Print this post

For the avoidance of doubt, entries that use pre-calculation of anything outside of the MMBasic program will be discounted. You do not need to use PAGE COPY. The challenge is to do the calculations and update the video memory as fast as possible. The transfer of the video memory to VGA output is asynchronous in the background and outside of your control so is not relevant.
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 432
Posted: 03:23am 07 Nov 2020
Copy link to clipboard 
Print this post

Will a flickering image be accepted?
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 432
Posted: 06:37am 07 Nov 2020
Copy link to clipboard 
Print this post

Peter

Is this what you are expecting?



Octahedron rendering with page copy (125 FPS):

https://youtu.be/OFFE4AApq4U

Octahedron rendering directly to page 0 (250 FPS):

https://youtu.be/vvfzPPXxBUQ

No optimizations yet, but it's being very cool
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8516
Posted: 08:08am 07 Nov 2020
Copy link to clipboard 
Print this post

  Quote  Is this what you are expecting?


Looks too small. I'm expecting the octahedron will be about 400 pixels high ((250+250)/1000*800)

More clarification on the rules:
Please print out the coordinates of all 6 vertices after 650 iterations.
Do not use specific characteristics of a tetrahedron for hidden face analysis  (i.e. only 4 faces can ever be showing). Please make the techniques for hidden faces fully generic.
Should also have said to centre the output on MM.HRES\2, MM.VRES\2

angles to be considered as follows:

X + 2 degrees rotates the top of the tetrahedron away from you
Y + 1 degrees rotates the left of the tetrahedron away from you
Z + 0.5 degrees rotates the tetrahedron clockwise from the perspective of the viewer

If you are using Euler angles then rotate in the order x,y,z

Before any rotation the screen should look something like this. The white border is the edge of the 800x600 display area (BOX 0,0,MM.HRES,MM.VRES)



Edited 2020-11-07 21:31 by matherp
 
mkopack73
Senior Member

Joined: 03/07/2020
Location: United States
Posts: 261
Posted: 06:48pm 07 Nov 2020
Copy link to clipboard 
Print this post

Might be a good idea to also dictate the screen mode and color depth so comparing apples to apples.
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 311
Posted: 07:02pm 07 Nov 2020
Copy link to clipboard 
Print this post

  matherp said  
X, Y , Z vertices at 0,250,0,   250,0,0,   -250,0,0,  0,-250,0,   0,0,250,   0,0,-250
Each face should be coloured differently and the correct faces should be hidden.


I know this is a competition, but just in case it helps anyone, if the above vertices are numbered 0 to 5, then the numbering for the right hand rotated planes is:

0,5,2  0,1,5  0,2,4  0,4,1  3,2,5  3,5,1  3,1,4   3,4,2
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 311
Posted: 07:10pm 07 Nov 2020
Copy link to clipboard 
Print this post

  mkopack73 said  Might be a good idea to also dictate the screen mode and color depth so comparing apples to apples.


Mode 1,8 (from the original post).
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8516
Posted: 07:38pm 07 Nov 2020
Copy link to clipboard 
Print this post

  Quote   if the above vertices are numbered 0 to 5, then the numbering for the right hand rotated planes is:


Be interesting to see if cross products to determine which faces to output will be faster than "painters"

My current time for 720 iterations, with the area to be drawn cleared each time (mandatory), but no page copy is 3.449 seconds or 208FPS using Euler angles and Painters. The screen output seems to be taking just under half of the time so that could be nearly halved if hidden planes are not output , albeit at the expense of possibly more calculation.

Of course without page copy the video output is a complete mess but the challenge is to do the calculations and display the output on a clear page as fast as possible.

Video with page copy for reference

This is running at 132 FPS

  Quote  Might be a good idea to also dictate the screen mode and color depth so comparing apples to apples.


In first post
  Quote  MODE 1,8
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 432
Posted: 09:09pm 07 Nov 2020
Copy link to clipboard 
Print this post

I'm using normals calculation for polygon occlusion.

I have some questions:

What are the expected coordinates at the 650th iteration?

Are you expecting a code that can render any kind of polygon or can it be extremely optimized for octahedron?
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 311
Posted: 09:49pm 07 Nov 2020
Copy link to clipboard 
Print this post

I guess I'll go first

I have no idea if these vertices (from the 650th iteration) actually match anyone elses?

1759ms (409 frames per second)

With Page Copy it drops to 5485ms (131 fps)


Edited 2020-11-08 07:52 by PeteCotton
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 432
Posted: 11:01pm 07 Nov 2020
Copy link to clipboard 
Print this post

Amazing Pete

I'm near 400 FPS. I have some optimizations to implement :)

I didn't understand this calc:

"480MHz users can multiply their times by 1.18 to allow comparison with 400MHz CMM2"

Shouldn't it be the inverse, 400MHz might multiply by 1.18?
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1081
Posted: 11:42pm 07 Nov 2020
Copy link to clipboard 
Print this post

  LeoNicolas said  I didn't understand this calc:

"480MHz users can multiply their times by 1.18 to allow comparison with 400MHz CMM2"

Shouldn't it be the inverse, 400MHz might multiply by 1.18?

Matherp wants the time for 720 iterations, not frame rate.

==============
This is perplexing. While experimenting with geometry and perspective, I created the following program which crashes my CMM2. Can anyone see what I'm doing wrong? In line 14, I loop through different perspective values. The max number of loops is 35 iterations, which suggests I'm nesting too many subroutines, but I can't see where I'm doing that. Maybe the restore command?

mode 1,8
cls
timer = 0
'======================================
rho = 20
d = 1500
theta = 0.3
phi = 1.3
cx = MM.HRES/2
cy = MM.VRES/2
s1 = sin(theta) : s2 = sin(phi)
c1 = cos(theta) : c2 = cos(phi)

for rho = 10 to 100 ' crash past 45 - ie 35 iteration max
 cls
 restore cubeshape
 read x,y,z
 transform
 for j = 1 to 9
   bx = sx
   by = sy
   read x,y,z
   transform
   line bx,by,sx,sy
 next j

 for j = 1 to 3
   read x,y,z
   transform
   bx = sx
   by = sy
   read x,y,z
   transform
   line bx,by,sx,sy
 next j

 print @(250,50) rho
 pause 20
next rho

end

sub transform
 xe = - x * s1 + y * c1
 ye = - x * c1 * c2 - y * s1 * c2 + z * s2
 ze = - x * s2 * c1 - y * s2 * s1 - z * c2 + rho

 sx = d * xe / ze + cx
 sy = cy - d * ye / ze

end sub

cubeshape:
data  1, 1, 1
data  1,-1, 1, -1,-1, 1, -1, 1, 1,  1, 1, 1,  1, 1,-1
data  1,-1,-1, -1,-1,-1, -1, 1,-1,  1, 1,-1

data  1,-1, 1,  1,-1,-1
data -1,-1, 1, -1,-1,-1
data -1, 1, 1, -1, 1,-1


Also, I see after the BSOD that the colour map has changed. The white text is "whiter-than-white."
Error: System fault - possible causes
- Incorrect use of POKE
- Faulty CSUB
- Reserved words used as variables
- Firmware problem
> map reset
>

Edited 2020-11-08 10:07 by vegipete
Visit Vegipete's *Mite Library for cool programs.
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 311
Posted: 12:51am 08 Nov 2020
Copy link to clipboard 
Print this post

  LeoNicolas said  
"480MHz users can multiply their times by 1.18 to allow comparison with 400MHz CMM2"


I managed to creep mine up to 1642ms (438 FPS).
Mine is a 480mhz, so I guess my adjusted time is 1,937ms.
Edited 2020-11-08 11:12 by PeteCotton
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 432
Posted: 01:45am 08 Nov 2020
Copy link to clipboard 
Print this post

Wow... I'm still optimizing my code...
 
     Page 1 of 11    
Print this page
© JAQ Software 2024