Hi everyone,
I'm trying to get the world space position of a voxel in a heightfield volume using OpenCL. There is a option in the bindings to get “Volume Transform to World”, which returns a float16 OpenCL matrix but I don't understand how to extract a voxel position from this.
My guess is that I have to use gdix and gdiz and multiply them with the matrix but the matrix itself I don't understand.
height_xformtoworld.hi.hi = 0, 0, 0, 4?
height_xformtoworld.hi.lo = 0, ~15?, 0, 0
height_xformtoworld.lo.hi = ~15?, 0, 0, 0
height_xformtoworld.lo.lo = 0, 0, ~15?, 0
There is this weird approx 15 value in there. (I figure it out by dividing the matrix value by 15 to get 1 showing on the heightfield mask). These values are also out of place. I would expect matrix.lo.lo to return the translation part of the matrix but…
Any help to figure this out would be appreciated.
Thx!
Christian
OpenCL Voxel Space to World Space position?
2798 6 3- cs_pix
- Member
- 23 posts
- Joined: July 2015
- Offline
- jlait
- Staff
- 6129 posts
- Joined: July 2005
- Offline
From attribvolume.hip of the OpenCL masterclass:
In this case you are going the other way, but it should be a matter of using the gidx.xyz rather than pos.xyz.
So hi.hi is the translate component, not lo.lo. Note heightfields are stored always with a xy layout in memory, but usually displayed with a zx layout on screen. This would be why the 15s are not along a diagonal.
float4 voxelpos = pos.x * density_xformtovoxel.lo.lo +
pos.y * density_xformtovoxel.lo.hi +
pos.z * density_xformtovoxel.hi.lo +
density_xformtovoxel.hi.hi;
In this case you are going the other way, but it should be a matter of using the gidx.xyz rather than pos.xyz.
So hi.hi is the translate component, not lo.lo. Note heightfields are stored always with a xy layout in memory, but usually displayed with a zx layout on screen. This would be why the 15s are not along a diagonal.
- postas
- Member
- 11 posts
- Joined: June 2008
- Offline
- postas
- Member
- 11 posts
- Joined: June 2008
- Offline
- Konstantin Magnus
- Member
- 670 posts
- Joined: Sept. 2013
- Offline
Could you perhaps provide a code example of getting the world position of voxels in openCL?
So far I have got this, but I would not know how to multiply float3 pos by float16 density_xformtoworld.
So far I have got this, but I would not know how to multiply float3 pos by float16 density_xformtoworld.
float pos_x = gidx * density_voxelsize_x; float pos_y = gidy * density_voxelsize_y; float pos_z = gidz * density_voxelsize_z; float3 pos = {pos_x, pos_y, pos_z};
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
- gorrod
- Member
- 28 posts
- Joined: Nov. 2016
- Offline
It's just like jlait wrote. What you need to do is going the other way around from the world pos to the index.
This is what works for me:
This is what works for me:
kernel void get_world_P( int world_Px_stride_x, int world_Px_stride_y, int world_Px_stride_z, int world_Px_stride_offset, float16 world_Px_xformtoworld, global float * world_Px , global float * world_Py , global float * world_Pz ) { int gidx = get_global_id(0); int gidy = get_global_id(1); int gidz = get_global_id(2); int idx = world_Px_stride_offset + world_Px_stride_x * gidx + world_Px_stride_y * gidy + world_Px_stride_z * gidz; float4 world_pos = gidx * world_Px_xformtoworld.lo.lo + gidy * world_Px_xformtoworld.lo.hi + gidz * world_Px_xformtoworld.hi.lo + world_Px_xformtoworld.hi.hi; world_Px[idx] = world_pos.x; world_Py[idx] = world_pos.y; world_Pz[idx] = world_pos.z; }
- Konstantin Magnus
- Member
- 670 posts
- Joined: Sept. 2013
- Offline
Thank you so much gorrod! I think this works for me, too ; )
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
-
- Quick Links