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

Compatibility renderer web export: Directional shadows malfunction on Mac browsers (Chrome, Safari), function correctly on Mac native app and Windows browsers #93537

Closed
cosformula opened this issue Jun 24, 2024 · 8 comments · Fixed by #94556

Comments

@cosformula
Copy link
Contributor

cosformula commented Jun 24, 2024

Tested versions

  • Reproducible in 4.2.2.stable, 4.3.beta2

System information

Godot v4.2.2.stable - macOS 14.5.0 - GLES3 (Compatibility) - Apple M1 Max - Apple M1 Max (10 Threads)

Issue description

Directional shadows not working correctly on mac browser(both chrome and safari), but working correctly on mac native and windows browser.

Running preview on mac
image

Running preview on mac chrome(v126.0.6478.115 arm64) (both shadow and color seems wrong)
image

Running preview on windows chrome(v126.0.6478.115)
img_v3_02c5_d79ad31c-b6d5-49b2-bda0-acdf3aabd66g

Additional notes:
By changing the ground color, we can see that the shadow was actualy there, but in a light color
image

Steps to reproduce

  • Download the minimal reproduction project
  • Run project in the browser

Minimal reproduction project (MRP)

DirectionalShadow.zip

@cosformula cosformula changed the title Directional shadows malfunction on Mac browsers (Chrome, Safari); function correctly on Mac native app and Windows browsers Directional shadows malfunction on Mac browsers (Chrome, Safari), function correctly on Mac native app and Windows browsers Jun 24, 2024
@cosformula cosformula changed the title Directional shadows malfunction on Mac browsers (Chrome, Safari), function correctly on Mac native app and Windows browsers In Compatibility mode, directional shadows malfunction on Mac browsers (Chrome, Safari), function correctly on Mac native app and Windows browsers Jun 24, 2024
@cosformula cosformula changed the title In Compatibility mode, directional shadows malfunction on Mac browsers (Chrome, Safari), function correctly on Mac native app and Windows browsers In Compatibility renderer, directional shadows malfunction on Mac browsers (Chrome, Safari), function correctly on Mac native app and Windows browsers Jun 24, 2024
@cosformula cosformula changed the title In Compatibility renderer, directional shadows malfunction on Mac browsers (Chrome, Safari), function correctly on Mac native app and Windows browsers Compatibility renderer web export: Directional shadows malfunction on Mac browsers (Chrome, Safari), function correctly on Mac native app and Windows browsers Jun 24, 2024
@akien-mga
Copy link
Member

Might be related to #85567.

@cosformula
Copy link
Contributor Author

This issue is resolved when I choose OpenGL instead of Metal as the ANGLE backend:
image
I am currently debugging and believe the problem is related to the directional shadow atlas rendering stage. However, I am not very familiar with the rendering process and would appreciate any guidance or hints from the community.

@cosformula
Copy link
Contributor Author

I found a workaround to solve the issue, modifying sample_shadow function in drivers/gles3/scene.glsl :

float sample_shadow(highp sampler2DShadow shadow, float shadow_pixel_size, vec4 pos) {
	// float avg = textureProj(shadow, pos);
	vec3 pos3 = vec3(pos.x,pos.y,pos.z);
	float avg = texture(shadow, pos3);
	return avg;

Not a perfect solution, and spot light shadow still broken, but it might help someone else.
image
Still don't know why this happeds, I'll continue working on this.

@cosformula
Copy link
Contributor Author

cosformula commented Jul 19, 2024

It seems like textureProj is broken on the Metal-backend for WebGL2. I've created a test page to demonstrate the issue:
https://jsgist.org/?src=60e40e12f617541a28c777523c23208d
On Safari/Chrome:
image
On Firefox :
image

A workaround is to simulate textureProj with the following code:

float textureProjSimulated(highp sampler2DShadow shadow, vec4 pos) {
	float d = texture(shadow, pos.xyz/pos.w);
	return d;
}

or use textureProjLod, which gives correct result.

As this seems to be an upstream issue(Angle, I've file an issue), I'm not sure if this is the best solution. Should I open a PR to implement this workaround?

@akien-mga
Copy link
Member

As this seems to be an upstream issue(Angle, I've file an issue), I'm not sure if this is the best solution. Should I open a PR to implement this workaround?

I'll defer to @clayjohn to decide if the workaround is acceptable, or would incur too big a performance penalty.

I'd suggest also filing a WebKit bug report, they have a WebGL component and Apple developers might be more likely to be notified of the issue there than on upstream ANGLE, I suppose. The bug reports can cross-reference each other.

And maybe even an Apple Feedback ticket? https://developer.apple.com/bug-reporting/

@cosformula
Copy link
Contributor Author

As this seems to be an upstream issue(Angle, I've file an issue), I'm not sure if this is the best solution. Should I open a PR to implement this workaround?由于这似乎是一个上游问题(角度,我已经提交了一个问题),我不确定这是否是最好的解决方案。我应该打开 PR 来实施此解决方法吗?

I'll defer to @clayjohn to decide if the workaround is acceptable, or would incur too big a performance penalty.我将推迟决定解决方法是否可以接受,或者会导致太大的性能损失。

I'd suggest also filing a WebKit bug report, they have a WebGL component and Apple developers might be more likely to be notified of the issue there than on upstream ANGLE, I suppose. The bug reports can cross-reference each other.我建议还提交一份 WebKit 错误报告,他们有一个 WebGL 组件,我想苹果开发人员可能比上游 ANGLE 更有可能收到有关该问题的通知。错误报告可以相互交叉引用。

And maybe even an Apple Feedback ticket? https://developer.apple.com/bug-reporting/甚至可能还有 Apple 反馈票? https://developer.apple.com/bug-reporting/

Thanks!
Reports for both Safari and Chrome have been submitted. Looking forward to the new progress.

@clayjohn
Copy link
Member

@cosformula If textureProjLod works, let's use that. The shadow map does not have mipmaps anyway. So the result should be exactly the same if we use textureProj or textureProjLod with an LOD of 0 and the speed should also be the same.

@cosformula
Copy link
Contributor Author

@cosformula If textureProjLod works, let's use that. The shadow map does not have mipmaps anyway. So the result should be exactly the same if we use textureProj or textureProjLod with an LOD of 0 and the speed should also be the same.

Thanks! Made a draft PR, I'll do more test to ensure it does't cause any regression.

@clayjohn clayjohn moved this from For team assessment to Fix pending review in Rendering Issue Triage Jul 23, 2024
@clayjohn clayjohn moved this from Fix pending review to Done in Rendering Issue Triage Jul 23, 2024
@akien-mga akien-mga added this to the 4.3 milestone Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants