godotengine / godot

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

POINT_COORD shader builtin is broken on Windows #95530

Open timoschwarzer opened 4 weeks ago

timoschwarzer commented 4 weeks ago

Tested versions

System information

Godot v4.2.2.stable - Windows 10.0.22631 - Vulkan (Forward+) - dedicated Intel(R) Arc(TM) A770 Graphics (Intel Corporation; 32.0.101.5768) - Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz (16 Threads)

Issue description

A polygon with a 1x1 white pixel texture (or any other texture) and a simple shader using POINT_COORD like the following behaves strangely on Windows while working as expected on Linux.

shader_type canvas_item;

void fragment() {
    COLOR.rgb = vec3(POINT_COORD.x);
}

It does not seem to be related to the Intel Arc GPU as the same happens on a different system with an RTX 4070 Ti as well.

Linux:

Screencast from 2024-08-14 22-57-31.webm

Windows:

https://github.com/user-attachments/assets/8a839fb2-8053-4aa4-b818-f181946b8a17

Steps to reproduce

  1. Add a Polygon2D (Sprite2D reproduces the bug as well)
  2. Add a texture to it
  3. Add a ShaderMaterial to it
  4. Write a shader using the POINT_COORD builtin

Minimal reproduction project (MRP)

point-coord-bug-repro.zip

kleonc commented 4 weeks ago

I think that's expected as POINT_COORD is mapped to gl_PointCoord which is undefined for non-point primitives.

https://github.com/godotengine/godot/blob/8e666adeed99328fda02e47429c8e45f36cd5ae1/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp#L2595 https://github.com/godotengine/godot/blob/8e666adeed99328fda02e47429c8e45f36cd5ae1/drivers/gles3/storage/material_storage.cpp#L1161

Calinou commented 4 weeks ago

If it appears to work as expected on Linux, it's likely because the Mesa driver is doing something different there. Mesa's Vulkan and OpenGL implementations have nothing in common compared to Intel or AMD's Windows drivers. Only NVIDIA's proprietary driver shares its Vulkan and OpenGL implementations with Windows, so behavior is almost always identical on Windows and Linux.

timoschwarzer commented 3 weeks ago

Ah, that makes sense! Thanks for clarifying. I will take a look at how to improve the docs to make this more clear in the next days.