OpenGL 3D Game Tutorial 36: Instanced Rendering

preview_player
Показать описание
LWJGL tutorial series on how to create a 3D Java game with OpenGL!

The final particle effects tutorial, this week about instanced rendering!

storeMatrixData() Code:

vboData[pointer++] = matrix.m00;
vboData[pointer++] = matrix.m01;
vboData[pointer++] = matrix.m02;
vboData[pointer++] = matrix.m03;
vboData[pointer++] = matrix.m10;
vboData[pointer++] = matrix.m11;
vboData[pointer++] = matrix.m12;
vboData[pointer++] = matrix.m13;
vboData[pointer++] = matrix.m20;
vboData[pointer++] = matrix.m21;
vboData[pointer++] = matrix.m22;
vboData[pointer++] = matrix.m23;
vboData[pointer++] = matrix.m30;
vboData[pointer++] = matrix.m31;
vboData[pointer++] = matrix.m32;
vboData[pointer++] = matrix.m33;

Upcoming tutorials:

- Random Terrain Generation
- Shadows
- Post processing
- Geometry shader

Future Tutorial Series:

- Game Audio
- Multiplayer
- Advanced Game Dev Concepts
- OpenGL Optimizing Techniques

Previous tutorial topics:

- Display
- VAOs and VBOs - Rendering a quad
- Rendering using glDrawElements
- Shader introduction
- Coloring using shaders
- Texturing
- Matrices, moving and rotating
- Loading 3D OBJ models
- Lighting I
- Lighting II
- Optimizations
- Transparency
- Fog
- Multitexturing
- Player Movement
- 3rd Person Camera
- Mipmapping
- Terrain Generation
- Terrain Collision Detection
- Texture Atlases
- GUIs/HUDs
- Multiple Light sources
- Point light attenuation
- Skybox
- Day/Night
- 3D Mouse Picking
- Water
- Cel Shading
- Normal Mapping
- Rendering Text
- Signed Distance Field Fonts
- Particle Effects

End of video music- Kai Engel, "Waking Stars":

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

Don't mind me, just setting some personal timestamps:

15:27 - Creating VBO and saying that it is an instanced one
17:45 - Using a method to which data is going where in the one big instanced VBO
18:42 - Don't forget to enable and disable all attributes
20:02 - How to update instanced VBO data (don't forget the hint shown some seconds before about the mistake he made)
21:18 - Changes in the rendermethod
22:56 - Make a float array which holds all the new data (the data for the next instance)
23:08 - Actually updating the vbo and draw the whole stuff

23:39 - So, if we now go ahead and run that, it will look exactly the same!

NOOBDP
Автор

You can efficiently sort the particles using a Treeset<Particle> and the interface Comprator<Particle>.

marcperlade
Автор

This is fucking amazing! Very clear explanations of all the VAO/VBO stuff!

MagpieMcGraw
Автор

I watch these to learn opengl c++, the functions are the same

PeguinDesign
Автор

Regarding the giant array of uniforms..

All graphics card have a limit to the amount of uniforms that can be bound in a single call, for instance intel HD 4000 integrated graphics has a limit of 4092. That sounds like quite a bit, but it's 4092 floats. Meaning that a single mat4 takes up 16 bind locations =(.

The limit is also different for many graphics cards so it's rather annoying. A way around this is uniform buffers, and of course what you've gone over.

firefly
Автор

You sir are awesome! Keep up the greatness :).

mitchyouker
Автор

I need help for some reason after this tutorial all my particles are going only up and not changing scale

nicolasschleicher
Автор

I added the code so that all of the texture atlases could be in one atlas but now when i render more than one particle system it gets buggy

urgentina
Автор

Is there anyway I could get a copy of the completed particle package, I've watched the particle tutorials at least 6 times over and I cannot get the scaling to work properly. Thank you!

jackshouseofanime
Автор

Christ almighty, you go through so much effort to calculate those matrices on the CPU and then transmit them to the GPU each frame, when you could have just sent position and scale information and calculated a per-vertex model matrix on the GPU.
GLSL will let you mess with the matrices - the easiest way is to just index the mat4 as a 2D array.

peterjohnson
Автор

Thanks, really helpfull, but why dont you use geometry shader and feedback with timebased animation?

GieneqAD
Автор

hello @ThinMatrix and thank you for these tutorials. I followed these last three tutorials as instructed. Then I had the idea to measure the time taken by the render function of the particleRenderer. The time taken for the function on my gamer laptop is [60, 000 to 300, 000 nanosec] with the function without instanced rendering, and the same function with the instanced rendering takes from [1, 000, 000 to 17, 000, 000 nanosec]. Which much more than the reverse of the desired result. Why Is the same result for you?

trouduc
Автор

hey @ThinMatrix
I know that its a old video but i just start to learn game programs and i watch this sires,
I wonder how do you make the particle go around the player i try to do a while loop and make a degress = 360, and call the update function and make the calculation around the player but its all go wrong can you please put some piece of code that make the particale goes around the player

dornahemani
Автор

Hi

I've been studying modern open gl 4.2 and have used gldrawarraysinstance and I then used an array element to access each element but cannot update instance positions such that the instances move separately when I run the program. do you have any ideas?

fisslewine
Автор

Great tutorial +ThinMatrix ! I'm impressed with such complex topics you effectively teach, you really are a great teacher. I'm sure everyone else as I - what is the next tutorial going to be on? (hopefully shadow mapping ;) )

chrisruley
Автор

9:50 this caused my fontVertexShader to break with:

ERROR: 0:1: '' : version '330' is not supported
ERROR: 0:1: '' : syntax error: #version

how am I supposed to fix that?

AgentM
Автор

I need help. I followed all your tutorial but when i run it, it throws an error saying not supported

da_kgamer
Автор

Can you do a quick tutorial on frustum culling? I noticed that the game still lags, even when not looking at the particles.

bryceblankinship
Автор

I'm not sure how long you tested this code but if you let it run for an extended period of time you end up with an Any idea as to why this may be happening. I've gone through the tutorial numerous times and I'm certain I didn't miss anything. Your thoughts?

dustybaldwin
Автор

ThinMatrix, you seem very, focused, smart, and overachieving for someone your age, especially in todays society. What are your philosophies on life in terms of your career, learning and creating?

What were you like in university? (Some people graduate without even being competent at simple programming, so I've heard) - since you also did CS.

ManMadeToons