Sprite Batching In OpenGL (Uniform Buffer Objects) // OpenGL Tutorial #33

preview_player
Показать описание
In this video we take a break from 3D and explore 2D rendering using a sprite batching technique in OpenGL. This is also a great opportunity to get introduced to Uniform Buffer Objects which is a more efficient way of loading uniforms than the method that we've been using so far, especially when you have many of them. UBOs can be used for 3D as well so even if you don't plan on doing 2D rendering you should definitely learn about them.

Timecodes
0:00 Intro
0:26 Sprite Batching
1:54 Calculating sprite size in texture space
2:34 Screen space to NDC
2:47 Sprite batching solution
4:09 The vertex shader
4:54 The fragment shader
5:52 Supporting multiple sprite sheets
6:03 The QuadArray class
6:37 The SpriteBatch class
8:22 Simple animation example
8:35 Efficiency of uniform variables
9:08 Uniform Buffer Objects
13:40 Conclusion

Feel free to comment below.

Twitter: @ogldev

Enjoy,

Etay Meiri

#opengl #ogldev #opengtutorials
Рекомендации по теме
Комментарии
Автор

Very good info and explanation! thanks

miumpre
Автор

Thanks a lot. Btw have you ever consider making a video about OIT ?

mourirsilfaut
Автор

You are awesome! I am very grateful for your work! I was wondering, is it worth doing batching in a 3D renderer? Or maybe it will turn out to be a useless feature (especially with different assimp optimizations)... It seems to me that this would be useful in a game with low-poly like graphics, but certainly not in a physically based renderer or something like that, am I right?

SB-pqdp
Автор

Multiple identical quads is a simple sollution tho you can also use only one with very simple modifications

orocimarosay
Автор

Can't you create a struct containing the releavant quad info (base pos etc.) and then create an array of struct with size MAX_QUADS?

struct T {
vec2 BasePos;
vec2 WidthHeight;
...
};

uniform T QuadInfo[MAX_QUADS];

MrFabrizioV
Автор

Slightly unrelated, instead of using 6 vertices to draw the quad you could also use only 4 vertices with an element buffer object right? Does this make performance better?

thomasnguyen
Автор

How would you handle rotation of each individual sprite in this scenario?

razcodes
Автор

Is there a simple way to add a uniform to the frag shader so that we can determine the offset of the spritesheet? Your set up is quite different from the opengl tutorial I'm following, so I'm curious if it's a simple task or not.

pastasawce
Автор

I'm still trying to figure out the vertex buffer, index buffer, and the vao thing. How do I draw multiple different models? Do I have to declare a different vertice and indice buffer for each object or do I declare all models in one vertex buffer and one index buffer? And the vao: what the f is this? I'm still confused...

developerdeveloper