Hello there,
I haven't tried Godot 4 but I'm hearing all sorts of exciting stuff about it. Support for compute shaders seems like a really neat addition that will open up tons for those of us interested in godot and physical simulation.
I'll look into that but I imagine I'll probably be wondering the same thing. Is it just the standard godot 4 particle emitted that is so impressive?
I decided to attempt a naive series of tests. The idea was to see what the performance would be like if I rendered ~20 million points in godot 3.4 using this script. I had to bring in the threading because I found that the game window wouldn't respond if I left things in the _ready
function. Now a test scene is free to define things like number of threads and number of points instantiated each time. I believe this means that I'm increasing the number of draw calls and that each draw puts less points on the screen but ultimately I'll be working with some systems that have a high number of cpu cores to support the thread numbers. Could have all this backwards again so open to hearing so. This example of course doesn't begin to handle point coloration, or reading in point cloud as input to Godot. Both of these are still things that I'd love to hear about from some folks more knowledgeable
extends Spatial
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
export var material: SpatialMaterial
export var scalef: float =1
export var numpoints: int = 100
export var numthreads : int = 1
var mutex
var threads =[]
# Called when the node enters the scene tree for the first time.
func _ready():
# call thread to add all the vertices
# wait for finish in join
mutex = Mutex.new()
for i in range(numthreads):
var thread = Thread.new()
thread.start(self,"tf",[i,numpoints])
threads.append(thread)
func tf(data):
var vertices
var id = data[0]
var nump = data[1]
vertices = PoolVector3Array()
var array_mesh = ArrayMesh.new()
var arr = []
for i in range(nump):
if i%100000 == 0:
print("checkpoint",id ,(float(i)/nump)*100,"%")
vertices.append(scalef*Vector3(randf(),randf(),randf()) - Vector3(scalef/2,scalef/2,scalef/2))
print("finish")
print("now doing things with the vertices")
arr.resize(array_mesh.ARRAY_MAX)
arr[0] = vertices
array_mesh.add_surface_from_arrays(PrimitiveMesh.PRIMITIVE_POINTS,arr)
var instance = MeshInstance.new()
instance.mesh = array_mesh
instance.set_surface_material(0,material)
mutex.lock()
add_child(instance)
print(instance)
mutex.unlock()
func _exit_tree():
for i in range(numthreads):
threads[i].wait_to_finish()