Closed BudgiePanic closed 8 months ago
debugging pixel c: 785 r: 762
moving the light source to the camera location while keeping the cube rotated -45 degrees on y axis produced this image
suffice to say these shadows should not be present, why are these pixels being flagged as in shadow?
I think this would be easier to debug with a normal cube instead of a compound shape as the shape a in the dice compound shape
I think what is happening is:
but this needs to be confirmed
I think we got it wrong maybe we are supposed to perform all intersection tests first and then do the filtering of intersections at the end
the only difference is we need to curry the predicate down to the composite shapes like we are doing now?
lets make the unit tests and try this approach
for reference (to place a cube in the middle of the dice dimples)
new Cube(Transforms.identity().translate(1f, 1f, 1f).scale(0.50f).assemble(), diceMaterial),
new unit tests to capture the 3 lighting conditions were created in commit https://github.com/BudgiePanic/PushingP/pull/73/commits/4fe548091468feb7db391db4053889add86e15e7
all of these tests pass when the dimple material does not cast shadows
the dimples are supposed to cast shadows
5 test conditions to verify in compound shape demo
it would be nice if concrete shapes had a name attribute to help identify which shape is which in the compound union cube
found Heisenbug with TimingWrapper camera class
in the unit test I wrote, a normal camera was used. The output was different to the CompoundShapeDemo despite being the exact same scene
changing the unit test to use a TimingWrapper camera caused the output to become the same, but even more confusing, the output remained the same even after changing back to a normal camera
in a simplified test case, it looks like the bug is in the filtering of compound intersections method,
specifically in the case where left
shape only produces one intersection (such as a plane, or high angle intersect on a cylinder with no lids)
when this is the case, the shadow ray intersects with the cylinder behind it, and has 2 intersections with the difference sphere in front of it. These sphere intersections are not being filtered, when logically they ought to
optimization for the future:
I believe the root cause of the issue is that for shapes that do not enclose a volume, it is possible to cast a ray that will intersect with the shape only 1 time. examples include
when this occurs the iterative algorithm in the CompoundShape::filter
function will be in the following state:
difference
operation will always passwe need to be more selective about when we set the inLeft
flag because the ray might actually be leaving the object when it's first intersection is encountered
CompoundShapeTest
inLeft
flag iff isLeftHit
was true
and at least one of the following intersection's shapes is also contained in the compound shape's left shape (if inLeft
is true and we never encounter another intersection to 'exit' left
that implies a logical contradiction, we aren't really inLeft
in that case)The proposed fix in the above comment is not working because under its logic, a ray entering a shape and a ray leaving a shape are the same, which isn't true
Instead we will try use the trick from Intersection::computeShadingInfo
by looking at the dot product between the shape's normal vector at the intersection point and the negation of the ray direction
if this value is less than zero, the ray has come from inside the shape, and this we can set the 'inLeft' flag
not sure if the above approach will work because the method is not designed to be provided with the ray
of course I can make a new method that is though, I'll give it s try
edit: doesn't work either
we need a set up that will pass this scenario, with and open cylinder
As a temporary work around to this problem, we need only avoid the use of shapes that do not enclose a volume in compound shapes
now that I think about it, the real problem here is that the shapes that don't enclose a volume aren't solid shapes, which defeats the purpose of constructive solid geometry
to wrap this issue up, we'll
investigating:
Originally posted by @BudgiePanic in https://github.com/BudgiePanic/PushingP/issues/73#issuecomment-1974166987