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

POINT_SIZE does not work in canvas item shader (Godot 3 to 4 regression) #80291

Closed
bluenote10 opened this issue Aug 5, 2023 · 0 comments · Fixed by #80323
Closed

POINT_SIZE does not work in canvas item shader (Godot 3 to 4 regression) #80291

bluenote10 opened this issue Aug 5, 2023 · 0 comments · Fixed by #80323

Comments

@bluenote10
Copy link
Contributor

Godot version

v4.1.1.stable.official [bd6af8e]

System information

Godot v4.1.1.stable - Ubuntu 22.04.2 LTS 22.04 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 980 (nvidia; 535.54.03) - Intel(R) Core(TM) i5-4670 CPU @ 3.40GHz (4 Threads)

Issue description

I'm trying to migrate a project from Godot 3 to 4, but I'm running into an apparent showstopper: The project relies on some fancy 2d shaders based on PRIMITIVE_POINTS meshes in combination with adjusting the POINT_SIZE in the vertex shader (amongst other things, see the nice Antialiased 2D Grid, Marker, and Arrow Shaders paper for motivation).

This used to work well under Godot 3, but unfortunately it looks like it is no longer possible in Godot 4. The approach relies on being able to set the POINT_SIZE in the vertex shader. Reduced to its minimal form:

shader_type canvas_item;

void vertex() {
    // The vertex shader should be able to control the point size.
    POINT_SIZE = 10.0;
}

void fragment() {
    COLOR = vec4(1.0, 0.0, 0.0, 1.0);
}

Using this minimal bootstrap code:

extends Node2D

func _ready():

    var points = PackedVector2Array()
    points.push_back(Vector2(10, 30))
    points.push_back(Vector2(100, 100))
    points.push_back(Vector2(30, 10))

    var arrays = []
    arrays.resize(ArrayMesh.ARRAY_MAX)
    arrays[ArrayMesh.ARRAY_VERTEX] = points

    var mesh = ArrayMesh.new()
    mesh.add_surface_from_arrays(Mesh.PRIMITIVE_POINTS, arrays)

    var mesh_instance = MeshInstance2D.new()
    mesh_instance.mesh = mesh
    mesh_instance.material = load("res://shader_material.tres")

    add_child(mesh_instance)

the output in Godot 4 is:

image

Notice that the three points are just single pixels.

Doing the same in Godot 3 (of course replacing PackedVector2Array by PoolVector2Array) has the expected outcome, i.e., setting POINT_SIZE is not ignored:

image

Steps to reproduce

Basically as already described above.

Minimal reproduction project

ShaderPointSize.zip

Or on GitHub:

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

Successfully merging a pull request may close this issue.

4 participants