Skip to content
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

added the suggested solution, but not working currently #2470

Closed
wants to merge 2 commits into from

Conversation

aabdullah27182845
Copy link

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
Copy link
Owner

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

@aabdullah27182845
Copy link
Author

Thanks @hannobraun !

@aabdullah27182845
Copy link
Author

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
Copy link
Owner

hannobraun commented Sep 30, 2024

The code already does what you're suggesting. It is computing a shading factor based on the angle to the normal here:

let angle = acos(dot(light, -in.normal));
let f_angle = angle / (pi * 0.75);
let f_normal = max(1.0 - f_angle, 0.0);

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 #2161.

@hannobraun
Copy link
Owner

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.

@hannobraun hannobraun closed this Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants