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.
- The wall alone: 1 draw call.
- One MeshInstance3D per hole, all sharing one QuadMesh and one material: 101 draw calls with 100 holes, 501 with 500 and 2,001 with 2,000.
- The script: 1 draw call before the first shot, then 2 after 100, 500 and 2,000 shots.
visible_instance_countwas 100, then 256 and 256. Afterclear(): 1 draw call and no marks on screen. - The first 100 marks of the script covered as much of the screen as the 100 separate holes: 565 to 573 lit pixels against 564.
- A MultiMesh made by hand with 256 slots, only 10 of them set and
visible_instance_countleft at -1: the 246 empty slots showed nothing, 59 lit pixels either way. The script still setsvisible_instance_count, so only the slots in use are drawn.
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
max_marks: how many marks stay before the oldest is reused.sizeandlift: 12 cm wide and 1 cm off the surface. A flat mark lying exactly on a surface flickers against it, as in the glowing circle on the ground.- One node per kind of mark: bullet holes, blood and scorch marks each have their own texture, so each gets its own node.
add()takes world positions, so the node stays at the origin, not rotated or scaled. Marks on something that moves, a door or an enemy, belong on that object instead.
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
- A first-person gun that walls cannot cut
- A ball that hits the net however hard it is kicked
- A shot that meets a moving target
- An Area3D that does not see a bullet or another area
- A fire rate that holds at any frame rate
- Point swords, projectiles and models that face +Z at the target
- FPS shots that land on the crosshair
- A spell that keeps flying straight after it leaves the hand
- Turn towards a target the short way round
- A laser beam that stops where it hits, the moment you aim
- Fast projectiles that never fly through enemies
- A trajectory line that matches where the ball lands
- Aim a spell at the mouse on a 3D floor
- A homing missile that turns, but not instantly
- Particles fall sideways when you rotate the emitter
- Particles that fly into the player
- Gaps in the trail of a fast emitter
- Make a tower shoot the enemy closest to your base
- Hit the target with an arcing shot at any angle and height
- Kick a RigidBody3D ball with the same strength at any tick rate
- Reload without losing or making up rounds
- Fan out any number of projectiles evenly around the aim direction
- Recoil that settles back to where the player aims