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

Precision-induced lighting failure on large objects on Android devices with Vulkan mobile renderer (solution provided) #86275

Closed
roalyr opened this issue Dec 17, 2023 · 10 comments · Fixed by #99163

Comments

@roalyr
Copy link

roalyr commented Dec 17, 2023

Solution

Increase precision in fragment shader for normal_interp
roalyr@c26f7ac

Tested versions

4.x as of 2d0ee20 and official Android 4.2 build.

System information

Lenovo TB350FU, ARM Mali-G57 MC2 and Motorola moto g(60), Adreno 618, all in Vulkan mobile mode.

Issue description

On large 3D objects omni light either ceases to render at all, if an object is above some certain scale (Motorola), or is rendered with bugs (Lenovo). On GLES3 renderer everything works fine, same goes for desktop (both Forward+ and Mobile renderer).

Also the bug seems to affect blend_add fresnel shaders.

Intended look (on desktop):
287460725-54bc7b57-8cb8-485d-a3b2-2376c93d7f91

Links to videos showing the bug:
https://imgur.com/a/fSqghHU
https://imgur.com/a/MGLpjvq
https://youtu.be/9AVLGC-C2-I?si=wsHlsaOSfbtplzsD

Remarks:

  1. This issue persists for both editor and exported project on a mobile device (I included editor build below).
  2. Models use shader material with log depth, but it doesn't seem to affect the bug (can be commented out).
  3. My fork 4.x build ( GF3DOW ) has increased z-far cap in order to be able to display objects at large scales, could increased z-far in Vulkan mobile cause this bug? Edit: same behavior on official 4.2 Android editor.
  4. Behavior is different on different mobile GPUs.
  5. Switching to compatibility makes scene appear normal, lighting works as intended.
  6. Desktop GPU renders as intended on every renderer.
  7. Only light, direction light behave the same.

Steps to reproduce

Open test scene and navigate the view. Try gradually scaling down the models to see the threshold at which omni light starts to misbehave.

Or just create an empty 3D scene, add a spherical model and gradually scale it up.

Minimal reproduction project (MRP)

The test scene itself: test.zip
(Should be opened on a mobile device with Android editor build because the scale is around 1e6-1e7 units, so it requires editor with larger z-far cap and double precision)

@roalyr
Copy link
Author

roalyr commented Dec 20, 2023

On Motorola where light is either rendered or not, the size of a sphere above which the light fails is 256 meters.

Screenshot_20231220-115754.png

Screenshot_20231220-115744.png

Screenshot_20231220-120552.png

Directional light behaves the same way.

@roalyr
Copy link
Author

roalyr commented Dec 20, 2023

On the Lenovo tablet the size of a sphere at which light begins to glitch is about 65520...65522 meters.

Screenshot_20231220-131109.png

Screenshot_20231220-131051.png

@roalyr
Copy link
Author

roalyr commented Dec 20, 2023

The same bug happens on 4.2 official build, just tested.

@roalyr
Copy link
Author

roalyr commented Jan 6, 2024

Suggested by @clayjohn, copying here from chat so as to not to lose:

clayjohn11:27 PM
The issue looks like it's coming from the scene shader itself. I would look at the shaders and ensure you are doing math in high precision. Then I would look at the inputs to the light shader. Try assigning NORMAL to ALBEDO as well as depth and see if you notice any issues.

clayjohn11:28 PM
Also try a very simple light shader to see if the issue comes from the internal light shader or earlier in the pipe

@roalyr
Copy link
Author

roalyr commented Jan 31, 2024

The bug appears to be affecting unshaded materials with blend_add mode too:

https://youtu.be/oILRIk3NxGU?si=ogyDSYxLFif3M804

This is not related to near/far plane distances, because they do not affect this bug.

@roalyr roalyr changed the title Omni light failure on large objects on Android devices with Vulkan mobile renderer Omni light and transparency failure on large objects on Android devices with Vulkan mobile renderer Jan 31, 2024
@roalyr
Copy link
Author

roalyr commented Feb 6, 2024

Some more, shows both lighting and blend_add fresnel material: https://youtu.be/9AVLGC-C2-I?si=wsHlsaOSfbtplzsD

Motorola moto g(60), Adreno 618

@roalyr roalyr changed the title Omni light and transparency failure on large objects on Android devices with Vulkan mobile renderer Precision-induced lighting failure on large objects on Android devices with Vulkan mobile renderer Feb 12, 2024
@roalyr
Copy link
Author

roalyr commented Feb 12, 2024

Solution

Increase precision in fragment shader for normal_interp
Might be related to normalize() function being unable to properly handle it.
roalyr@c26f7ac

@roalyr roalyr changed the title Precision-induced lighting failure on large objects on Android devices with Vulkan mobile renderer Precision-induced lighting failure on large objects on Android devices with Vulkan mobile renderer (solution provided) Feb 13, 2024
@Flarkk
Copy link
Contributor

Flarkk commented Oct 31, 2024

@roalyr can you make a PR ?

@roalyr
Copy link
Author

roalyr commented Oct 31, 2024

I am sorry, I am in a poor state of mind as of late, please don't rely on me. I know you are doing important work on mobile renderer there, but I am not able to contribute these days.

@Flarkk
Copy link
Contributor

Flarkk commented Oct 31, 2024

No worries, take care

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