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

Android Texture Artifacts #137

Closed
TokisanGames opened this issue Jul 18, 2023 · 11 comments · Fixed by #296
Closed

Android Texture Artifacts #137

TokisanGames opened this issue Jul 18, 2023 · 11 comments · Fixed by #296
Labels
bug Something isn't working
Milestone

Comments

@TokisanGames
Copy link
Owner

TokisanGames commented Jul 18, 2023

m4gr3d ran terrain3d on android (samsung galaxy tab) and it works fine, except the shader looks like it has terrible floating point precision.

https://chat.godotengine.org/channel/android?msg=Xo95Qcs52bv3BAF2X

image

Screen_Recording_20231116_153742_Terrain3D.mp4
terrain_3d_demo_godot_android_editor.mp4

@Calinou suggested

I guess you need a highp annotation in some places

@TokisanGames TokisanGames added the bug Something isn't working label Jul 18, 2023
@TokisanGames TokisanGames added this to the Beta milestone Jul 18, 2023
@Calinou
Copy link

Calinou commented Jul 18, 2023

Be careful to only use highp where absolutely needed, or performance will suffer.

My guess is that you need to use highp for UV coordinates here.

@TokisanGames
Copy link
Owner Author

@Calinou according to the docs highp is the default (on desktop presumably) so adding it shouldn't affect performance at all, right?

According to the image above, it looks like maybe lowp is the default on android/mobile renderer? So changing the UV to highp or even mediump will only affect android performance.

@m4gr3d, did you use the mobile renderer? Do you want to help troubleshoot this? If you enable custom shader in the storage resource, it will give you an editable one and you could experiment with adding mediump and highp around the shader.

@Calinou
Copy link

Calinou commented Jul 23, 2023

According to the image above, it looks like maybe lowp is the default on android/mobile renderer? So changing the UV to highp or even mediump will only affect android performance.

Yes, this is exactly what's happening 🙂

I think desktop GPUs tend to ignore precision hints anyway. The hints are mostly needed for mobile GPUs. (This is not about the rendering method, but about the graphics driver.)

@m4gr3d
Copy link

m4gr3d commented Jul 24, 2023

@m4gr3d, did you use the mobile renderer? Do you want to help troubleshoot this? If you enable custom shader in the storage resource, it will give you an editable one and you could experiment with adding mediump and highp around the shader.

Yes, I used the mobile vulkan renderer. I can try modifying the custom shader to see if that improves things.
I'll also post a draft PR with a custom build of the Android editor with the functionality enabled to allow others to test as well.

@m4gr3d
Copy link

m4gr3d commented Nov 17, 2023

@TokisanGames I played around with adding highp to the custom shader, but that had no effect on the rendering artifacts.

@TokisanGames
Copy link
Owner Author

Ok. Another possibility is that DDS textures aren't supposed to work on android anyway. Since Godot doesn't import them, it isn't converting them. Perhaps the android sdk or OS is converting them poorly? What if PNG textures are used, imported with ETC2 enabled in the project settings and with vram compressed? That way Godot will convert to proper etc2 files. However this line might need to be changed to allow Image::FORMAT_ETC2_R11S (hopefully) and/or Image::FORMAT_RGBA8 (hopefully not).

@TokisanGames TokisanGames changed the title Add highp to shader Android Texture Artifacts Nov 17, 2023
@TokisanGames TokisanGames removed the good first issue Good for newcomers label Nov 19, 2023
@TokisanGames
Copy link
Owner Author

It was reported that the cause of this issue has been found:

https://discord.com/channels/691957978680786944/1065519581013229578/1192757400315363398

@m4gr3d
Copy link

m4gr3d commented Jan 5, 2024

It was reported that the cause of this issue has been found:

https://discord.com/channels/691957978680786944/1065519581013229578/1192757400315363398

I'm unable to access the discord link; can you paste the cause of the issue here?

@Calinou
Copy link

Calinou commented Jan 5, 2024

Perhaps the android sdk or OS is converting them poorly?

The Android OS/SDK does nothing special to DDS textures. These need to be decoded on the CPU by Godot (or transcoded to a compatible VRAM-compressed format) if S3TC support isn't available on the hardware.

We could choose to perform this automatically on unsupported formats, but it comes with a significant impact on memory usage (if decoding to lossless) or quality and binary size (if transcoding to ETC2). Both choices will impact loading times negatively too, but transcoding will be particularly bad on this aspect.

(Note: This assumes we are talking about an exported project or runtime DDS loading here, with no existing ETC2 textures available.)

@TokisanGames
Copy link
Owner Author

TokisanGames commented Jan 8, 2024

I think this artifact is due to or related to using DDS files since android doesn't have wide support for them. I think that using PNGs which get converted to etc2 would be fine, but I haven't confirmed that. I have replaced the demo textures with PNG so it can be a mobile demo as well.

@lfxu reported this, which I have not tested or implemented myself yet:

I found the cause, precision issue.
image
image
Of course this is incorrect, probably having a offset, but you get the idea.
interpolation of large UV value produce poor precision results at fragment shader input.
image
These are all the changes I did.
I think you want to check other varyings too.
image

@TokisanGames
Copy link
Owner Author

Fixed in #296. We can use more android testers to confirm. I heard everything with android should be working now. The github builds include android arm 32 & 64.

@TokisanGames TokisanGames modified the milestones: 0.9.1, Beta 0.9.x Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants