godotengine / godot

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

Gradients on a sprite 3d have artifacts. #73739

Closed Puppyguarb closed 9 months ago

Puppyguarb commented 1 year ago

Godot version

4.0.rc2 EDIT: I have tested, and it appears on 4.0.rc3 as well.

System information

Windows 10, NVIDIA GeForce GTX 1650 SUPER

Issue description

the problem Sprite 3Ds with a gradient texture assigned to them have a line on the edge that should not be present.

This still occurs even if using a Quad mesh with a gradient texture.

Steps to reproduce

  1. Spawn in a Sprite3d.
  2. Give it a GradientTexture2D (A GradientTexture1D works too.)
  3. Observe the artifact on the edge.

If you want to do this with a Quad instead:

  1. Spawn in a MeshInstance3D
  2. Give it a QuadMesh.
  3. Give the QuadMesh a StandardMaterial3D
  4. Set the material's texture (under albedo) to a GradientTexture2D (A GradientTexture1D works too.)
  5. (Optional) Set the material's Shading_Mode to unshaded to better see the artifacts.

Minimal reproduction project

Included in the project below is a Camera3D set to view a Sprite3D with a GradientTexture2D assigned to it, and a Quad with an unshaded material with a GradientTexture2D assigned to it.

GradientArtifactsProject.zip

Sauermann commented 1 year ago

I had a look at this issue and it is related to Sprite3D.texture_filter.

Setting the Texture size to (4x4) shows the problem even better for Linear Mipmap:

image

To me it is not entirely clear, what the desired functionality should be. In the case of this Gradient I would assume, that the desired behavior is, that the Sprite3D should have the darkest black on the left and the brightest white on the right.

One way to solve this would require to stretch the Texture in the case of *LINEAR* and keep it the same in the case of *NEAREST*, but I assume that this stretching would interfere with other uses of *LINEAR*?!

A different way to solve this, would be to disable the linear interpolation at the four edges, but I am not sure, if this is feasible because of the additional computational cost.

What would be a fitting solution for this problem?

logzero commented 1 year ago

Disabling texture repeat (FLAG_REPEAT ) should fix that.

vipulvatsa5 commented 1 year ago

Hey, I am new in this , can you provide me some easy entry level work.

Zireael07 commented 1 year ago

@vipulvatsa5 look for issues tagged "good first issue" like this one. And if you're fishing for assigning you issues, Godot does NOT practice assigning issues, just start a PR

Calinou commented 1 year ago

This is expected, as texture repeat is enabled by default (it makes sense on most materials). In the few cases where it's not desired, disable texture repeat in the material or shader.

I'm not sure where this should be documented specifically, as this isn't something you'll run into often (since this doesn't occur with QuadMeshes that have transparent edges).

Mickeon commented 10 months ago

(it makes sense on most materials)

But does it make sense on the default material used for Sprite3D when a texture is applied? I'm not too sure.