hannobraun / fornjot

Early-stage b-rep CAD kernel, written in the Rust programming language.
https://www.fornjot.app/
Other
2.05k stars 118 forks source link

added the suggested solution, but not working currently #2470

Closed aabdullah27182845 closed 1 month ago

aabdullah27182845 commented 1 month ago

Currently trying to resolve issue #2161 (Improve shading to properly display blind holes). The current resolution is not working as intended, but aiming to resolve this issue. This is why I have kept this as a draft pull request. Thanks!

hannobraun commented 1 month ago

Thank you, @aabdullah27182845! As I said in the issue, I'll be able to take a closer look next week.

aabdullah27182845 commented 1 month ago

Thanks @hannobraun !

aabdullah27182845 commented 1 month ago

For anyone else who's interested in looking deeper into this, I can list the following findings.

Adding a shader that depends on the distance from the initialised light point isn't the way to go about this, since we get interference on the shading of the surface of the cuboid of the surface, not just the hole.

With my limited knowledge on wgsl and limited knowledge on vector algebra, I think the way this could be solved is by calculating the normal vector to the plane of the cuboid, and then using that vector as our base and multiplying a darkening factor on top of that. Normal vectors always tend to be perpendicular to the plane, so I think that would be something reasonable we would use here.

Also, I'm in no way a computer graphics expert at all, I just thought this was a cool problem and wanted to solve it. Screenshot from 2024-09-28 23-42-51

The picture above is what the normal vector is to the cuboid (perpendicular to the cuboid). I'm suggesting we solve that (I don't know how in the code, but usually they are solved using dot products equalling zero), and then use that vector to scale the shading.

hannobraun commented 1 month ago

The code already does what you're suggesting. It is computing a shading factor based on the angle to the normal here: https://github.com/hannobraun/fornjot/blob/ef5830fc79db39d64c5747968ff0eab37895b940/crates/fj-viewer/src/graphics/shader.wgsl#L42-L45

This is visible in your screenshot. See the side walls of the holes.

That alone is not enough though, due to the problem tracked in https://github.com/hannobraun/fornjot/issues/2161.

hannobraun commented 1 month ago

Closing due to inactivity.

@aabdullah27182845, feel free to reopen this pull request (or maybe open a new one) if you want to pick this up again in the future.