DarkBeam
Global Moderator
Fractal Senior
Posts: 2512
Fragments of the fractal -like the tip of it
|
|
« on: November 29, 2015, 11:59:12 PM » |
|
I wanted to realize a sphere that looks like pixelated (Minecraft like)... Without slow methods like "place one cube then another one ..." and a smooth distance estimation. Possible? Knighty if you have some time
|
|
« Last Edit: November 30, 2015, 12:25:59 AM by DarkBeam »
|
Logged
|
No sweat, guardian of wisdom!
|
|
|
lycium
|
|
« Reply #1 on: November 30, 2015, 03:07:27 AM » |
|
Just about to head to bed, but had an idea - is it maybe possible to find the closest cube (pretty easy), and use the DE for that?
|
|
|
Logged
|
|
|
|
Patryk Kizny
|
|
« Reply #2 on: November 30, 2015, 10:54:57 AM » |
|
I would try to use modulo for that so just modulo something small (your pixel) and limit it with the sphere volume (length(v) < R)
|
|
|
Logged
|
Visual Artist, Director & Cinematographer specialized in emerging imaging techniques.
|
|
|
zebastian
|
|
« Reply #3 on: November 30, 2015, 01:14:44 PM » |
|
@Patryck: i think a modulo on the view vector will cubify not to the global grid, but only quantify length in view direction. Anyway, if we map every found point on the sphere surface to the rasterized grid (find nearest cube) we could calculate the distance to this cube. This will have the upside, that this method will work on different kinds of surfaces (but surfaces will need to be smooth) What do you think?
Here some pseudo code:
double distToSphere = getDistanceToSphere(cameraPosition ...); CVector3 hitSphere = cameraPosition + normalizedViewVector * dist; CVector3 centerHitCube = hitSphere - (hitSphere.mod(cubeDimension)); double distToCube = getDistanceToCube(centerHitCube...); return distToCube;
|
|
« Last Edit: November 30, 2015, 02:15:50 PM by zebastian »
|
Logged
|
|
|
|
lycium
|
|
« Reply #4 on: November 30, 2015, 02:21:45 PM » |
|
is it maybe possible to find the closest cube (pretty easy), and use the DE for that?
Anyway, if we map every found point on the sphere surface to the rasterized grid (find nearest cube) we could calculate the distance to this cube.
|
|
|
Logged
|
|
|
|
zebastian
|
|
« Reply #5 on: November 30, 2015, 03:16:44 PM » |
|
oh yeah, thats pretty much it i just wanted to give an example, how to integrate this into the calculation. A more interesting question is: Can we find a way to get a cube which is constant for all view vectors hitting the cube (for arbitrary surfaces). If the surface is disturbed two view vectors close to each other should hit the same cube, but one may be more than boxSize away, so the boxes will have holes
|
|
|
Logged
|
|
|
|
lycium
|
|
« Reply #6 on: November 30, 2015, 04:00:32 PM » |
|
might be necessarily to check the neighbour blocks (also ensuring that their centre is still < radius).
|
|
|
Logged
|
|
|
|
Aexion
|
|
« Reply #7 on: November 30, 2015, 04:28:56 PM » |
|
You can just simulate low resolution coordinates: double Sphere(double x,double y,double z){ x*=45; y*=45; z*=45; x=int(x); y=int(y); z=int(z); x/=45;//just for clarification y/=45; z/=45; const double a=sqrt(x*x+y*y+z*z)-1; return (a); }
|
|
« Last Edit: November 30, 2015, 04:50:48 PM by Aexion »
|
Logged
|
| Fractals all the way.. Incendia for 3D Fractals Aural for Musical Fractals |
|
|
|
Buddhi
|
|
« Reply #8 on: November 30, 2015, 05:55:40 PM » |
|
Nice. I have also looked for it. Thanks for sharing this function.
|
|
|
Logged
|
|
|
|
DarkBeam
Global Moderator
Fractal Senior
Posts: 2512
Fragments of the fractal -like the tip of it
|
|
« Reply #9 on: November 30, 2015, 06:43:15 PM » |
|
Wow interesting solution Ramiro! It is not the correct one (no discontinuity) I was looking for but should work! Still if someone has the smooth solution please post ok.
|
|
|
Logged
|
No sweat, guardian of wisdom!
|
|
|
zebastian
|
|
« Reply #10 on: December 01, 2015, 06:52:24 PM » |
|
great idea aexion, this works quite good on all kinds of primite objects. i did some tests in mandelbulber, see screenshot attached. only change was adding this to modify the position of the surface point, before calculation of the distance:
point.x = ((int)(point.x * 10)) / 10.0; point.y = ((int)(point.y * 10)) / 10.0; point.z = ((int)(point.z * 10)) / 10.0;
@buddhi, what do you think about adding another modifier for this?
|
|
|
|
knighty
Fractal Iambus
Posts: 819
|
|
« Reply #11 on: December 11, 2015, 05:29:36 PM » |
|
interesting! If it is just for a sphere, it should be possible. Something like what lycium suggested. The only general solution I could think about is exactly the one you want to avoid. No miracle! Anyway! One can still use DDA when close to the surface. There is a very cool shadertoy toy out there with a voxelized pac man that mainly uses DE.
|
|
|
Logged
|
|
|
|
knighty
Fractal Iambus
Posts: 819
|
|
« Reply #12 on: December 15, 2015, 01:28:23 PM » |
|
Ok! here is my attempt. It comes with a sphere but it can be used for any DE. The method is general and costly: more than 27 evaluations of the base DE. It can be optimized for convex objects: If one have the gradient of the base DE then it is not necessary to check for 27 cells, only 8.
... And of course use the base DE when far from the object...
|
|
« Last Edit: December 15, 2015, 01:50:06 PM by knighty »
|
Logged
|
|
|
|
|
Aexion
|
|
« Reply #14 on: January 14, 2016, 02:17:56 PM » |
|
If anyone is interested, here's the hexagonal (honeycomb) version: It basically transforms the (x,z) coordinates into the hexagonal (q,r) coordinates, then transforms it again to (x,z). This wasn't easy to guess at first, I tried a lot of formulas and combinations until I comes with this solution. Is not perfect, but its a good start. The code is unoptimized, but that's because I want to make it very clear. double HexSphere(double x,double y,double z){ x*=0.6;//scaling.. don't ask.. x*=45;//45 hexagons by unit y*=45; z*=45; y=int(y); //converts (x,z) to (r,q) const double temp = floor(x + z); const double r = floor((floor(z - x) + temp) / 3.0); const double q = floor((floor(2 * x + 1) + temp) / 3.0) - r; x = 3.0/2.0 * r; //turns back, r q to x z z = sqrt(3.0) * (q + r/2.0); x/=45.0;//just for clarification y/=45.0; z/=45.0; const double a=sqrt(x*x+y*y+z*z)-1; return (a); }
For more info on hexagonal coordinates, this is a good source: http://www.redblobgames.com/grids/hexagons/Hope you like it..
|
|
« Last Edit: January 14, 2016, 09:44:37 PM by Aexion »
|
Logged
|
| Fractals all the way.. Incendia for 3D Fractals Aural for Musical Fractals |
|
|
|
|