Skip to content

Commit 0d6a1eb

Browse files
committed
add(/wiki/virtual-sprites): draft from 7th May 2025
1 parent 64f4a06 commit 0d6a1eb

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
+++
2+
title = "Virtual Sprites"
3+
description = "Dynamically building an atlas of used sprites at runtime."
4+
draft = true
5+
[taxonomies]
6+
categories = ["rendering"]
7+
tags = ["rendering", "texturing"]
8+
+++
9+
10+
> Dynamically building an atlas and index of sprites at runtime...
11+
12+
{{ todo_notice(body="This article is incomplete and explains an experimental technique.") }}
13+
14+
## Motivation
15+
16+
{{ todo_notice(body="Convert to paragraphs? Explain better?") }}
17+
18+
- Building a texture atlas at start-up of *all* the sprites is quite the expensive process.
19+
- Array textures are limited to ~2048 layers and require all sprites to have the same size.
20+
- Both a normal atlas and array-textures have trouble with animated textures.
21+
- Uploading small textures/sprites to the GPU is surprisingly fast and easy.
22+
- As chunk meshes depend on their used sprites, we can't save/restore them to disk.
23+
- Being able to dynamically create new sprites at runtime as needed is neat.
24+
- Being able to let sprites have special projections and parameters is neat.
25+
- Surprisingly this is doable, though slower, with older OpenGL versions!
26+
- (iirc, older GPUs/drivers don't like random-ish memory/texture reads?)
27+
28+
Silly things one can do with this technique:
29+
30+
- 'Environmental' sprites.
31+
- User-generated sprites.
32+
- Font glyphs and emoji.
33+
34+
Drawbacks:
35+
36+
- Whomst cares?
37+
38+
## Implementation
39+
40+
{{ todo_notice(body="Finish (minimal) implementation?") }}
41+
42+
```glsl
43+
#version 460 core
44+
45+
struct SpriteDef {
46+
float uv[4];
47+
};
48+
49+
layout(binding = 0, std430) readonly buffer ssbo_sprites {
50+
SpriteDef sprites[];
51+
};
52+
53+
struct Facelet {
54+
int data0; // position, dimensions, rotation
55+
int data1; // colortint, corner-ao, ...
56+
int data2; // spriteref, spritearg, ...
57+
}
58+
59+
layout(binding = 1, std430) readonly buffer ssbo_faces {
60+
Facelet facelets[];
61+
};
62+
63+
struct Meshlet {
64+
mat4 transform;
65+
int facelets_start;
66+
int facelets_count;
67+
}
68+
69+
layout(binding = 2, std430) readonly buffer ssbo_meshlets {
70+
Meshlet meshlets[];
71+
};
72+
```
73+
74+
---
75+
76+
{{ todo_notice(body="Recommended: Face Pulling") }}
77+
{{ todo_notice(body="Requirement: SSBOs or BufferTextures") }}
78+
79+
## See also
80+
81+
- [Face Pulling](/wiki/face-pulling)
82+
- [Vertex Pooling](/wiki/vertex-pooling)
83+
84+
## References
85+
86+
- [SSBOs](https://ktstephano.github.io/rendering/opengl/ssbos)

0 commit comments

Comments
 (0)