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

Visibility Range "Fade Self" option hides shadows unexpectedly in Depth Pre-Pass #91671

Open
eswartz opened this issue May 7, 2024 · 4 comments

Comments

@eswartz
Copy link
Contributor

eswartz commented May 7, 2024

Tested versions

System information

Godot v4.3.dev (32339a8c3) - Debian GNU/Linux trixie/sid trixie - X11 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3080 Ti (nvidia) - AMD Ryzen 7 5800X 8-Core Processor (16 Threads)

Issue description

When using this combination:

  • GeometryInstance3D > Visibility Range established
  • Fade Mode set to Self
  • Add a mesh instance with a material that enables Transparency = Depth Pre-Pass
  • Enable Cast Shadows on meshes
  • Add a light with shadows enabled

-- then no shadows are ever rendered.

I assume the intention is to have shadows disappear when the object is actually invisible, as it does for an opaque material under the same circumstances.

Steps to reproduce

See MRP. Move camera back and forth.

Close up, one shadow missing on "GeoDistanceFadeSelf + Blend":

screenshot-20240507-132534

At a distance, all shadows for fadeable objects gone as expected:

screenshot-20240507-132601

Minimal reproduction project (MRP)

fade-shadow-test.zip

@Calinou
Copy link
Member

Calinou commented May 7, 2024

Materials with alpha transparency never cast shadows. If you want them to cast shadows, you need to duplicate the MeshInstance, give the duplicate an opaque material and set its shadow casting mode to Shadows Only.

GeometryInstance3D transparency allows materials that are made transparent this way to cast shadows, but only if the material is originally opaque (or alpha scissor/alpha hash).

@eswartz
Copy link
Contributor Author

eswartz commented May 7, 2024

I should clarify, the "blend" objects in the project are using the Depth Pre-Pass model, not actual alpha blending. The three other objects using this mode do cast shadows. I'll clarify the title.

@eswartz eswartz changed the title Visibility Range "Fade Self" option hides shadows unexpectedly Visibility Range "Fade Self" option hides shadows unexpectedly in Depth Pre-Pass May 7, 2024
@eswartz
Copy link
Contributor Author

eswartz commented May 7, 2024

According to material.cpp:788, using pre-pass should add this render_mode:


	if (transparency == TRANSPARENCY_ALPHA_DEPTH_PRE_PASS) {
		code += ", depth_prepass_alpha";
	}

which should then trigger casts_shadows per uses_depth_prepass_alpha in the check:


bool SceneShaderForwardClustered::ShaderData::casts_shadows() const {
	bool has_read_screen_alpha = uses_screen_texture || uses_depth_texture || uses_normal_texture;
	bool has_base_alpha = (uses_alpha && (!uses_alpha_clip || uses_alpha_antialiasing)) || has_read_screen_alpha;
	bool has_alpha = has_base_alpha || uses_blend_alpha;

	return !has_alpha || (uses_depth_prepass_alpha && !(depth_draw == DEPTH_DRAW_DISABLED || depth_test == DEPTH_TEST_DISABLED));
}

The material I'm using seems to pass this test (depth draw is OPAQUE and "no depth test" is not enabled).

image

Am I understanding correctly? It seems this should still be considered to cast a shadow.

@Calinou
Copy link
Member

Calinou commented May 7, 2024

Am I understanding correctly? It seems this should still be considered to cast a shadow.

Yes, that makes sense. I recall this bug being reported elsewhere already, but I can't find an issue right now. Perhaps #73158 is related.

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

No branches or pull requests

2 participants