godotengine / godot

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

Texture UV Precision Issue #16053

Closed EIREXE closed 6 years ago

EIREXE commented 6 years ago

Godot version: 3.0 RC3

OS/device including version: Windows, 64.

Issue description: When getting a point from the top of a texture that has two colors:

imagen

texture() returns a mix between the color at the top and the color at the bottom, for example, when getting UV 0.0,0.0:

imagen

And then when getting UV 0.0,0.1:

imagen

UV 0.0,0.6:

imagen

imagen

Seems like a precision issue to me or something.

Minimal reproduction project: ShaderBug.zip

mrcdk commented 6 years ago

This is how the texture filtering and how the hardware interpolates the pixel colors to get the final color result work. If you reimport the texture with filtering disabled it shouldn't happen.

EIREXE commented 6 years ago

@mrcdk oh so it's not really a bug?

bojidar-bg commented 6 years ago

I tried @mrcdk's solution, and it worked on the test project.

The problem stems from the texture having "Repeat" and "Filter" on, should be like this: image

After this, it seems to work fine.

mrcdk commented 6 years ago

Yes, it's not a bug @EIREXE Basically, when the filtering is disabled, the GPU will pick the closest color it can find but when the filtering is enabled it will combine the surrounding colors to get the final color. This plus repeat enabled makes it get the green and the red color at uv(0, 0) combine them and return yellow. The same will happen at uv(0, 0.5) and uv(0, 1)

https://www.gamedevelopment.blog/texture-filter/

EIREXE commented 6 years ago

Oh alright, thanks!