X Tutup
Skip to content

Implement DirectionalLight3D cull masks in Compatibility#107384

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
Kaleb-Reid:compat-directional-cull-mask
Oct 7, 2025
Merged

Implement DirectionalLight3D cull masks in Compatibility#107384
Repiteo merged 1 commit intogodotengine:masterfrom
Kaleb-Reid:compat-directional-cull-mask

Conversation

@Kaleb-Reid
Copy link
Contributor

This allows for using cull masks with DirectionalLight3Ds in the Compatibility renderer.

image

I'm mostly certain that they were not implemented before, I spent a bit of time looking for why they stopped working but I think it's because they never did.

I'm not sure what the optimal way is or if I'm missing anything so I encourage feedback.

Fixes #103595

@Kaleb-Reid Kaleb-Reid requested a review from a team as a code owner June 10, 2025 23:12
@Kaleb-Reid Kaleb-Reid force-pushed the compat-directional-cull-mask branch from 2067153 to f14573b Compare June 10, 2025 23:22
@Kaleb-Reid Kaleb-Reid marked this pull request as draft June 10, 2025 23:26
@Kaleb-Reid
Copy link
Contributor Author

Kaleb-Reid commented Jun 10, 2025

I just realized that this breaks using multiple directional lights so I'm looking into it
Fixed it, just learned about uniform block alignment.

image

@Kaleb-Reid Kaleb-Reid force-pushed the compat-directional-cull-mask branch from f14573b to 90e8534 Compare June 11, 2025 00:53
@Kaleb-Reid Kaleb-Reid marked this pull request as ready for review June 11, 2025 00:53
@Kaleb-Reid
Copy link
Contributor Author

Kaleb-Reid commented Jun 11, 2025

Noticed that turning on shadows on the light puts the light through the lightmap therefore ignoring the check added by this pr. Will be looking into that.
Should be fixed now.
image

@Calinou
Copy link
Member

Calinou commented Jun 11, 2025

Noticed that turning on shadows on the light puts the light through the lightmap therefore ignoring the check added by this pr. Will be looking into that.

Lights with shadows enabled in Compatibility are rendered in a separate pass, as described in Internal rendering architecture.

@Kaleb-Reid Kaleb-Reid force-pushed the compat-directional-cull-mask branch from 90e8534 to 1e7ae93 Compare June 11, 2025 21:38
@Kaleb-Reid Kaleb-Reid marked this pull request as ready for review June 11, 2025 21:38
@Kaleb-Reid Kaleb-Reid force-pushed the compat-directional-cull-mask branch 4 times, most recently from 22328dd to 1585c42 Compare June 11, 2025 21:47
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

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

Tested locally, it mostly works as expected (both with shadows enabled and disabled).

Testing project: test_pr_107384.zip

Preview

Forward+ Mobile Compatibility
Image Image Image

One issue I encountered while testing is that I've had a situation where it looked like this in Compatibility (each screenshot taken in a different session):

Image Image
Image Image

It seems to sporadically occur on startup, and is possibly due to uninitialized memory somewhere (which leads to undefined behavior). I've also had one situation where it appeared to render correctly, but part of the sky was pure black. This doesn't occur on master.

A quick way to test is to use Debug > Customize Run Instances..., enable multiple instances and increase the instance count to a value your PC can handle (up to 20).

@Kaleb-Reid Kaleb-Reid force-pushed the compat-directional-cull-mask branch from 1585c42 to 0c88c44 Compare July 1, 2025 02:01
@Kaleb-Reid
Copy link
Contributor Author

@Calinou I'm unable to reproduce this (maybe different graphics driver?), but I have a guess as to why it was doing that and have just pushed what is hopefully the fix.

@Kaleb-Reid Kaleb-Reid requested a review from Calinou July 1, 2025 02:02
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

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

The issue I reported above appears to be fixed now (tested over 20 launches in Compatibility).

@BossMaink
Copy link

This change appears to cause semi‑transparent objects to no longer be influenced by directional light, even if ALPHA is 1.
image
image
image

different appearance on master
image

@Kaleb-Reid Kaleb-Reid force-pushed the compat-directional-cull-mask branch from 0c88c44 to a8bd26d Compare July 6, 2025 23:08
@Kaleb-Reid
Copy link
Contributor Author

@BossMaink Should be fixed now, I forgot to send in the layer mask for the transparent pass so it was always 0.

@BossMaink
Copy link

@Kaleb-Reid You’re the best, issue be fixed now

@Kaleb-Reid Kaleb-Reid force-pushed the compat-directional-cull-mask branch from a8bd26d to b653636 Compare October 3, 2025 18:48
@Kaleb-Reid
Copy link
Contributor Author

Rebased onto master

@Kaleb-Reid Kaleb-Reid force-pushed the compat-directional-cull-mask branch from b653636 to 79b1a6d Compare October 4, 2025 23:12
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Looks great!

@clayjohn clayjohn modified the milestones: 4.x, 4.6 Oct 6, 2025
@Repiteo Repiteo merged commit cb164a3 into godotengine:master Oct 7, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Oct 7, 2025

Thanks!

@Kaleb-Reid Kaleb-Reid deleted the compat-directional-cull-mask branch October 7, 2025 17:23
@dog-on-moon
Copy link
Contributor

so i believe this PR breaks materials w/ blend_mode add in certain conditions?

directional light disabled directional light enabled
image image

this scene already has a directional light, but I wanted to add a second one for just the player models to make them brighter. while it does make the player brighter, it seems to have an impact on other shaders, such as breaking the cutoff effect on this enemy arrow

the arrow is just a super long arrow mesh that disables its alphas after a certain threshold

image

also noticing that it sometimes breaks one of my battle particle emitters (which also uses blend_mode add):

image

(i can't seem to get an MRP for this, since it happens kinda unreliably and I can't replicate it in the editor, but it's 100% caused by toggling the culling light)

@Kaleb-Reid
Copy link
Contributor Author

@dog-on-moon You should make an issue for this. Also put in the issue if the light has shadows enabled.

@dog-on-moon
Copy link
Contributor

I did more testing with it and found out that it wasn't related to this PR, but rather just that multiple directional lights break shaders in very specific circumstances that I can't quite figure out. If I can figure out an MRP I'll report it as an issue, but right now the actual conditions seem really niche and related to specific things in my project that I can't seem to isolate; apologies for the scare :P

@dog-on-moon
Copy link
Contributor

OK, teammate figured it out, figured I'd link it here anyways: #112216

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.

Compatibility: Cull Mask on DirectionalLight3D doesn't work

7 participants

X Tutup