Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Does anyone know how to make a 3d poinrt cloud of your 3d model with texture?

Author
Message
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 14th Oct 2012 16:32
Hi guys i'm trying to make a 3d model of just points that doesn't render polygons. Does anyone know how you would do one? I know you have to store x,y,z and normals. However, if each pixel is in integer base and your 3d model vertices are in float base I don't see this working.

darkvee
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 14th Oct 2012 17:05
Convert to floats?

Do you mean creating a sprite of sorts at each pixel point?

That would be a mahusive amount of processing I can guess...

Have you looked at DarkClouds? maybe see how it works, there should still be a working demo for it... [I mean study it]

Unless your intended usage is different... maybe shed more light on your intention of usage and more directed answers or more directed questions can be asked

darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 14th Oct 2012 18:36
Like a 3d model with 3d information but behaves like a 3d model with no polys.

darkvee
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 14th Oct 2012 18:43 Edited at: 14th Oct 2012 18:44
<HEAD EXPLODES>




RonsWare
15
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Netherlands
Posted: 14th Oct 2012 19:12
Do you mean the use of particles ?

Cheers Ron.

Programming is learning
Aaron Miller
20
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 14th Oct 2012 19:20
You want just 3D points (as in X, Y, Z) and color information? Or, do you want voxels?

If you want the former, run through each triangle in the model, and interpolate across each of its vertex positions. At each interpolation point, sample the relevant texture(s).

If you want the latter, there are a couple ways to do this. Have a look at sparse voxel octrees. A simple method though, would be to render your model in layers (discard fragments outside of a certain depth range when rendering, do multiple passes).

If you're looking for a premade solution, there might be some, but I'm not aware of them.

If you don't mind my asking though, why?

Web - Tweets
“I'm going to punch DXGI in the face. Repeatedly.” ~Aras Pranckevicius
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 14th Oct 2012 21:52
Hi I guess like voxels but more of point cloud.
Here is a point cloud. http://upload.wikimedia.org/wikipedia/commons/4/4c/Point_cloud_torus.gif

Quote: "If you don't mind my asking though, why?"

I have some theory and other ideas of using it for gaming.

darkvee
Aaron Miller
20
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 15th Oct 2012 00:40 Edited at: 15th Oct 2012 00:43
Then the former, which are point clouds.
Quote: "If you want the former [just 3D points (as in X, Y, Z) and color information], run through each triangle in the model, and interpolate across each of its vertex positions. At each interpolation point, sample the relevant texture(s)."


Edit: A simpler method came to mind. Subdivide the model until there are a sufficient number of vertices (points). Remove all redundant information (keep UV information though). Triangles are no longer necessary, just render the points. (Fill mode would be "point.")

Does any of that work for you?

Web - Tweets
“I'm going to punch DXGI in the face. Repeatedly.” ~Aras Pranckevicius
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 15th Oct 2012 01:27
Well ya but to render it if your vertex data has floats that means you can't just render pixels which uses a integers. I know how you store it I think but how do you render it if it's using floats for the vertices. When you have to convert it to pixels.

darkvee
Aaron Miller
20
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 15th Oct 2012 02:23 Edited at: 15th Oct 2012 02:27
With the GPU you would render it with the "point" fill mode. Judging from the documentation DBPro doesn't offer a "set object point" setting or another mode value for "set object wireframe" (such as "2") to change the fill mode.

If you want, you could give shaders a try for rendering the points. You would just set "FillMode = Point;" inside of the pass. This hasn't been tested, but should work:


If, however, you want to actually "software render" these point clouds, you just transform the points by a world view projection matrix, which moves them from local (model) space to "clip space." Transforming from clip space to screen space is pretty easy though. I have some code that does this, but it's written in C, so I'm not sure how helpful it'll be. Still, if this is what you want to do, here's the code:



The relevant function is "vertextransform" which I'll list here:



If you want to render voxels, there's a lot of research in this area already. GigaVoxels, Sparse Voxel Octrees, and other methods come to mind. The biggest issue with these types of rendering methods is the amount of data necessary to actually render the scene. I can't really comment on this since I haven't sufficiently experimented with SVOs yet. (Though they are very tempting.)

Good luck on your venture.

Web - Tweets
“I'm going to punch DXGI in the face. Repeatedly.” ~Aras Pranckevicius
Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 15th Oct 2012 05:12
for every vertex in object render a 3d point (commands available in Cloggy's 3d plugin). You don't have to convert anything to pixels, gpu does that

Duke E
17
Years of Service
User Offline
Joined: 10th Mar 2009
Location:
Posted: 15th Oct 2012 15:12 Edited at: 15th Oct 2012 15:17
@darkvee
You are describing "Point sprites".

It can be done in DBPro by using a shader that displays an image on each vertex coordinate instead of using 3 vertex points to display a surface polygon.

"Dark coder" made a proof of concept demo shader here:
http://forum.thegamecreators.com/?m=forum_view&t=121302&b=1
(some posts down the page)

I have done a GPU only particle system using this method and it is pretty efficient, but there are problems with it...

The foremost problem is the graphics card drivers.
The point sprite support has no set standard, NVidia and ATI cards displays them differently.

Some problems:
ATI can't display point sizes above a certain magnification.

NVidia drivers past version 198.xx have no built in clipping plane for vertexes approaching the camera, this results in very erratic behavior (can be overcome by making a calculated clip plane in the shader though).

I have read elsewhere that point sprite support is not recommended at all nowadays, think it was some XNA documentation. And that using planes is also more efficient in contemporary graphics drivers.

If point sprites are to be used on a specific hardware setup you know is working i'd say it's ok, but using it for games where the end user can have any type of graphics hardware and driver versions it is only looking for trouble.

Regards
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 15th Oct 2012 16:19
@darkvee
Well, here's an idea: if you know anything about memblocks, you can make your model into a memblock. Go through the vertices and for each one, convert it to 2D. Write the 2D version to the back buffer if it's within the screen.

Depending on the zvalue relative to the camera, you can decide how dark or light the pixel. As far as the texture, you could figure out the pixel color from the UV values since those values represent a percentage of the position within the texture.

Enjoy your day.
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 15th Oct 2012 22:52 Edited at: 15th Oct 2012 23:13
Wow very great stuff guys.

Thanks for all the help you have gave me. I will have to check this all this out .

Hi Aaron Miller to bad I don't understand directx yet but looks like a very efficient way.

Hi Duke E,

Ahh point sprites I dunno maybe it is that.
.
Latch , Yes I know how to do memblocks. I made one that stores the x,y,z normalX, normalY, normal,z ,u,v. The problem is when I try to convert this to a image that holds 3d info in it.The only x,y, brg colors and alpha doesn't seem to fit the bill. I can't figure out how you would do this. You have to convert it into a image right? Here is some example code using memblocks



darkvee
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 15th Oct 2012 22:57 Edited at: 15th Oct 2012 22:58
Hi there. I`ve been playing with something like that time ago. If we just need a render of point of our object, we could use vertexdata commands to check where to place a simple plain to make our object with just points...

This example use an sphere 10x10 grid


This other example makes a terrain using a 100x100 pixels image...we can use any grayscale image to render this example





Cheers.

I'm not a grumpy grandpa
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 16th Oct 2012 01:56 Edited at: 16th Oct 2012 01:58
@Chafari
I was thinking about that too. Hows the performance?

@darkvee
Here's another idea that may work, though I'm not 100% sure. Set the vertex colors to something, and texture the object to black. Then set the object to transparent. I'm not sure if the texturing overrides the vertex colors.

Or you may be able to set the diffuse of the object to black, set the vertex colors to a specific color, then set the emmissive equal to the vertex colors. And set transparency on.

As far as the conversion from 3D to 2D, there is lots of information around on how to do that. Without getting into the full details here:

1. Basically, the Z value tells you the depth of a point = how far away from the camera the point is.

2. You use the Z value to calculate perspective.

3. If you divide the X and Y value by Z, it gives a rough 2D translation of where X and Y will fall on the screen.

4. Starting with the center of the screen, assuming that is where the camera is, the generic formula is something like
ScreenX = (X3d / Z3d) + halfwidth
ScreenY = halfheight - (Y3d / Z3d)

5. In order to match these points correctly to your 3D world, you have to figure out the skew for the X and Y based on the field of view. I call this the Z distance into the screen where 1 3d unit is the same value as a pixel.

the formula for y is
Ydist=halfheight/(tan(fieldofview/2))

and x
Xdist=halfwidth/(halfwidth/Ydist))

so your screen values for your x and y become
Sx=ScreenX/Xdist
Sy=ScreenY/Ydist

That's with never changing the camera angle or position. I think, however,that if you make a mesh from an object, it's vertices become where ever it is in world space so if you kept your true object hidden and make a mesh from it whenever you wanted the 2d cloud, you wouldn't have to calcualate your own rotations and positions for the points before converting them to 2D.

Enjoy your day.
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 17th Oct 2012 15:22
Hi chafari,

That is pretty cool using that method.


Hi Latch,
Thanks. I will try to see if I get this working and post results after.

darkvee
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 17th Oct 2012 16:28 Edited at: 17th Oct 2012 16:29
Well Latch here is what I got. It's to small to tell if it's even working. Does the math look correct?



darkvee
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Oct 2012 18:32
@Duke E Thanks for that point sprite link - it seems to have escaped my notice.
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 18th Oct 2012 05:29 Edited at: 18th Oct 2012 05:41
@darkvee
You sorta got it. I really didn't explain it well because I was rushing. I see where my psuedo code might cause some problems.

Your math looks about right for what I said, the problem is in what I didn't say!

The goal is to find an imaginary distance where 1 3d unit equals 1 2d pixel. We'll call it the viewing plane and it is some z distance into the screen.

When I mentioned the field of view (FOV), I meant for you to think of it as the angle of the camera lens. For DB, the default is given in radians at 3.14/2.905 . That's about 62 degrees. So, solving for ydist and xdist is the same idea, we just have to use the correct FOV:



And like we saw before, the perspective for the 2D screen values of X and Y are really just the 3d x and y values divided by the z value

x2D = x3D/z3D
y2D = y3D/z3D

Now, an important piece that I left out before, is the camera distance. This is the difference between z3D and the camera position. This will affect the scaling of your points so we need to adjust z3D:

adjz3D = z3D-cameraZ

Now, we use the center of the 2d screen as an offset so our points initially are at a camera position of 0,0,cameraz .

x2d = (x3d/adjz3d)+halfscreenwidth
y2d = halfscreenheight-(y3d/adjz3d)

Ok, now the reason why we wanted the distance to the viewing plane: we have to make sure our 3d points are scaled into the 2d world. I originally listed this step as a division because I was thinking about the ratio between 2d/3d. To bring the 3d into the 2d we have to scale it up according to our distance values so we have to adjust our original 3d values for x and y:

x3d=x3d*xdist
y3d=y3d*ydist

So our final equation for the 2d x and y screen coordinates becomes:

screenX = ((x3d*xdist)/adjz3d)+halfscreenwidth
screenY = halfscreenheight - ((y3d*ydist)/adjz3d)

To be sure you don't get a division by zero, test adjz3d. If it is zero the before doing any division, screenX and screenY become:

screenX = halfscreenwidth
screenY = halfscreenheight

So that's the basics. You'd have to expand on the idea if you want to rotate the points or the camera. Even if you move the camera.

However, I think that by creating a mesh from an object and then a memblock, I think all of the vertices are adjusted to world coordinates so for the 2d vertex drawing, you may not have to do any matrix math.

EDIT
I just tried it out in DBC and it totally works! I'm rotating a sphere using DB commands, updating the mesh and matrix and just drawing the vertices in 2d and they are rotating just fine! If it works in DBC, it'll work much faster in DBPro. That's just the verts though, I haven't tried adding any texturing.

Enjoy your day.
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 18th Oct 2012 20:02 Edited at: 18th Oct 2012 20:09
Hi Latch,

I got it working! Thanks man for all your help I couldn't of done it without your assistance. You have been a very big help and I appreciate it.

Now I need to get the texture working.

I have it showing it works. I didn't add vertexdata rotations but I did make it rotate randomly when it loads up.

Here is the code:



Try using 0.1 for a much point feel using this circle screen(i).X+t# ,screen(i).Y,0.1

darkvee
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 18th Oct 2012 22:03
Hi Aaron Miller,

Sorry I didn't realize you had shader code that does this. I just saw the c++ code and decided I can't use this anyways because I don't understand directx yet. Anyways thanks for the help and i'm very sorry I didn't see this.

darkvee

Login to post a reply

Server time is: 2026-07-07 07:57:44
Your offset time is: 2026-07-07 07:57:44