News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Plot 3D Pixel to 2D screen

Started by Farabi, January 04, 2013, 03:01:20 PM

Previous topic - Next topic

Farabi


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


Farabi

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

Contact me at Whatsapp: 6283818314165

dedndave

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

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

Farabi

Quote from: dedndave 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

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

Quote from: jj2007 on January 04, 2013, 05:13:15 PM
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

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

i guess that depends on what you want to do, eh

BogdanOntanu

Quote from: dedndave on January 05, 2013, 01:32:43 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

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

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

Quote from: Rockoon 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.

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

i don't think that remark was aimed at you, farabi - lol

BogdanOntanu

Quote from: Rockoon 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.

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

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.