godot icon indicating copy to clipboard operation
godot copied to clipboard

Fix issue in shadow to opacity in GLES3

Open BastiaanOlij opened this issue 1 year ago • 4 comments

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 avatar Apr 24 '24 03:04 BastiaanOlij

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 avatar Apr 24 '24 03:04 BastiaanOlij

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.

BastiaanOlij avatar Apr 24 '24 04:04 BastiaanOlij

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!

DanielSnd avatar Apr 24 '24 06:04 DanielSnd

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

clayjohn avatar Apr 24 '24 19:04 clayjohn

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

oops! fixed! :)

BastiaanOlij avatar Apr 26 '24 09:04 BastiaanOlij

Thanks!

akien-mga avatar Apr 26 '24 13:04 akien-mga