godotengine / godot

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

MultiMesh won't display in web (MultiMeshInstance2D & RenderingServer) #81926

Closed Pizza-Script closed 11 months ago

Pizza-Script commented 1 year ago

Godot version

v4.1.1.stable.official [bd6af8e0e]

System information

Godot v4.1.1.stable - Windows 10.0.19045 - Vulkan (Compatibility) - NVIDIA GeForce GTX 1660 SUPER (NVIDIA; 31.0.15.3623) - 11th Gen Intel(R) Core(TM) i7-11700 @ 2.50GHz (16 Threads)

Issue description

Browser receives errors when trying to use both MultiMeshInstance2D and RenderingServer.multimesh_*

Chrome - Version 116.0.5845.188 (Official Build) (64-bit):

[.WebGL-00007DF006C86900] GL_INVALID_OPERATION: Vertex shader input type does not match the type of the bound vertex attribute.

01 Chrome

Firefox - 117.0.1 (64-bit):

WebGL warning: drawElementsInstanced: Vertex attrib 5 requires data of type UINT, but is being supplied with type FLOAT.

01 Firefox

Steps to reproduce

Can view files and Itch.IO project here - https://quietgodot.itch.io/web-multimesh?secret=hyR14x8ZiMmxMP6X4rx9476fmTo

Was using the following minimal code:

For MultiMeshInstance2D

func _ready() -> void:
    for index in multimesh.instance_count:
        multimesh.set_instance_transform_2d(index, Transform2D(0, Vector2(index * 16 + 16, 16)))

For RenderingServer

var unit_texture: Texture2D = preload("icon.svg")
var unit_size: Vector2 = Vector2(16.0, 16.0)
var unit_mid: Vector2 = Vector2(8.0, 8.0)
var unit_count: int = 100

var quad_mesh: QuadMesh = QuadMesh.new()
var unit_rid: RID = RenderingServer.canvas_item_create()
var mesh_rid: RID = RenderingServer.multimesh_create()

func _ready() -> void:
    quad_mesh.size = unit_size
    quad_mesh.center_offset = Vector3(unit_mid.x, unit_mid.y, 0.0)
    RenderingServer.multimesh_set_mesh(mesh_rid, quad_mesh.get_rid())
    RenderingServer.multimesh_allocate_data(mesh_rid, unit_count, RenderingServer.MULTIMESH_TRANSFORM_2D)
    RenderingServer.canvas_item_set_parent(unit_rid, get_canvas_item())

    for unit_index in unit_count:
        RenderingServer.multimesh_instance_set_transform_2d(mesh_rid, unit_index, Transform2D(0, Vector2(randi() % 1025, randi() % 769)))

    RenderingServer.canvas_item_add_multimesh(unit_rid, mesh_rid, unit_texture)

Minimal reproduction project

project.zip

bitsawer commented 1 year ago

Thanks for the report. Looks like a 2D version bug report of https://github.com/godotengine/godot/issues/80980 (GridMap uses MultiMeshInstance internally), both of these should be fixed by https://github.com/godotengine/godot/pull/81575

I'll keep this open as it is still slighly different from the other report and is also directly about 2D and MultiMesh.