Join us on Discord!
You can help CodeWalrus stay online by donating here.

[gLib][3d][z80][ez80] gLib a fast 3D asm/axiom library

Started by TheMachine02, January 19, 2015, 05:10:01 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TheMachine02

Yeah, definitly  :P And I indeed saw the 3D walrus. *Speed battle started* (just jooking). Polygons are definitly the next thing (with clipping), since rotations are kinda done. Some features :
-quaternions (I finally got them right this time, altough some strange things still bother me)
-16 bits world (no, no 24 bits world cause it would be too slow)
-still the same 3x3 matrix than old gLib

But indeed, this seemed dead because I didn't had much time those last month, and futhermore, I felt that in France the *pure* z80 was dying (and even if is still funny to do thing, z80 is wayyy to much limited - fancy 3d stuff are way too hard to do). But those new ez80 really interested me !!

Dream of Omnimaga

There are still some monochrome calc users out there but I hope to see a CE version in the future too. :p
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

TheMachine02

Polygons now works  ;)



The triangle filling routine is quite fast, despite being absolutly huge (and not quite optimized for the moment, with few glitch here and here), working fully in ez80 mode. It use two parallel modified bresenham algorithm.
EDIT : it is about ~450 bytes.

[spoiler=the code]

IDrawTriangle:
; (ix list of 2d coordinate)
#define x0 0
#define y0 3
#define x1 6
#define y1 9
#define x2 12
#define y2 15

#macro swap(a,b)
ld hl, (ix+a)
ld de, (ix+b)
ld (ix+a), de
ld (ix+b), hl
#endmacro

ld hl, (ix+y1)
ld de, (ix+y0)
or a, a
sbc hl, de
jr nc, _INoSwap1
swap(x0,x1)
swap(y0,y1)
_INoSwap1:
ld hl, (ix+y2)
ld de, (ix+y1)
or a, a
sbc hl, de
jr nc, _INoSwap2
swap(x1,x2)
swap(y1,y2)
_INoSwap2:
ld hl, (ix+y1)
ld de, (ix+y0)
or a, a
sbc hl, de
jr nc, _INoSwap3
swap(x0,x1)
swap(y0,y1)
_INoSwap3:
; y0<y1<y2
; changing edges are y0-y1 and y1-y2
ld hl, (ix+x0)
ld de, (ix+x2)
ld bc, $09DD2B ; dec hl, add ix,bc
or a, a
sbc hl, de
; if x0>x1, edge goes to left
jr nc, _IEdge0
; edge goes to right
ld bc, $09DD23 ; inc hl, add ix,bc
ex de, hl
or a, a
sbc hl, hl
sbc hl, de
_IEdge0:
ex de, hl
or a, a
sbc hl, hl
sbc hl, de
ld (IDeltaX0), hl
ld (ISMC_Code0), bc
ld hl, (ix+y2)
ld de, (ix+y0)
or a, a
sbc hl, de
ld (IDeltaY0), hl
; block 0 is the constant block
ld hl, (ix+x0)
ld de, (ix+x1)
ld bc, $09FD1B ; dec de, add iy,bc
or a, a
sbc hl, de
; if x0>x1, edge goes to left
jr nc, _IEdge1
; edge goes to right
ld bc, $09FD13 ; inc de, add iy,bc
ex de, hl
or a, a
sbc hl, hl
sbc hl, de
_IEdge1:
ex de, hl
or a, a
sbc hl, hl
sbc hl, de
ld (IDeltaX1), hl
ld (ISMC_Code1), bc
ld hl, (ix+y1)
ld de, (ix+y0)
or a, a
sbc hl, de
ld (IDeltaY1), hl
; block 1 is the variable block

ld a, 2
push af
ld a, l

ld hl, (ix+y0)
ld h, 160
mlt hl
add hl, hl
ld de, (ix+x0)
add hl, de
ld de, (IFramebuffer)
add hl, de
ex de, hl
sbc hl, hl
add hl, de

push ix

ld ix, (IDeltaY0)
ld iy, (IDeltaY1)

__ITriangleOuter__:
or a, a
jp z, _INextHalf
__ITriangleInner__:
push af

IDeltaX0=$+1
ld bc, $000000
add ix, bc
ld a, ixh
rla
jr nc, __INoSignChange0__
IDeltaY0=$+1
ld bc, $000000
__IBlockRestoreLoop0__:
ISMC_Code0=$
nop
add ix, bc
ld a, ixh
rla
jr c, __IBlockRestoreLoop0__
__INoSignChange0__:

IDeltaX1=$+1
ld bc, $000000
add iy, bc
ld a, iyh
rla
jr nc, __INoSignChange1__
IDeltaY1=$+1
ld bc, $000000
__IBlockRestoreLoop1__:
ISMC_Code1=$
nop
add iy, bc
ld a, iyh
rla
jr c, __IBlockRestoreLoop1__
__INoSignChange1__:
; hl = adress1, de = adress2
push hl
sbc hl, de
jr z, _ISizeIs0
push de
jr nc, _IDrawLine
add hl, de
ex de, hl
or a, a
sbc hl, de
_IDrawLine:
; de= right point, hl = size
mlt bc ; hack to clear bcu faster than ld bc,0
ld b, h
ld c, l
sbc hl, hl
add hl, de
; hl = de
inc de
IColor=$+1
ld (hl), 255
ldir
pop de
_ISizeIs0:
pop hl
ld bc, 320
add hl, bc
ex de, hl
add hl, bc
ex de, hl
pop af
dec a
jr nz, __ITriangleInner__
_INextHalf:
lea bc, ix+0
pop ix
pop af
dec a
ret z
push af
push af

push bc
push hl

ld hl, (ix+x1)
ld de, (ix+x2)
ld bc, $09FD1B ; dec de, add iy,bc
or a, a
sbc hl, de
; if x0>x1, edge goes to left
jr nc, _IEdgeC1
; edge goes to right
ld bc, $09FD13 ; inc de, add iy,bc
ex de, hl
or a, a
sbc hl, hl
sbc hl, de
_IEdgeC1:
ex de, hl
or a, a
sbc hl, hl
sbc hl, de
ld (IDeltaX1), hl
ld (ISMC_Code1), bc
ld hl, (ix+y2)
ld de, (ix+y1)
or a, a
sbc hl, de
ld (IDeltaY1), hl
ld a, l

ld hl, (ix+y1)
ld h, 160
mlt hl
add hl, hl
ld de, (ix+x1)
add hl, de
ld de, (IFramebuffer)
add hl, de
ex de, hl

pop hl
pop ix

jp __ITriangleOuter__

[/spoiler]

ben_g

Will the b&w version still be updated, or are you going to focus completely on the colour version?

TheMachine02

I'll indeed continue to update b&w, but it is pretty much near completion (there isn't many thing I can do to speed up thing futher). Only thing left are more high level function and more fast vector function.

Dream of Omnimaga

Nice to see progress and a new screenshot. :) I'm glad the monochrome version will still be updated. I know that monochrome calcs are less popular now and some people gave up on them, but they still have a solid base of users, like when the TI-83 when it got replaced with the TI-83+.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U


Dream of Omnimaga

  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

TheMachine02

It is indeed. Still need to implement backface culling/z-sorting, and more support for color  :P

Dream of Omnimaga

If you are refering to polygon sorting, then I hope you don't have too many issues with it and no big slowdowns. >.<

Do you use 8 bpp mode by the way?
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

tr1p1ea

BFC should speed things up nicely, however sorting might be a small hit, depending on how it is performed. For a model viewer you could get away with a few assumptions.

How many verts/faces is that model TheMachine? It looks very nice!

TheMachine02

Quote from: DJ Omnimaga on May 30, 2016, 11:11:56 PM
Do you use 8 bpp mode by the way?

Yes, I do. I also use double buffer with correct swaping (giving me nice free vsync !)

Quote from: tr1p1ea on May 31, 2016, 06:54:48 AM
BFC should speed things up nicely

Yeah definitly. I guess I'll end up doing it in world space, so I won't need to transform backculled vertices (and won't need rendering the polygon). Implementation is pretty memory intensive however, so I am thinking on how I could pack thing up.

Quote from: tr1p1ea on May 31, 2016, 06:54:48 AM
sorting might be a small hit, depending on how it is performed

yeah, that kinda bother me. Sorting might not be the most efficient way to do it. I'll think about it.

Quote from: tr1p1ea on May 31, 2016, 06:54:48 AM
How many verts/faces is that model TheMachine? It looks very nice!

341 verts and 563 faces.

Snektron

  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


TheMachine02

Well dependof what you want to talk about with shading. Is it pixel shading, face shading, gouraud shading ... ?  :P

Pixel shading might be too slow, however, gouraud shading might be possible. Face shading is pretty much easy, and is kinda left to the user of the lib.

tr1p1ea

Cool, I was wondering how many degrees (0-360) you are rotating that model by per frame?

Also do you plan on making a project with it yourself, or just releasing as a lib?

Powered by EzPortal