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

"Detect 3D" is triggered for ShaderMaterial with shader_type canvas_item; #62087

Closed
lyuma opened this issue Jun 16, 2022 · 6 comments · Fixed by #78199
Closed

"Detect 3D" is triggered for ShaderMaterial with shader_type canvas_item; #62087

lyuma opened this issue Jun 16, 2022 · 6 comments · Fixed by #78199

Comments

@lyuma
Copy link
Contributor

lyuma commented Jun 16, 2022

Godot version

4.0.dev 706dc74

System information

Windows 10, Vulkan

Issue description

ShaderMaterial is treated as 3D for the purpose of "Detect 3D", even if the material is of type canvas_item and used in a 2D node.

Here you can see the problem. Let's take icon.png, a quality piece of artwork whose every pixel is perfectly preserved.
While dragging into canvas_item material
Now we drag it into a 2D canvas_item shader, as opposed to a 2D sprite's texture slot. There could be lots of reasons for this. For example, it might be an auxiliary texture used for outline drawing, or a palette, or something else.

Now see what happened. (The import inspector doesn't refresh, so you select a different file and back.)
After dragging into material
It got VRAM Compressed!

Godot also prints the following.

res://random_texture.png: Texture detected as used in 3D. Enabling mipmap generation and setting the texture compression mode to VRAM Compressed (S3TC/ETC/BPTC).

Steps to reproduce

  1. Create a new 2D scene.
  2. Add a new node of type ColorRect
  3. Create a new ShaderMaterial or convert to shader material.
  4. Modify the shader to have the following code.
shader_type canvas_item;
render_mode blend_mix;

uniform sampler2D tex;

void fragment() {
	COLOR = texture(tex, UV);
}
  1. Find a texture, such as icon.png. Check the Import tab and make sure that Compress Mode is set to Lossless, and Detect 3D Compress is set to VRAM Compressed.
  2. Drag this texture into the tex slot in the material.
  3. The import inspector will still show the old settings. This is a different bug.
  4. Click a different file, then select icon.png again.
  5. Now the import settings will show that it has been changed to VRAM Compressed, and Detect 3D was disabled.

Minimal reproduction project

detect3dcanvas.zip

Editing to add repro project from #74335 in case it helps. To repro in this project, drag perfect.png into the material's Evil slot.
https://github.com/godotengine/godot/files/10887280/shader.texture.distorted.reproduction.project.zip

@clayjohn
Copy link
Member

It looks like the logic for detect 3D is to call the callback anytime textures are updated and p_use_linear_color is true

if (tex->detect_3d_callback && p_use_linear_color) {
tex->detect_3d_callback(tex->detect_3d_callback_ud);
}

However, p_use_linear_color is always true as it is set here:

update_textures(p_parameters, p_default_texture_params, p_texture_uniforms, texture_cache.ptrw(), true);

Looks like maybe we used to handle srgb differently in 2D and then we lost something during a refactoring.

Related: #61697

@clayjohn
Copy link
Member

I can't reproduce on Beta 2! So I am going to close this issue.

At any rate, I am changing the behaviour that I described in my earlier post so this problem should be gone soon for sure.

@lyuma
Copy link
Contributor Author

lyuma commented Mar 4, 2023

Reopening due to reproduction project in #74335
Should we close the new issue and keep this one open?

@lyuma lyuma reopened this Mar 4, 2023
@Calinou
Copy link
Member

Calinou commented Mar 4, 2023

Should we close the new issue and keep this one open?

Yes 🙂

@Calinou Calinou modified the milestones: 4.0, 4.1 Mar 4, 2023
@RafaelVidaurre
Copy link

Any news on this, or a workaround? Super nasty issues going on for me

@Calinou
Copy link
Member

Calinou commented May 20, 2023

Any news on this, or a workaround? Super nasty issues going on for me

You can change the Import Defaults for Texture2D/ImageTexture in the Project Settings. Set Detect 3D to Disable so that 3D usage detection never kicks in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants