Author Topic: Plot 3D Pixel to 2D screen  (Read 16701 times)

Farabi

  • Member
  • ****
  • Posts: 968
  • Neuroscience Fans
Plot 3D Pixel to 2D screen
« on: January 04, 2013, 03:01:20 PM »
Code: [Select]
f3DTo2DF proc uses esi edi X:real4,Y:real4,Z:real4,F:real4,intScreenW:dword,intScreenH:dword
LOCAL xres,yes:dword
shr intScreenW,1
shr intScreenH,1
;X:= ((X/Z) * F) + intScreenW/2
;Y:= ((Y/Z) * F) + intScreenH/2

fld X
fdiv Z
fmul F
fiadd intScreenW

fld Y
fdiv Z
fmul F
fiadd intScreenH


ret
f3DTo2DF endp

About 35 milions fill rate each second. I dont know is it fast enough or not. But on a demo I saw, at least you need 60 millions fill rate each second to gain a good software renderer.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: Plot 3D Pixel to 2D screen
« Reply #1 on: January 04, 2013, 03:13:51 PM »
SSE   :biggrin:

Farabi

  • Member
  • ****
  • Posts: 968
  • Neuroscience Fans
Re: Plot 3D Pixel to 2D screen
« Reply #2 on: January 04, 2013, 03:19:57 PM »
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: Plot 3D Pixel to 2D screen
« Reply #3 on: January 04, 2013, 03:53:41 PM »
you could speed that code up a bit by pre-calculating F/Z

;M = F/Z
;x= X*M + intScreenW/2
;x = Y*M + intScreenH/2

it eliminates an FDIV

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: Plot 3D Pixel to 2D screen
« Reply #4 on: January 04, 2013, 05:13:15 PM »
See if you can replace the fiadds with fadds, it's much faster.

Farabi

  • Member
  • ****
  • Posts: 968
  • Neuroscience Fans
Re: Plot 3D Pixel to 2D screen
« Reply #5 on: January 04, 2013, 10:54:39 PM »
you could speed that code up a bit by pre-calculating F/Z

;M = F/Z
;x= X*M + intScreenW/2
;x = Y*M + intScreenH/2

it eliminates an FDIV

Yeah, good Idea. I did not even think about that

See if you can replace the fiadds with fadds, it's much faster.

Whoa, thanks.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

BogdanOntanu

  • Global Moderator
  • Member
  • *****
  • Posts: 64
    • Solar_OS, Solar_Asm and HE RTS Game
Re: Plot 3D Pixel to 2D screen
« Reply #6 on: January 05, 2013, 12:41:37 AM »
You are wasting your time.

You are never going to plot 3D pixels on screen fast enough by using CPU / FPU or SSE2/4/ whatever.

The correct way to do this is to use the hardware accelerated functions from DirectX or OpenGL

Ambition is a lame excuse for the ones not brave enough to be lazy, www.oby.ro

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: Plot 3D Pixel to 2D screen
« Reply #7 on: January 05, 2013, 01:32:43 AM »
i guess that depends on what you want to do, eh

BogdanOntanu

  • Global Moderator
  • Member
  • *****
  • Posts: 64
    • Solar_OS, Solar_Asm and HE RTS Game
Re: Plot 3D Pixel to 2D screen
« Reply #8 on: January 05, 2013, 01:48:33 AM »
i guess that depends on what you want to do, eh

Yes... but however :D

Even for an software render algorithm the most time consuming operation is NOT going to be plotting pixels on screen and the final 3D to 2D transformation.

You will have to calculate the pixel's color first and this is what is going to take a lot of time.

For example going to all the 3D objects lists and intersecting all the rays (assuming raytracer) with all the objects and all the math involved...

Then add reflections, multiple or soft lights, refraction and transparency, add the materials, bumps, displacements and shading algorithms and textures...

My guess is that the final 3D to 2D pixel transformation is not really going to matter at all when comparing with all of the above 3D calculations.
Ambition is a lame excuse for the ones not brave enough to be lazy, www.oby.ro

Rockoon

  • Guest
Re: Plot 3D Pixel to 2D screen
« Reply #9 on: January 05, 2013, 01:03:21 PM »
Sigh...

A raytracer would be doing a 2D coordinate to 3D Ray transform, not a 3D coordinate to 2D coordinate transform (aka projection.)

It helps when you don't act like you know what you are talking about when you know that you don't know what you are talking about.

Farabi

  • Member
  • ****
  • Posts: 968
  • Neuroscience Fans
Re: Plot 3D Pixel to 2D screen
« Reply #10 on: January 05, 2013, 01:49:19 PM »
Im impressed with this project http://users.softlab.ntua.gr/~ttsiod/renderer.html it is a pure software rendering. Not so fast on my computers, but it gives freedom for me to do anything what I want.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Farabi

  • Member
  • ****
  • Posts: 968
  • Neuroscience Fans
Re: Plot 3D Pixel to 2D screen
« Reply #11 on: January 05, 2013, 01:51:50 PM »
Sigh...

A raytracer would be doing a 2D coordinate to 3D Ray transform, not a 3D coordinate to 2D coordinate transform (aka projection.)

It helps when you don't act like you know what you are talking about when you know that you don't know what you are talking about.

You still need that code to render the basic object. I did not even finished the direction vector for the ray path.

Well, I wont finished it on a year or so. But at least it will satisfied my curiousity. I know how to do raytrace for a simple primitives like globe. It just a simple straigh line trace and wait until it hit the object. Well, I had the tutorial. So I guess I should be fine.

http://www.codermind.com/articles/Raytracer-in-C++-Part-I-First-rays.html
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: Plot 3D Pixel to 2D screen
« Reply #12 on: January 05, 2013, 04:07:19 PM »
i don't think that remark was aimed at you, farabi - lol

BogdanOntanu

  • Global Moderator
  • Member
  • *****
  • Posts: 64
    • Solar_OS, Solar_Asm and HE RTS Game
Re: Plot 3D Pixel to 2D screen
« Reply #13 on: January 05, 2013, 09:23:43 PM »
Sigh...

A raytracer would be doing a 2D coordinate to 3D Ray transform, not a 3D coordinate to 2D coordinate transform (aka projection.)

It helps when you don't act like you know what you are talking about when you know that you don't know what you are talking about.

Here: http://www.oby.ro/sol_ray/files/sol_ray_2006_07_31_bin.zip

Go get this realtime 3D raytracer written by me at least 6 year ago in ASM using the FPU. I guess this is kind of what Farabi is trying to do.

Try menu option File->Load Texture and then Trace->Start and Animate->Start and then play with the options (shadows, specular, etc)
Then you can select camera or sphere 1 and move them or move around.
PageUp and Page Down moves the camera or selected object on Z axis and  arrow keys move on X and Y axis respectively.

Then stop dreaming that I do not know what I am speaking about  :bgrin:

In the intro screen of Hostile Encounter game there is a much bigger and nicer version of this used to render the Earth like planet.

Raytracing is a method of rendering a 3D scene on a 2D screen ;)
It has some advantages (shadows, reflections, objects intersections, etc) but it is also very slow when compared to scan-line algorithms that are currently in use in 3D video cards.


Ambition is a lame excuse for the ones not brave enough to be lazy, www.oby.ro

Rockoon

  • Guest
Re: Plot 3D Pixel to 2D screen
« Reply #14 on: January 06, 2013, 01:12:05 AM »
If you think a raytracer has to do 3D to 2D projection, then you are truly dreaming.

Raytracers begin with the pixel coordinate. For each pixel... cast ray into scene graph, performing intersection tests, ...

Its rasterizers that need to project from 3D to 2D. For each triangle in view frustum... calculate pixel coordinates of each vertex, then scan down the left and right (or top and bottom) edges...

How do you not know this? Makes us wonder how much of that project is yours.