2
$\begingroup$

Hey guys i was trying to render this scene with shadows. The spheres do not have any acne...but the floor and the walls seem to still have the shadow acne problem... enter image description here

This is the code i have for IsShadowed: bool IsShadowed(World w, Entity point) { // Vector from point to light source Entity v = Subtract(w.light.position, point);

// Magnitude of that vector and it's direction float distance = Magnitude(v); Entity direction = Normalize(v); // Create a ray from the point to the light source Ray r(point, direction); // Get list of intersections in the path of the ray std::vector<Intersection> intersections = IntersectWorld(w, r); Intersection h = Hit(intersections); if (h.t != INFINITY && h.t < distance) return true; else return false; 

}

I am then calling this function in while calculating the color at the hit to determine whether the point is under shadow or not.

Could someone please help me with this issue

Thanks in advance!!

$\endgroup$
2
  • $\begingroup$ The problem seems to be that the ray starts at the point on the surface. Therefore, the first point of intersection may be the wall itself. There are several ways to solve this problem: 1: Move the point slightly in the normal direction of the surface. 2: Save the surface ID to the ray so that an intersection point with this ID is ignored. However, this can lead to problems if 2 surfaces touch each other. ... $\endgroup$ Commented Oct 17, 2024 at 7:40
  • $\begingroup$ @Thomas, Thanks for the help. I did move the point along the normal slightly above the surface by scaling the normal by 0.00001 and adding it the point, and it worked for the Spheres not the Walls and the floor. I increased the scaling factor to 0.01 which then seemed to work perfect. Since i had made those walls from largely scaled spheres, i needed a larger scaling factor. $\endgroup$ Commented Oct 17, 2024 at 8:24

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.