Welcome to Fractal Forums

Fractal Software => Fragmentarium => Topic started by: DarkBeam on November 29, 2015, 11:59:12 PM




Title: Pixelated sphere DE?
Post by: DarkBeam 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 ;)
(http://stupidname.org/files/misc/minecraft/voxelspheres/120sphere_thumb.png)


Title: Re: Pixelated sphere DE?
Post by: lycium 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?


Title: Re: Pixelated sphere DE?
Post by: Patryk Kizny 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)


Title: Re: Pixelated sphere DE?
Post by: zebastian 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;


Title: Re: Pixelated sphere DE?
Post by: lycium 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.

 O0


Title: Re: Pixelated sphere DE?
Post by: zebastian on November 30, 2015, 03:16:44 PM
 ;D 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


Title: Re: Pixelated sphere DE?
Post by: lycium on November 30, 2015, 04:00:32 PM
might be necessarily to check the neighbour blocks (also ensuring that their centre is still < radius).


Title: Re: Pixelated sphere DE?
Post by: Aexion on November 30, 2015, 04:28:56 PM
You can just simulate low resolution coordinates:
Code:
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);
}



Title: Re: Pixelated sphere DE?
Post by: Buddhi on November 30, 2015, 05:55:40 PM
Nice. I have also looked for it. Thanks for sharing this function.


Title: Re: Pixelated sphere DE?
Post by: DarkBeam 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. :beer:


Title: Re: Pixelated sphere DE?
Post by: zebastian 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?


Title: Re: Pixelated sphere DE?
Post by: knighty 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.


Title: Re: Pixelated sphere DE?
Post by: knighty 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...


Title: Re: Pixelated sphere DE?
Post by: knighty on December 15, 2015, 01:48:20 PM
BTW!
A little bit off topic but related. This excellent shader by eiffie: https://www.shadertoy.com/view/llf3z8 (https://www.shadertoy.com/view/llf3z8)
also: https://www.shadertoy.com/view/Xlf3zf (https://www.shadertoy.com/view/Xlf3zf)


Title: Re: Pixelated sphere DE?
Post by: Aexion 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.

Code:
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.. :)

 


Title: Re: Pixelated sphere DE?
Post by: Patryk Kizny on January 14, 2016, 04:31:34 PM
Totally Cool!


Title: Re: Pixelated sphere DE?
Post by: DarkBeam on October 02, 2016, 09:49:10 PM
You can just simulate low resolution coordinates:
Code:
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);
}



I finally was able to remove the discontinuity!
I used a smooth function.
Instead of int I split x in xi= int(x) and the fractional part xf = x-xi. Then I did xf = xf^5*p where p ensures that xf(0.5)-xf(-0.5)=1. Any similar treatment can work if you respect the last condition.
Then I sum back xf and xi and use same method as Aexion getting a smooth DE! :) Formula m3f is downloadable in my zip.


Title: Re: Pixelated sphere DE?
Post by: DarkBeam on October 03, 2016, 06:22:04 PM
pretty pic :D

(http://nocache-nocookies.digitalgott.com/gallery/19/4162_03_10_16_12_46_40.png)


Title: Re: Pixelated sphere DE?
Post by: Aexion on October 04, 2016, 05:06:34 PM
Looks very good!!  Congratulations!
:)

Now weave your mathematical magics with Hexes  ;D
I have attached is modified a Fragmentarium example (Mandelbox), just zoom.
Two parameters (in the Mandelbox tab): Shape, that going from Triangles, Hexagons and some sort of futuristic bathroom tiles,
and Segments, that is, the number of tile segments..

Have fun!

  


Title: Re: Pixelated sphere DE?
Post by: Crist-JRoger on October 04, 2016, 05:55:26 PM
Aexion, minekraft comes to fragmentarium  ;D Thank you!


Title: Re: Pixelated sphere DE?
Post by: Crist-JRoger on October 08, 2016, 05:23:40 PM
PseudoKleinian-Voxel. Many thanks Knighty for these scripts  O0

(http://pre14.deviantart.net/c38a/th/pre/f/2016/281/4/0/pseudokleinian_voxel_by_crist_jroger-dakacjo.jpg) (http://orig08.deviantart.net/3e0c/f/2016/281/4/0/pseudokleinian_voxel_by_crist_jroger-dakacjo.jpg)

(http://pre03.deviantart.net/a328/th/pre/f/2016/282/2/3/flying_bridge_by_crist_jroger-dakedu5.jpg) (http://orig13.deviantart.net/a246/f/2016/282/2/3/flying_bridge_by_crist_jroger-dakedu5.jpg)


Title: Re: Pixelated sphere DE?
Post by: Crist-JRoger on November 08, 2016, 02:04:36 PM
Menger into Voxel  ;D

(http://pre09.deviantart.net/628f/th/pre/i/2016/313/d/e/vox_menger_by_crist_jroger-dantkoj.jpg) (http://orig08.deviantart.net/6ce7/f/2016/313/4/b/vox_menger_by_crist_jroger-dantkoj.jpg)


Title: Re: Pixelated sphere DE?
Post by: Crist-JRoger on November 14, 2016, 10:46:04 AM
Is it possible to create several basic shapes and use them both randomly?