Jump to content
IGNORED

(demo) 3d engine


DrTypo

Recommended Posts

After Tube2020, I decided to make a more complete 3d engine.

It is still a very simple engine and lacks many features.

It displays only flat shaded triangles and does rotations only around Y axis.

 

So what to say about it?

It's not very fast despite the fact that it uses the GPU and blitter.

On my PAL machine, it runs in 3 frames (16.6 fps) while computing about 254 triangles.

Possible optimisations are:

  • improve depth sorting: if I remove depth sorting, it runs in 2 frames (25 fps). To do depth sorting I uses comb sort, which is an optimized bubble sort. Shell sort would probably be better. Another optimisation would be to do depth sorting only on the objects and use convex objects.
  • backface culling: I didn't implement backface culling (because lazyness). This would likely speed things up quite  bit.
  • use the DSP for transformation and clipping, the GPU for rasterisation.
  • reduces the amount of transformations: there are duplicate vertices that are transformed multiple times. This could be improved.

 

Doing this would take time and also run into the 4K limit of the GPU (except using DSP, this would help a lot with the 4K limit but good-bye U235 sound engine).

The routine could easily be split into 2 chunks for the GPU (transformation/clipping and rasterisation).

 

Anyway, doing fast 3D on the Jag is not easy (who knew?). Now I understand Checkered Flag (which probably uses a faster engine than this one).

But I don't understand No Second Prize on the Atari ST.

 

Edit: I implemented backface culling and things are indeed quite a bit faster. It now runs in 2 frames (25fps).

The effects of backface culling are two-fold: there are fewer triangles the rasterize will attempt to draw and fewer triangles to depth sort.

By the way I'll explain the meaning of the numbers on screen:

  • the first is the size of the routine in bytes. I can check that I stay within the 4096 bytes limitation of the GPU.
  • the second one is the number of triangles rendered.
  • the third one is a bit hard to grasp: it's the number of ticks (1/50th ou 1/60th of a second depending on your region) used to render 50 frames. So if the number is 50, one frame takes one tick. You are at full framerate (50fps or 60fps). If the number is 100, one frame takes two ticks you're at half framerate (25fps or 30fps).

 

 

 

 

engine.zip

Edited by DrTypo
edit: backface culling implemented
  • Like 18
Link to comment
Share on other sites

2 hours ago, DrTypo said:

After Tube2020, I decided to make a more complete 3d engine.

It is still a very simple engine and lacks many features.

It displays only flat shaded triangles and does rotations only around Y axis.

 

So what to say about it?

It's not very fast despite the fact that it uses the GPU and blitter.

On my PAL machine, it runs in 3 frames (16.6 fps) while computing about 254 triangles.

Possible optimisations are:

  • improve depth sorting: if I remove depth sorting, it runs in 2 frames (25 fps). To do depth sorting I uses comb sort, which is an optimized bubble sort. Shell sort would probably be better. Another optimisation would be to do depth sorting only on the objects and use convex objects.
  • backface culling: I didn't implement backface culling (because lazyness). This would likely speed things up quite  bit.
  • use the DSP for transformation and clipping, the GPU for rasterisation.
  • reduces the amount of transformations: there are duplicate vertices that are transformed multiple times. This could be improved.

 

Doing this would take time and also run into the 4K limit of the GPU (except using DSP, this would help a lot with the 4K limit but good-bye U235 sound engine).

The routine could easily be split into 2 chunks for the GPU (transformation/clipping and rasterisation).

 

Anyway, doing fast 3D on the Jag is not easy (who knew?). Now I understand Checkered Flag (which probably uses a faster engine than this one).

But I don't understand No Second Prize on the Atari ST.

 

engine.zip 30.75 kB · 14 downloads

Great stuff! Can I ask a question? How do you  make and import your 3D meshes?

Link to comment
Share on other sites

4 hours ago, agradeneu said:

Great stuff! Can I ask a question? How do you  make and import your 3D meshes?

I make the 3D meshes in Blender and export them as .obj files. Then I convert them in raw structures for my engine using a tool I made.

 

  • Like 1
Link to comment
Share on other sites

Cool! Pretty zippy, too!

 

*It would be cool for an auto spin around routine to kind of automate and show off the 3D at full speed without any user interaction, say pressing 5 and it could loop to 4 points, pausing at each one briefly or spinning around complete then ping ponging to another coordinate point at random though I suppose that may be silly and useless. Also, I take it the U235 isn't implemented at all on this one but am curious as to impact it would make if added.

 

**and maybe other goofy stuff like background color cycling

Edited by Clint Thompson
  • Like 2
Link to comment
Share on other sites

5 hours ago, CyranoJ said:

But can it do a completely straight road with weird random clipping errors?

:D I'm not elite enough to attempt such a task. But it does overflow when things are a bit far.

 

@Clint Thompson I don't think I'll implement an auto-spin feature. However I'll try to have U235 SE play some music. I expect the impact to be minimal. From my experience, U235 SE has hardly any effect on the rest of the system.

  • Like 7
Link to comment
Share on other sites

10 hours ago, CyranoJ said:

But can it do a completely straight road with weird random clipping errors?

He hasn't worked out the 200 pages of spreadsheets showing cycle counts nor re-worked the engine continuously for 2.5 years.  Give it time, and it just may be possible!

  • Like 2
  • Haha 2
Link to comment
Share on other sites

  • 5 months later...
  • 5 months later...

Well @Cyprian there is news!

So I went back to this project and separated the geometric transformations and rasterization parts. Now the DSP is doing the transformations and GPU+Blitter rasterization.

The rendering now is between 25fps and 50fps.

I also added a basic sound routine (3 voices with panning and resampling) to see if it interfered with the transformation calculations. And yes it id, I got weird random clipping errors!

In the clipping function, I had code like this:

    load  (r15+CVertexXti),rX
    load  (r15+CVertexYti),rY
    load  (r15+CVertexZti),rZ
    or rZ,rZ
    store rX,(r14+CVertexXti)
    store rY,(r14+CVertexYti)
    store rZ,(r14+CVertexZti)

I had to change it to:

    load  (r15+CVertexXti),rX
    or  rX,rX
    load  (r15+CVertexYti),rY
    or  rY,rY
    load  (r15+CVertexZti),rZ
    or rZ,rZ
    store rX,(r14+CVertexXti)
    store rY,(r14+CVertexYti)
    store rZ,(r14+CVertexZti)

I don't know really why.

In other parts of the code I also run several load instructions in succession without issues...

 

Controls: move around with the D-pad, strafe with A and C, play sounds with numpad 1,2 or 3.

 

For the moment I'm not planning on doing any game with it.

By the way, better try it on real hardware. In VJ the animation is choppy. I guess it's because of synchronization between TOM emulation thread and JERRY emulation thread. On older monothread VJ it should run fine.

 

 

3djag.zip

  • Like 4
Link to comment
Share on other sites

45 minutes ago, DrTypo said:

In the clipping function, I had code like this:


    load  (r15+CVertexXti),rX
    load  (r15+CVertexYti),rY
    load  (r15+CVertexZti),rZ
    or rZ,rZ
    store rX,(r14+CVertexXti)
    store rY,(r14+CVertexYti)
    store rZ,(r14+CVertexZti)

I had to change it to:


    load  (r15+CVertexXti),rX
    or  rX,rX
    load  (r15+CVertexYti),rY
    or  rY,rY
    load  (r15+CVertexZti),rZ
    or rZ,rZ
    store rX,(r14+CVertexXti)
    store rY,(r14+CVertexYti)
    store rZ,(r14+CVertexZti)

I don't know really why.

If r15 is pointing to main RAM, this is a known bug:

image.png.474b0a019a0b720ab761fe370cfb3c68.png

  • Like 1
Link to comment
Share on other sites

Indeed @Zerosquare, r15 is pointing to the main RAM. But I thought the last OR (or rZ,rZ) after the last LOAD was enough to protect the first STORE. Apparently this is not the case.

What's really strange is that the issue appears only when the interrupt is enabled. Otherwise it works fine.

 

 

Link to comment
Share on other sites

10 hours ago, SlidellMan said:

Maybe you could make something in the vein of Axelay?

I guess you meant StarFox? Axelay is a (gorgeous) 2D scroller.

For the moment I don't have any specific idea. The game should be fun and simple to do, which is not very compatible with 3D.

  • Like 3
Link to comment
Share on other sites

On 4/18/2021 at 5:02 AM, DrTypo said:

For the moment I'm not planning on doing any game with it.

Wow, this looks like a perfect engine to be used for a Battlezone inspired game.

(using flat shaded, solid polygons instead of the wireframe graphics of the original)

 

Great work!

Edited by phoboz
  • Like 2
Link to comment
Share on other sites

3 hours ago, phoboz said:

Wow, this looks like a perfect engine to be used for a Battlezone inspired game.

(using flat shaded, solid polygons instead of the wireframe graphics of the original)

 

Great work!

We already have similar games like I War and Hoverstrike...

 

But how about a 3D puzzle game like Cubixx? Looks doable on that engine.

 

 Looks 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...