← Pixel Dreamer Studio

Bullet holes and blood splats in one draw call

Put every mark in one MultiMesh with a fixed number of slots, and let the newest mark replace the oldest.

A bullet hole or blood splat is usually a small textured quad placed where a raycast hits. Added as its own MeshInstance3D each time, every mark is one more draw call, and the marks keep piling up. In our Godot 4.7 test, 100, 500 and 2,000 holes on a wall took 101, 501 and 2,001 draw calls, one for the wall and one for each hole, although they all shared one mesh and one material. The script below keeps the marks in one MultiMeshInstance3D: 2 draw calls after 100, 500 or 2,000 shots, the wall and the marks. It keeps the newest 256 and writes each new mark over the oldest one. It draws flat quads, not Decal nodes, so it also works with the Compatibility renderer that web exports use.

The code

Save it as bullet_holes.gd and add one to your level as in the lines at the top of the script. Keep that node at the world origin, then call add() with the position and normal of each raycast hit. clear() removes every mark, for example when the level restarts.

extends MultiMeshInstance3D
## Bullet holes, blood splats or scorch marks as one MultiMesh: one draw call however many
## there are. When it is full, the newest mark replaces the oldest.
##   var holes := preload("res://bullet_holes.gd").new()
##   holes.texture = preload("res://bullet_hole.png")
##   add_child(holes)  # keep this node at the world origin, not rotated or scaled
##   holes.add(hit.position, hit.normal)  # hit = a raycast result

@export var texture: Texture2D
@export var max_marks := 256
@export var size := 0.12  # meters
@export var lift := 0.01  # meters off the surface, so the mark does not flicker against it
@export var random_spin := true

var _next := 0
var _count := 0


func _ready() -> void:
	var quad := QuadMesh.new()  # 1 x 1, scaled to size per mark
	var mat := StandardMaterial3D.new()
	mat.albedo_texture = texture
	mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
	quad.material = mat
	multimesh = MultiMesh.new()
	multimesh.transform_format = MultiMesh.TRANSFORM_3D
	multimesh.mesh = quad
	multimesh.instance_count = max_marks
	multimesh.visible_instance_count = 0  # draw only the slots in use
	cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF


func add(pos: Vector3, normal: Vector3) -> void:
	var n := normal.normalized()
	var helper := Vector3.UP if absf(n.y) < 0.99 else Vector3.FORWARD
	var x := helper.cross(n).normalized()
	var b := Basis(x, n.cross(x), n)  # a QuadMesh faces +Z, so Z is the surface normal
	if random_spin:
		b = Basis(n, randf() * TAU) * b
	b = b.scaled(Vector3(size, size, size))
	multimesh.set_instance_transform(_next, Transform3D(b, pos + n * lift))
	_next = (_next + 1) % max_marks
	_count = mini(_count + 1, max_marks)
	multimesh.visible_instance_count = _count


func clear() -> void:
	_next = 0
	_count = 0
	multimesh.visible_instance_count = 0

With max_marks at 256, the 257th shot went into the first slot and visible_instance_count stayed at 256.

What we measured

A dark wall 6 m from the camera, holes 12 cm wide at random spots on it, one DirectionalLight3D, no shadows. Draw calls from the renderer's own monitor. Two runs gave the same draw calls.

Why it happens

Each MeshInstance3D is drawn on its own. Sharing the mesh and the material did not merge them: the draw calls went up by exactly one per hole. A MultiMesh hands all of its copies to the GPU at once, each with its own position, turn and size, and they are drawn in one call. Marks that never move once placed are what a MultiMesh is made for.

The number of marks also has to stop somewhere, or a long fight keeps adding them. With a fixed number of slots reused from the oldest, the 2,000th shot cost the same 2 draw calls as the 100th.

What to change

Why not a Decal node: with the Compatibility renderer in Godot 4.7, a Decal drew nothing in the same test with a circle on the ground. Where the hit comes from: a shot that lands on the crosshair. The spark at the same spot: a hit effect at the impact point.

Decals painted by hand instead: Decal Painter Kit for Godot 4 lets you click and drag decals onto walls and floors in the editor, with Undo, as real Decal nodes or as stickers cut to the surface that work in every renderer and Godot 4.7, and has paint_ray() for bullet and blood decals from code.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Decal Painter Kit for Godot 4 lets you click and drag decals onto walls and floors in the editor, with Undo, in every renderer, and has paint_ray() for bullet and blood decals from code.

More how-tos: Projectiles and aiming