#Efficient Mesh Manipulation via RenderingServer

1 messages · Page 1 of 1 (latest)

sage field
#

I'm trying to dynamically modify a mesh using RenderingServer.mesh_surface_update_vertex_region and finding it to have really bad performance with ~100 meshes each with ~200 vertices.

I'm doing this to implement curving lasers, which are implemented as a list of points in the last n frames (the game runs at a fixed framerate for determinism), example video of what one looks like is embeded.

The lasers are managed in a GDExtension plugin and all the other parts of the code seem performant enough, disabling the line updating the laser's vertices instantly returns the game to regular speed.

Is there some other way I could be rendering this that's of satisfactory performance?

#

one hyper cursed idea was just rendering each segment out with a texture rect and using shaders to bend it into the right shape but previous attempts at that had issues with tiny pixel gaps between each section

sage field
#

seems my older iteration of this from a few years ago just put it all on one mesh and remade the surfaces each frame so gonna try something like that tomorrow

feral thorn
sage field
#

I'll try both out and compare their performance/visuals

#

I already have some cursed shader that uses its "colour" to pick from a spritesheet so all bullets can share a single texture

#

so I'm pretty fine with doing some messed up shader stuff

#

though I am pretty bandwidth limited doing that right now, gonna be pretty hard to find room to shove in data to twist it in the shader

sage field
feral thorn
# sage field looking through that not too sure it would be very applicable here

Sorry I didn't realize it was a curtain-shooter! Godot 4.4 is fast at drawing sprites. The Sprite2D class is too general purpose for this case so

extends Node2D

const SPRITE_COUNT := 1024

@export var texture : Texture2D

func _physics_process(delta: float) -> void:
    queue_redraw()

func _draw() -> void:
    for i in SPRITE_COUNT:
        draw_texture(texture, ...)

I've got a demo for ya (that I had too much fun playing with), there's a lot of room for optimization. extract to res://laser/

sage field
#

I do quite appreciate the effort here though I do not think I would be able to use Path2Ds when I can't for certain know how the laser would move

sage field
sage field
#

found out for some reason setting the vertex colour of a mesh then trying to use that in the shader has the colours clamped to [0, 1]

#

thankfully could just use CUSTOM0