godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.58k stars 20.46k forks source link

New Lightmapper renders black textures with PanoramaSky EXR in GLES 2. Godot_v3.2.4-rc3_win64 #46442

Open AlphaVDP2 opened 3 years ago

AlphaVDP2 commented 3 years ago

Godot version: Godot_v3.2.4-rc3_win64

Issue description: New Lightmapper renders black textures when the Environment Background is set to PanoramaSky EXR.

Issue appears to maybe only be present in GLES 2.

Setting LightMapper Environment to Custom Sky and loading the same PanoramaSky yields same result.

Steps to reproduce:

bake_bug

Minimal reproduction project: BUG_Bake.zip

JFonS commented 3 years ago

I have traced back the origin of the problem to the usage of an HDR .exr texture as the environment texture. It seems like the GLES2 doesn't play nice with HDR textures (AFAIK it doesn't support HDR lighting, so it makes sense) and getting data from them gives scrambled data.

I try to find a way around the limitation, but in the meantime converting your EXR image to png should work fine.

AlphaVDP2 commented 3 years ago

@JFonS Thank you for taking a look! I guess this should be obvious since it is stated in the documentation that GLES 2 doesn't use HDR rendering features. https://docs.godotengine.org/en/stable/tutorials/misc/gles2_gles3_differences.html#hdr

My fault for not realizing this extends to all HDR related operations and not just the viewport.

Can confirm that the same image converted to PNG does appear to bake correctly. png_gles2_bake

AlphaVDP2 commented 3 years ago

However, @JFonS this does raise another question.

In the BakedLightmap node Inspector settings, there is an option to "Use HDR" which renders HDR EXR images for the lightmaps.

If the project is set to GLES2, wouldn't the previously mentioned issue also be present here as well?

JFonS commented 3 years ago

Not really... From what I see, the only thing that is not working with HDR textures in GLES2 is getting the texture data from the GPU to the CPU (probably a bug somewhere, needs to be investigated).

So if you set an HDR texture as the environment panorama, when the lightmapper tries to read it, it gets invalid data. Just sending the lightmap texture as HDR to the GPU should work fine.

I debated disabling the "Use HDR" option in GLES2, since any light value over 1 will get clamped by the renderer anyway. But the increased precision reduces banding in the lightmap, so I decided to keep it.

AlphaVDP2 commented 3 years ago

Heh! So looking forward to the GPU lightmapper ;)

Actually, if I may humbly suggest, perhaps the pop up text on the "Use HDR" button in GLES2 could describe what is actually going on as to not confuse the user that they are actually rendering HDR lightmaps. (unless I don't understand what's happening)

Lastly, would you suggest that an issue be created to explore that bug regarding getting HDR texture data from the GPU to the CPU?