Logo by LAR2 - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Follow us on Twitter
 
*
Welcome, Guest. Please login or register. March 29, 2024, 10:23:18 AM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1] 2   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Distance Estimated Menger Sponge Normal Calculation  (Read 9990 times)
0 Members and 1 Guest are viewing this topic.
Geometrian
Forums Freshman
**
Posts: 19


« on: March 16, 2013, 12:34:46 AM »

Hi,

I can raytrace Menger sponges using the distance estimator:
Code:
//http://www.fractalforums.com/ifs-iterated-function-systems/revenge-of-the-half-eaten-menger-sponge/15/
float mengersponge_de(int n, vec3 pos) { //by recursively digging a box
float x=pos.x, y=pos.y, z=pos.z;
x=x*0.5+0.5;y=y*0.5+0.5;z=z*0.5+0.5; //center it by changing position and scale

float xx=abs(x-0.5)-0.5, yy=abs(y-0.5)-0.5, zz=abs(z-0.5)-0.5;
float d1=max(xx,max(yy,zz)); //distance to the box
float d=d1; //current computed distance
float p=1.0;
for (int i=1; i<=n; ++i) {
float xa = mod(3.0*x*p,3.0);
float ya = mod(3.0*y*p,3.0);
float za = mod(3.0*z*p,3.0);
p*=3.0;

//we can also translate/rotate (xa,ya,za) without affecting the DE estimate

float xx=0.5-abs(xa-1.5), yy=0.5-abs(ya-1.5), zz=0.5-abs(za-1.5);
d1=min(max(xx,zz),min(max(xx,yy),max(yy,zz))) / p; //distance inside the 3 axis-aligned square tubes

d=max(d,d1); //intersection
}
//return d*2.0; //the distance estimate. The *2 is because of the scaling we did at the beginning of the function
return d;
}
. . . however, when calculating the normal:
Code:
vec3 calculate_normal(vec3 pos) {
return -normalize(vec3(
_DE(pos-vec_epsx) - _DE(pos+vec_epsx),
_DE(pos-vec_epsy) - _DE(pos+vec_epsy),
_DE(pos-vec_epsz) - _DE(pos+vec_epsz)
));
}
. . . the calculation is not accurate for diagonal cuts (that is, any diagonal face has an inaccurate normal). For example, the above code renders the following image, showing a diagonal cut through a Menger sponge. Notice that the horizontal and vertical faces are okay, but the diagonal face is wrong:


This normal calculation works just fine for other fractals.

-G
« Last Edit: March 16, 2013, 12:36:26 AM by Geometrian » Logged
makc
Strange Attractor
***
Posts: 272



« Reply #1 on: March 16, 2013, 04:02:59 AM »

right, but you can't seriously expect smooth normals from code that has "min" and "max" in it tease
Logged
Geometrian
Forums Freshman
**
Posts: 19


« Reply #2 on: March 16, 2013, 05:36:57 AM »

Mmmm; the above was more by way of asking, what can be changed about how the DE or normal are calculated so as to get the correct effect?
Logged
Syntopia
Fractal Molossus
**
Posts: 681



syntopiadk
WWW
« Reply #3 on: March 16, 2013, 01:45:43 PM »

If the distance estimate is correct, I can not see why the normal calculation should fail?

If I do it, I get this:.



This was done by placing this at the end of the DE-calculation:
Code:
dist = max(dist, dot(inputPoint,normalize(cutPlaneNormal)));
Logged
makc
Strange Attractor
***
Posts: 272



« Reply #4 on: March 16, 2013, 01:51:44 PM »

aye but your normal comes from cutting plane; what he did, I think, was using DE as if whole sponge was there.
Logged
eiffie
Guest
« Reply #5 on: March 16, 2013, 04:45:05 PM »

I think if he accurately put the cut plane in the DE function then he would get Syntopia's result - he doesn't show how he cut the sponge???
Logged
Geometrian
Forums Freshman
**
Posts: 19


« Reply #6 on: March 16, 2013, 06:31:39 PM »

aye but your normal comes from cutting plane; what he did, I think, was using DE as if whole sponge was there.
Indeed.

The algorithm begins with a cube, with 3D texture coordinates defined for each vertex corresponding to the 3D position. The ray tracer shades each pixel on the cube by computing a ray from the camera through that pixel based on the texture coordinates of that point. So when the rasterizer draws a fragment with texture coordinate (1,1,1), the fragment program traces an eye ray from the camera through the virtual point (1,1,1).

To achieve cutting, I simply cut the cube. This naturally changes the texture coordinates, and thus the fractal produced.

I would like the planes to be arbitrary and unlimited in number. In particular, in order to draw with the camera inside the fractal, the cube must be clipped by the camera' near plane. It occurs to me that any such irregular normal is necessarily on the surface of the clipped cube (the ray has traveled zero distance). Yet, as far as the distance estimate is concerned, any point on the diagonal is "inside" the sponge!

It's pretty easy to just specify the surface normal of the clipped cube at each surface point, so perhaps is the distance estimator is negative, one immediately stops and uses the surface's normal?

Edit: the result of doing so is the quite lovely:

However, shadow calculation is now broken. Since points on the diagonal start "inside" (according to the distance estimator), shadow rays are automatically occluded!
« Last Edit: March 16, 2013, 07:08:36 PM by Geometrian » Logged
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #7 on: March 16, 2013, 10:13:08 PM »

You simply flag the cut point as "cut to plane" (which plane or other cutting surface if necessary) and calculate the normal of the cutting surface at that point (which should be incredibly simple compared to getting a normal for the actual uncut fractal surface).

Or you don't use the DE at all and use the nearby adjacent surface point method - which is guaranteed to work whether it's a cut point or part of the fractal surface.

Anything else is only useful in the sense of artistic license wink
« Last Edit: March 16, 2013, 10:16:49 PM by David Makin » Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #8 on: March 17, 2013, 01:30:09 AM »

ehrm, people ? those star structures happen to be just the cuts through the menger spone ? interesting....
Logged

---

divide and conquer - iterate and rule - chaos is No random!
tit_toinou
Iterator
*
Posts: 192


« Reply #9 on: March 17, 2013, 03:30:21 PM »

Awesome star & cube structure ! 3D Print this !
Logged

kram1032
Fractal Senior
******
Posts: 1863


« Reply #10 on: March 17, 2013, 07:02:19 PM »

Nice cut-throughs indeed.
I wonder, can somebody come up with a direct 2D description to obtain this?
Logged
Geometrian
Forums Freshman
**
Posts: 19


« Reply #11 on: March 20, 2013, 03:24:08 AM »

Is there a better, special way to calculate normals for the Menger Sponge in particular? I'm finding that sharp corners are incorrectly handled by the gradient calculation above.
Logged
makc
Strange Attractor
***
Posts: 272



« Reply #12 on: March 20, 2013, 09:54:39 AM »

you would need to change DE to return direction vector instead of distance. then old DE = length of that vector, and normal = -that vector.
Logged
tit_toinou
Iterator
*
Posts: 192


« Reply #13 on: April 02, 2013, 10:10:25 AM »

I've created this model for 3D printing since nobody was doing it !



Étoile de Menger 8cm




Triangle de Menger




Losange de Menger


http://www.fractalforums.com/format-printing-and-post-production/3d-printed-cross-sections-of-the-menger-sponge/.

Nice cut-throughs indeed.
I wonder, can somebody come up with a direct 2D description to obtain this?
Why "2D" ?
I didn't use any distance estimation thing.
I created all the faces of the littles cubes and the faces intersecting with the plane. (is that what you mean by direct description ?)
Logged

kram1032
Fractal Senior
******
Posts: 1863


« Reply #14 on: April 02, 2013, 01:27:32 PM »

I simply meant, I'd like to see a purely 2-dimensional iteration formula that exactly describes the Menger Star cut.
Awesome 3Dprintables smiley
Logged
Pages: [1] 2   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
A Menger Sponge Images Showcase (Rate My Fractal) David Makin 5 5107 Last post April 02, 2007, 03:16:32 AM
by bradorpoints
Menger sponge fly-through 3D Fractal Generation twinbee 10 6672 Last post February 16, 2009, 05:43:21 AM
by twinbee
3D menger sponge fly through Movies Showcase (Rate My Movie) DonWebber 0 2731 Last post September 14, 2010, 01:01:18 AM
by DonWebber
3D Julia Set Cross Section Distance Estimated Algorithm 3D Fractal Generation Geometrian 0 2330 Last post May 01, 2013, 11:16:39 PM
by Geometrian
Distance Estimated Soft Shadow Banding Artifact Programming Geometrian 1 2029 Last post May 05, 2013, 06:21:59 PM
by elphinstone

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.192 seconds with 24 queries. (Pretty URLs adds 0.009s, 2q)