From 8825aa8b5b9b01b1aa441a6c77cd8df6508d6c93 Mon Sep 17 00:00:00 2001 From: Forest Katsch Date: Fri, 18 Dec 2020 02:08:39 -0600 Subject: [PATCH] Fixes #43667. The root cause of the issue is that OpenGL ES 2 does not support the `textureCubeLod` function. There are (optional) extensions to support this, but they don't appear to be exposed with the ES2 renderer (even though the hardware needed to support LOD features are certainly available.) The existing shim in `drivers/gles2/shaders/cubemap_filter.glsl` just creates a macro: ``` #define textureCubeLod(img, coord, lod) textureCube(img, coord) ``` But the third parameter of `textureCube` is actually a mip bias, not an absolute mip level. (And it doesn't seem to work regardless.) In this specific case, the `cubemap_filter` should only sample from the first level of the "source" panorama cubemap. In lieu of a method to force a lod level of zero, I've chosen to comment out the switchover from a 2D equirectangular panorama to the cubemap version of the same image, therefore always sampling roughness values from the 2D equirectangular panorama. This may cause additional artifacts or issues across the seam, but at least it prevents the glaringly obvious black areas. --- This same issue (no fragment texture LOD support) has rather large repercussions elsewhere too; it means materials with larger cubemap density (i.e. planar or distant objects) will be far rougher than expected. Since GLES 3 appears to properly support fragment `texture*Lod` functions, switching to the GLES 3 backend would solve this problem. --- Root cause discovered with help from @KaadmY. --- drivers/gles2/rasterizer_storage_gles2.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index 322f63488cb..fd989cfc072 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -1276,11 +1276,8 @@ void RasterizerStorageGLES2::sky_set_texture(RID p_sky, RID p_panorama, int p_ra glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, resources.mipmap_blur_color, 0); if (lod == 1) { - //bind panorama for smaller lods - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_CUBE_MAP, sky->radiance); - shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES2::USE_SOURCE_PANORAMA, false); + // We set USE_DIRECT_WRITE to false for LOD levels 1 and up, so the shader will properly + // filter the roughness instead of just copying 1:1 from the source panorama. shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES2::USE_DIRECT_WRITE, false); shaders.cubemap_filter.bind(); }