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

OpenGL: textureLod() is blocky due to using linear mipmaps instead of Gaussian #72823

Closed
Tracked by #66458
blitpxl opened this issue Feb 7, 2023 · 6 comments · Fixed by #78168
Closed
Tracked by #66458

OpenGL: textureLod() is blocky due to using linear mipmaps instead of Gaussian #72823

blitpxl opened this issue Feb 7, 2023 · 6 comments · Fixed by #78168

Comments

@blitpxl
Copy link

blitpxl commented Feb 7, 2023

Godot version

v4.0.beta17.official [c400205]

System information

Windows 11, OpenGL (Compatibility), RTX 2060 (31.0.15.2824)

Issue description

I tried to make a blurred panel for a ui element with texturelod via shader:

shader_type canvas_item;

uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap_anisotropic;
uniform float blur_amount : hint_range(0.0, 5.0);

void fragment() {
	vec4 blurred = textureLod(SCREEN_TEXTURE, SCREEN_UV, blur_amount);
	COLOR = blurred;
}

but what I got instead is this:
image

vulkan renderer does not exhibit this issue:
image

Steps to reproduce

  1. Add a TextureRect node
  2. Add a Panel node to overlay the previously added node
  3. Apply the blur shader to the panel node

Minimal reproduction project

N/A

@Calinou
Copy link
Member

Calinou commented Feb 7, 2023

This is because the mipmap roughness generator is not used in the OpenGL renderer (most likely for performance reasons). Instead, basic bilinear downsampling is performed. I suppose an option to use a roughness mipmap generator can be added like in 3.x, but it will surely be disabled by default.

You can work this around by performing bicubic sampling on the downsampled texture, which will effectively make it look blurry. See godotengine/godot-proposals#3231 where a similar issue popped up back when the Vulkan renderer didn't use a roughness mipmap generator.

Example code for bicubic sampling on the screen texture: Calinou@2d9d52f

@Calinou Calinou changed the title Godot 4: Blocky TextureLOD with OpenGL OpenGL: textureLod() is blocky due to missing roughness mipmap generator Feb 7, 2023
@Calinou Calinou added this to the 4.x milestone Feb 7, 2023
@clayjohn
Copy link
Member

clayjohn commented Feb 7, 2023

An option for Gaussian blurred mipmaps seems like a good idea. The reason they weren't used in the OpenGL renderer is that they are super slow to generate on mobile and integrated GPUs.

That being said, now that generating mipmaps for SCREEN_TEXTURE is entirely optional, users get to choose whether to take that performance hit. And there probably aren't many uses for non-Gaussian mipmaps in 2D.

@lostminds
Copy link

That being said, now that generating mipmaps for SCREEN_TEXTURE is entirely optional, users get to choose whether to take that performance hit. And there probably aren't many uses for non-Gaussian mipmaps in 2D.

I think this would be a good idea as a very common use of this will be to blur the background when pausing a game or opening a menu of some sort. In these cases performance will not be critical, but getting the nicer blur appearance would be very good.

@Calinou
Copy link
Member

Calinou commented Mar 11, 2023

I think this would be a good idea as a very common use of this will be to blur the background when pausing a game or opening a menu of some sort. In these cases performance will not be critical, but getting the nicer blur appearance would be very good.

This can be done by setting the Environment background mode to Canvas, enabling Glow then configuring it to act as a blur shader: godotengine/godot-proposals#3485 (comment)

That said, glow isn't implemented in the Compatibility rendering method yet.

@lostminds
Copy link

This can be done by setting the Environment background mode to Canvas, enabling Glow then configuring it to act as a blur shader: godotengine/godot-proposals#3485 (comment)

Yes, this is a great technique! I used it (based on your linked tip) for my game to get a nice background blur on the mobile renderer since that supports Glow (but not textureLod I think?). However, as you noted Environment Glow isn't supported on Compatibility yet and there are cases where you might not want to do a full screen blur like the Environment Glow technique entails.

@djrain
Copy link

djrain commented Jun 10, 2023

Agree that having the option for gaussian mipmaps would be nice. We were forced back to compatibility mode for performance reasons (not entirely sure what exactly). But it's a bit of a bummer losing the nice blur, we're using it in several places and finding a performant workaround is tricky.

@clayjohn clayjohn changed the title OpenGL: textureLod() is blocky due to missing roughness mipmap generator OpenGL: textureLod() is blocky due to using linear mipmaps instead of Gaussian Jun 12, 2023
@YuriSizov YuriSizov modified the milestones: 4.x, 4.2 Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants