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

Fix issue in shadow to opacity #91096

Merged

Conversation

BastiaanOlij
Copy link
Contributor

This fixes this bug in the GLES3 implementation of shadow to opacity:
image

You can test this with this shader:

shader_type spatial;
render_mode blend_mix, depth_draw_opaque, cull_back, shadow_to_opacity;

void fragment() {
    ALBEDO = vec3(0.0, 0.0, 0.0);
}

Shadow to opacity is used in AR applications to render transparent geometry where there is geometry in real life. Think of a table or wall or anything like that. We render this geometry in the Opaque pass but with transparency based on how much in shadow we are.

We don't have access to ambient_light during depth passes or shadow passes hence the error. The fix now excludes our lighting check and alpha scissor check during depth/shadow pass which is correct behaviour. This allows for real live geometry to be visible through passthrough, accurately occlude other virtual geometry and casing shadows on virtual geometry.

@BastiaanOlij
Copy link
Contributor Author

One sec, there is more to this, there is a mismatch on the ifdefs, it shouldn't do anything with alpha during depth pass if USE_SHADOW_TO_OPACITY is set.

@BastiaanOlij BastiaanOlij force-pushed the fix_gles3_shadow_to_opacity branch from e37cdda to 97cd1a9 Compare April 24, 2024 04:07
@BastiaanOlij
Copy link
Contributor Author

Ok, fixed it and tested it in passthrough in XR.
So important to note that ALPHA in this case does not determine whether there is geometry or not. The geometry is fully opaque as far as depth is concerned. We are writing ALPHA because we want to see what's in the real world.

@DanielSnd
Copy link
Contributor

This is great! I'm using this fix on a mixed reality project I'm working on for a hackathon, you can see the result of the fix here:

ezgif-4-e8f9b9d864

Without it there's no way of hiding virtual elements that are behind real life objects. Great job!

Copy link
Contributor

@dsnopek dsnopek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much! This works great in my testing with the Compatibility renderer :-)

The only suggestion I'd make is changing the PR title and commit message, because this fixes the Forward+ renderer as well, not just GLES3.

@clayjohn
Copy link
Member

I think this same code is in the mobile renderer too. It might need to be fixed as well

@BastiaanOlij BastiaanOlij force-pushed the fix_gles3_shadow_to_opacity branch from 97cd1a9 to a8468ca Compare April 26, 2024 09:45
@BastiaanOlij
Copy link
Contributor Author

I think this same code is in the mobile renderer too. It might need to be fixed as well

oops! fixed! :)

@akien-mga akien-mga changed the title Fix issue in shadow to opacity in GLES3 Fix issue in shadow to opacity Apr 26, 2024
@BastiaanOlij BastiaanOlij force-pushed the fix_gles3_shadow_to_opacity branch from a8468ca to d2d2274 Compare April 26, 2024 11:54
@akien-mga akien-mga merged commit 34ec486 into godotengine:master Apr 26, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants