Raymarching idea: Invertible Surfaces
category: code [glöplog]
Another question for the raymarching community :]
I wonder whether this is a novel idea - or a known technique.
The idea is to define the distance function also for the inside of each object. On the outside, it will return the distance to the surface as usual. On the inside, it will also designate the distance to the closest surface point - but with a negative sign.
(In the distance functions I have seen, it seemed that on the inside of objects, the distance function was 0 or a random negative value.)
This way, you gain multiple advantages:
-Every object, even complicated ones, can now be inverted (space becoming solid and solid becoming space), simply by negating the distance function. Could be useful for CSG. And (admittedly a minor advantage) you can do with fewer primitives.
-You can also travel through the inside of objects (until you reach the surface). This would allow for transparent objects. And even refraction.
-In addition to spherically growing objects (by subtracting a fixed value from the distance function), you can also spherically shrink them (by adding a fixed value). (This is not possible without invertible surfaces as distances very close to the object would not be defined properly.)
As an example of an invertible surface (for some reason I always want to spell it 'invertable'), here's an invertible cube:
I wonder whether this is a novel idea - or a known technique.
The idea is to define the distance function also for the inside of each object. On the outside, it will return the distance to the surface as usual. On the inside, it will also designate the distance to the closest surface point - but with a negative sign.
(In the distance functions I have seen, it seemed that on the inside of objects, the distance function was 0 or a random negative value.)
This way, you gain multiple advantages:
-Every object, even complicated ones, can now be inverted (space becoming solid and solid becoming space), simply by negating the distance function. Could be useful for CSG. And (admittedly a minor advantage) you can do with fewer primitives.
-You can also travel through the inside of objects (until you reach the surface). This would allow for transparent objects. And even refraction.
-In addition to spherically growing objects (by subtracting a fixed value from the distance function), you can also spherically shrink them (by adding a fixed value). (This is not possible without invertible surfaces as distances very close to the object would not be defined properly.)
As an example of an invertible surface (for some reason I always want to spell it 'invertable'), here's an invertible cube:
Code:
public static double invertibleCube(V v, double size) {
double x = size-Math.abs(v.x), y = size-Math.abs(v.y), z = size-Math.abs(v.z);
if (x <= 0 || y <= 0 || z <= 0)
// outside
return new V(Math.max(-x, 0), Math.max(-y, 0), Math.max(-z, 0)).len();
else
// inside
return -Math.min(Math.min(x, y), z);
}
Make a demo or be quiet
I'm not sure but I think that usually happens with most distance functions.
done here, where the sphere shits the cube upwards. But this shows both surfaces always, as there's a hole on top of the sphere.
..and yeah, make a demo already :) You'll figure all this out from experimentation.
Quote:
Make a demo or be quiet
So you can't handle talking? You better stay out of the BBS.
Quote:
..and yeah, make a demo already :)
Making a demo requires a dedication I think I don't want to invest at this point. What's wrong with talking about technique? I like to discuss things and lay ground work. Maybe another place would be better for this anyway - to get away from the pointless crap responses one gets on pouet.
You know what?
You guys need to fuck more.
I might consider bothering with you again when you've grown up.
You guys need to fuck more.
I might consider bothering with you again when you've grown up.
Well, I didn't realize showing you an example of your idea was a crap response :) . And can we be blamed for trying to bolster some productivity and bring in some new releases?
Ferris: no, he's right - because nothing is more grown-up than insinuating that someone else does not get laid.
literal lol
haha what a monkey
Quote:
Making a demo requires a dedication I think I don't want to invest at this point. What's wrong with talking about technique? I like to discuss things and lay ground work. Maybe another place would be better for this anyway - to get away from the pointless crap responses one gets on pouet.
there's nothing wrong with discussion. i can't answer your post because i dont know squat about distance functions. though, instead try be patient, some smart guy will eventually answer your question(s).
vibrator has a point. this is a bbs and it's the right place to talk/ask/discuss. "make a demo or be quiet" is not logical just like "you guys need to fuck more" isn't.
vibrator, your nick is killing me. "vibrator has a point" hahahahaha
vibrator, your nick is killing me. "vibrator has a point" hahahahaha
Quote:
The oldskool pouët BBS is not the demoscene, please visit a demoparty. This is merely a forum for sceners, with obviously too much free time, to release their frustrations and request salted communitary feedback, as opposed to polluting the prod comments section.
New users: please take your vaccines before entering, don't expect instant praise, and try not to feel easily insulted.
Old users: please don't feed the trolls. Reoccuring annoying behavior will result in a heavily subjective ban. Just try not to piss off 90% of our active users with childish and/or idiotic behaviour and you should be safe.
You have been warned.
Skate: if you have read the whole thread you can clearly see that Ferris did in fact answer him, but vibrator just chose to be a dick anyway. That's the life of the BBS.
Ugly as fuck - but just a proof of concept.
3 RM-Steps:
Code:
RM to surface
refract (e.g. AIR -> GLASS)
RM through surface
refract (e.g. GLASS -> AIR)
RM to next surface
But walking through the surface is somewhat pretty ugly - the distance is negative and in the beginning very small - so you start with a very (too) small step size inside the object - and I had some trouble with the epsilons...
+ You do not want refraction rays only.
vibrator, i would say most raymarchers out there are using signed distance fields (negative inside of objects). it helps getting better normals.
as for your "invertible" cube, this is how you would usually do it in an optimized way:
this was posted long ago in some of the other raymarching threads here at pouet, but it's true that the info is all scattered all over these threads and makes it difficult to find the info. So, answering your question, no, it's not a new thing, this idea is currently used in demos/intros already.
as for your "invertible" cube, this is how you would usually do it in an optimized way:
Code:
float signedDistToBox( in vec3 p, in vec3 b )
{
const vec3 di = abs(p) - b;
return min( maxcomp(di), length(max(di,0.0)) );
}
this was posted long ago in some of the other raymarching threads here at pouet, but it's true that the info is all scattered all over these threads and makes it difficult to find the info. So, answering your question, no, it's not a new thing, this idea is currently used in demos/intros already.
Uhmmm, what about cutting out stuff from the distance function that is behind the viewer that looks from the first hit point in direction of the refracted ray...
Here we go... Some more testing with refractions...
Two spheres
Cube & Sphere
Damn those artifacts... Maybe sth like total internal reflection? Epsilon screwd up?
Two spheres
Cube & Sphere
Damn those artifacts... Maybe sth like total internal reflection? Epsilon screwd up?
las: Perhaps you need to need to step back/forth a small amount along the normal for the reflection/refraction to make sure the ray doesn't immediately intersect with the object it hit?
I thought I already did that... I rechecked the code and I obviously failed... ;)
Quote:
las: Perhaps you need to need to step back/forth a small amount
Vibrator already said
Quote:
You guys need to fuck more.
That's what she said!
Quote:
Making a demo requires a dedication I think I don't want to invest at this point.
pfft. so, you'd rather spent time updating pouet on your latest ideas of raymaching?!
if you shut down pouet and enter your thoughts into your editor and compile them - et voila - demo on the way!