-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing sdfu in a raytracer #8
Comments
So I think the main problem here is that you're using so your main tracing loop would then look like: for _march in 0..MAX_MARCHES {
let point = ray.point_at_parameter(t);
let dist = self.sdf.dist(point); // remove abs here
let eps = f32::from(0.00005 * SDF_DETAIL_SCALE).max(f32::from(0.05 * SDF_DETAIL_SCALE));
if dist.abs() < eps { // abs applied for comparison
hit = true;
break;
}
t = t + dist; // this addition can now be negative so you can then approach the surface again
if t > t1 || t.is_nan() {
break;
}
} Also you will likely need to reevaluate this if you try to do refraction, i.e. have rays that pass through the inside of an SDF, in which case you could special case the tracing loop to negate the distance or something like that. |
oh also, one more thing to point out here is that if you're not using a function like |
Actually I think I misspoke here and indeed my code likely has the same issue, the real reason I did this was because of the refraction thing I mentioned, and then didn't reevaluate if there was a better way to solve the problem (which there likely is). |
Dear Gray, everything works fine, thanks for your detailed answers. You can find a simple example here. https://github.com/edap/sdfu-example/blob/main/src/main.rs I have a couple of questions (again):
fn bounding_box(&self) -> Option<Aabb> {
Some(Aabb {
min: sdf.translation
- Vec3A::new(radius(),radius(), radius()),
max: sdf.translation
+ Vec3A::new(radius(), radius(), radius()),
})
} The problem is that I can not read the radius and the position out of `sdfu::sdf.
|
Hello, I am trying to use this crate in my raytracer that has been written in rust following the first book "raytracer in a weekend" https://raytracing.github.io/books/RayTracingInOneWeekend.html.
Now I would like to add sdf shapes to list of the hittables objects. I have looked at your amazing path tracer
rayn
to see how it is implemented https://github.com/fu5ha/rayn/blob/master/src/sdf.rs but unfortunately my unfamiliarity with SIMD made your code a little hard to read for me. Therefore, I have implemented a classic raymarching function in thehit
function.And I have added a simple sphere to my world.
Unfortunately, something is wrong. The central part of the sphere is missing
The first thing that I have thought is that the sphere is too big and it is clipped out. So I change the radius of the sphere from 1.0 to 0.5. An the sphere disappear completely.
I set the radius back to 1.0, and I increase the epsilon value, so, in the hit function I change this line:
to
With this result.
The "hole" in the middle of the sphere is smaller, but the sphere is also obviously bigger. Of course I have tried a small
eps
, like 0.0015, and this is the result.Now, I think that what it is happening is that the rays closer to the sphere the first time do not hit the sphere, but in the iteration in the raymarching loop
t
becomes too big and it pass through the sphere.In your path tracer, you are multiplying
eps
by a function bounded to the value oft
. https://github.com/fu5ha/rayn/blob/master/src/camera.rs#L210Before to do something similar, I would like to understand if I am doing something wrong in using your library inside a simple ray tracer, as for my understanding a fixed epsilon value should work as well.
Any hints or suggestion is really appreciated.
The text was updated successfully, but these errors were encountered: