Recent

Author Topic: Port "voxel" DOS demo to Lazarus  (Read 10587 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2365
    • UVviewsoft
Re: Port "voxel" DOS demo to Lazarus
« Reply #30 on: August 11, 2020, 01:24:01 pm »
Mr.Madguy had posted his code in attachment in zip.

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Port "voxel" DOS demo to Lazarus
« Reply #31 on: August 11, 2020, 01:31:08 pm »
Oh indeed. I suppose Madguy posted it afterwards.
Conscience is the debugger of the mind

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: Port "voxel" DOS demo to Lazarus
« Reply #32 on: August 11, 2020, 01:32:09 pm »
Where is this final version?

By the way, what was the display error with Code5 with my version on your computer? Can you provide a screenshot?

About TImage, that does not provide the actual drawing times, at least on MacOS and Linux.
This and RunError(204) at termination. Mine version works properly.

P.S. SetDIBitsToDevice is fastest because you draw directly on output surface. It's the best way to simulate VGA Mode13 on Windows. I use it in my universal (same EXE!) DOS/Win BMP View project. But at the end it can be a little slower than hardware BLT on modern hardware, because it's in system memory - not in video memory, as TBitmap is.
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Port "voxel" DOS demo to Lazarus
« Reply #33 on: August 11, 2020, 01:52:50 pm »
This and RunError(204) at termination. Mine version works properly.
Hmmm, though your version did not work on my computer.

Thanks for the screenshot. It seems there is a problem of alignment, maybe because without an alpha channel, it makes 3 bytes long pixels.

Here is a pull request to hopefully fix that using RGBA format. It is a tiny bit slower by 0.5 ms on my computer.
https://github.com/Alexey-T/Voxel_demo_Lazarus/pull/1
Conscience is the debugger of the mind

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: Port "voxel" DOS demo to Lazarus
« Reply #34 on: August 11, 2020, 01:58:35 pm »
This and RunError(204) at termination. Mine version works properly.
Hmmm, though your version did not work on my computer.

Thanks for the screenshot. It seems there is a problem of alignment, maybe because without an alpha channel, it makes 3 bytes long pixels.

Here is a pull request to hopefully fix that using RGBA format. It is a tiny bit slower by 0.5 ms on my computer.
https://github.com/Alexey-T/Voxel_demo_Lazarus/pull/1
And what was wrong with my version? Blank screen? May be I should set Alpha to $ff?

P.S. Try this version with Alpha channel handled properly.
« Last Edit: August 11, 2020, 02:06:22 pm by Mr.Madguy »
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Port "voxel" DOS demo to Lazarus
« Reply #35 on: August 11, 2020, 02:07:10 pm »
The problem was related with the byte order of the channels. You need to look in the image description to know the offset (bit shift) of each channel.

As I have a Retina display, I tried again measuring times displaying at actual pixel size (so 2x smaller). I get the following times:

MacOS 64-bit without Retina scaling
----------------------------------------
Code1: 79ms
Code2: N/A (pixels cannot be accessed)
Code3: N/A (Windows only)
Code4: 2ms
Code5: 2ms
Conscience is the debugger of the mind

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: Port "voxel" DOS demo to Lazarus
« Reply #36 on: August 11, 2020, 06:20:31 pm »
Hi to all, interesting, sometime ago i converted this voxel

We can improve performances by :
1) Using LUT for Sin and Cos
2) Avoid one mul and 4 sub
3) Drawing directly in the "bitmap buffer" instead of in Src (except for CODE 3)

What i do
1) I've added a rendering with the help of my own lib BZScene (https://github.com/jdelauney/BZScene) (CODE6) see GIF : https://imgbox.com/3WIFJgE8#
2) Improve BGRABitmap (CODE4)
3) Fix compatibility with TLazIntfImage (CODE5)
4) Introduce Sin and Cos LUT
5) Improve a little bit calculus (avoid one mul and 4 sub)
6) Added an auto travel throught the world (press key "A" to start)

Now the benchmark the results are the average frame speed of the travel (press key "A")

CPU            : AMD A10-7870K Radeon R7, 12 Compute Cores 4C+8G

Compiled in Release mode and full optimization

Under Windows 64 bits with FPC 3.2 and Lazarus 2.0.10 :

CODE 1 : 64,6442 ms
CODE 2 : 63,2677 ms
CODE 3 :  0,3597 ms
CODE 4 : 1,3309 ms
CODE 5 : 1,3684 ms
CODE 6 : 0,9012 ms

Under Linux (Manjaro) - GTK 2 - with FPC 3.0.4 and Lazarus 2.0.8 (Bench is not accurate)

CODE 1 : 17,9941 ms
CODE 2 : 18,1594 ms
CODE 3 : N/A
CODE 4 : 3,0521 ms
CODE 5 : 3,9579 ms
CODE 6 : 2,6569 ms

See the attached ZIP for code

Cheers



BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: Port "voxel" DOS demo to Lazarus
« Reply #37 on: August 11, 2020, 06:31:50 pm »
if you are interested by voxel landscape if i'm remember well Circular you have made one with BGRABitmap some time ago ( but forgot where to find it)

You can also take a look at one of my BZScene's demo  : https://github.com/jdelauney/BZScene-Samples/tree/master/Graphics/CommancheVoxel based on https://s-macke.github.io/VoxelSpace/VoxelSpace.html
https://www.youtube.com/watch?v=1ytUbSiUvjk  The landscape is rendering with a resolution of 1024x768 (sorry for the quality of this video)

Cheers
« Last Edit: August 11, 2020, 07:48:21 pm by BeanzMaster »

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Port "voxel" DOS demo to Lazarus
« Reply #38 on: August 11, 2020, 07:36:45 pm »
Hi BeanzMaster,

Maybe you can make a pull requests with your changes on the repository:
https://github.com/Alexey-T/Voxel_demo_Lazarus

I did indeed tamper with voxel and added vertical walls:
https://github.com/bgrabitmap/demo/tree/master/voxel
Conscience is the debugger of the mind

AlexTP

  • Hero Member
  • *****
  • Posts: 2365
    • UVviewsoft
Re: Port "voxel" DOS demo to Lazarus
« Reply #39 on: August 11, 2020, 08:02:06 pm »
Yes, I welcome pull-req so I don't need to merge by hands.

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: Port "voxel" DOS demo to Lazarus
« Reply #40 on: August 11, 2020, 08:59:37 pm »
Yes, I welcome pull-req so I don't need to merge by hands.

No problem i'll do and pull a request

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: Port "voxel" DOS demo to Lazarus
« Reply #41 on: August 12, 2020, 01:10:52 pm »
Hi to all

Pull request send ;)

This is the new benchmark :

Code: Pascal  [Select][+][-]
  1.  ______________________________________________________________________________
  2.  |  CPU     : AMD A10-7870K Radeon R7, 12 Compute Cores 4C+8G                 |
  3.  |  OS      : Windows 10 64bit                                                |
  4.  |  FPC     : 3.2.0                                                           |
  5.  |  LAZARUS : 2.0.10                                                          |
  6.  |____________________________________________________________________________|
  7.  |  MEHTOD |  CODE 1  |  CODE 2  |  CODE 3  |  CODE 4  |  CODE 5  |  CODE 6   |
  8.  |=========|==========|==========|==========|==========|==========|===========|
  9.  |  Debug  | 39,9572  | 686,1903 |  0,5434  |  1,2037  |  1,5852  |  0,8171   |
  10.  |---------|----------|----------|----------|----------|----------|-----------|
  11.  | Release | 38,7973  | 671,5684 |  0,4201  |  1,0717  |  1,3234  |  0,7014   |
  12.  |----------------------------------------------------------------------------|
  13.  
  14.  ______________________________________________________________________________
  15.  |  CPU     : AMD A10-7870K Radeon R7, 12 Compute Cores 4C+8G                 |
  16.  |  OS      : Linux Manjaro 64bit                                             |
  17.  |  FPC     : 3.2.0                                                           |
  18.  |  LAZARUS : 2.0.10                                                          |
  19.  |____________________________________________________________________________|
  20.  |  MEHTOD |  CODE 1  |  CODE 2  |  CODE 3  |  CODE 4  |  CODE 5  |  CODE 6   |
  21.  |=========|==========|==========|==========|==========|==========|===========|
  22.  |  Debug  | 11,2772  |  35,1391 |   N/A    |  2,3768  |  3,1898  |  2,1478   |
  23.  |---------|----------|----------|----------|----------|----------|-----------|
  24.  | Release | 11,2917  |  37,6608 |   N/A    |  2,1562  |  2,7684  |  2,0740   |
  25.  |----------------------------------------------------------------------------|

We can see Canvas method (CODE2) under Windows is a pit of doom
With IntfImage (CODE5) background is not cleared. The Bitmap is drawn on canvas with transparency, don't say why  :o

Under Linux :
  with CODE1 and CODE2 performances are little bit better in Debug mode than Release mode  :o
  BGRABitmap CODE4 and BZScene CODE6 are the best and are very close
 
Under Windows :
  the native method is the best and after is BZScene, which are below one ms

Under Windows and Linux : IntfImage CODE5 is a little slower than CODE4 and CODE6.

Cheers



AlexTP

  • Hero Member
  • *****
  • Posts: 2365
    • UVviewsoft
Re: Port "voxel" DOS demo to Lazarus
« Reply #42 on: August 12, 2020, 01:20:16 pm »
Good, tkx. If you can 'isolate' that pit of doom, in some small win32 demo- it may help to fix it...

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: Port "voxel" DOS demo to Lazarus
« Reply #43 on: August 12, 2020, 01:34:30 pm »
Good, tkx. If you can 'isolate' that pit of doom, in some small win32 demo- it may help to fix it...

It seems to be something with LCL Canvas methods and Windows.
Perhaps by using a TPaintBox it will be better

AlexTP

  • Hero Member
  • *****
  • Posts: 2365
    • UVviewsoft
Re: Port "voxel" DOS demo to Lazarus
« Reply #44 on: August 12, 2020, 01:41:35 pm »
We can 'isolate' the slowdown on some demo? I didn't read code detailed.

 

TinyPortal © 2005-2018