godotengine / godot

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

Decal with MeshTexture appears broken (not visible, and also affects other decals) #77564

Open Grix opened 1 year ago

Grix commented 1 year ago

Godot version

4.0.3 (.NET)

System information

Issue description

I am trying to use a Decal with a MeshTexture, because in my game it would be very useful to dynamically draw decal shapes at runtime, which I could do by creating a MeshTexture with SurfaceTool etc, as far as I understand.

However, Decals with MeshTextures as their texture appears to not work. There are two problems I encounter:

  1. The Decal with the MeshTexture itself is not visible.
  2. Other, nearby Decals with regular Texture2D textures, can also seemingly break when the MeshTexture Decal is present. It varies when moving them around relative to each other, but in many positions, when the MeshTexture Decal is present, the regular Decal can also turn invisible or be clipped.

Take a look at the reproduction project. There should be three decals visible, but only one is. To verify that the MeshTexture used in the decal in the sample project is a valid one, you can enable the TestingTexture instance. I generated the MeshTexture by converting a Sprite2D to this MeshInstance2D.

The documentation for MeshTexture is also generally very barebone. It is hard to understand exactly what this class does and how it's used, maybe this whole issue stems from me using it incorrectly.

Steps to reproduce

  1. Open the reproduction project and run it.
  2. Note that only one decal (blue circle) is visible, despite there being three decals in the tree. MeshTextureDecal and RegularTextureDecal2 should be visible too, but are not.
  3. Disable MeshTextureDecal.
  4. Note that RegularTextureDecal2 somehow became visible after step 3.

Minimal reproduction project

meshtexture_decal_test.zip

clayjohn commented 1 year ago

MeshTexture can't be used with decals. It can only be used with Canvas items or custom 2D drawing commands.

The docs for MeshTexture definitely have room for improvement

The engine should also provide an error when users try to set an invalid texture type on a Decal.

Grix commented 1 year ago

MeshTexture can't be used with decals. It can only be used with Canvas items or custom 2D drawing commands.

The docs for MeshTexture definitely have room for improvement

The engine should also provide an error when users try to set an invalid texture type on a Decal.

I see, that is unfortunate. Is there any other way of using decals with textures that you dynamically create at runtime like you can with a mesh?

Calinou commented 1 year ago

Is there any other way of using decals with textures that you dynamically create at runtime like you can with a mesh?

You can generate ImageTextures at run-time with a script, but this will be slow with large image sizes.

megarage9000 commented 9 months ago

Has this issue been resolved?

megarage9000 commented 9 months ago

I'll probably start digging into this in the next couple of days, but if this issue has been resolved do let me know!

Meowzszs commented 7 months ago

Hello, I want to look into this issue. Specifically, "The engine should also provide an error when users try to set an invalid texture type on a Decal."

Calinou commented 7 months ago

@Meowzszs Feel free to open a pull request for this :slightly_smiling_face: