OpenGL - instancing

  Рет қаралды 11,986

Brian Will

Brian Will

Күн бұрын

Code samples derived from work by Joey de Vries, @joeydevries, author of learnopengl.com/
All code samples, unless explicitly stated otherwise, are licensed under the terms of the CC BY-NC 4.0 license as published by Creative Commons, either version 4 of the License, or (at your option) any later version.

Пікірлер: 24
@Monogrammaton
@Monogrammaton 3 жыл бұрын
Good job. This is what finally made me fully understand instanced rendering after many years of avoiding it.
@cmdlp4178
@cmdlp4178 4 жыл бұрын
This is really useful for CAD programs. Consider thousands of objects, which are all the same, but at different positions.
@smallgoodwoodoodaddy
@smallgoodwoodoodaddy 4 жыл бұрын
Very interesting! Thank You!
@taureanwooley
@taureanwooley 11 ай бұрын
Best part about instance rendering is that it begins the process of noticing and understanding what is and isn't being drawn, which can compute to more degragation of the vertices and faces that may be duplicated by simple resizing and minor skewing. This is what current usages of Nanite rendering does with large model files so that it can read directly from memory without over reading. It gets more intense when you started understanding why the instances are being "painted" quicker because the memory access is duplicated throughout the process, creating a copying effect that can be organized further with other algorithms/testing.
@seditt5146
@seditt5146 4 жыл бұрын
Curious, couldn't the amount of data needing to be sent to the GPU via Attributes be cut in half by sending two Vec4 of the Position and Rotation at this point? There is no need to send a Matrix. Given the savings of performing yet another matrix multiplication coupled with GPUs optimization for trig functions and the Data bus savings it might out perform sending all that extra data. All we would have to compensate for would be a trig rotation. Personally I would just use resident buffer in this case and if not available use a Texture to pass my data.
@spider853
@spider853 4 жыл бұрын
are multiple textures possible with instancing? (not uvs)
@Edo_Aelio
@Edo_Aelio 3 жыл бұрын
Amazing! Seeing the planet now I feel dumb being unable to draw just the same cube a few thousands of times :(
@overloader7900
@overloader7900 3 жыл бұрын
My attempts at drawing a triangle fails half of the times :)
@cmdlp4178
@cmdlp4178 4 жыл бұрын
Could you do the scaling similar to the translating without changing the vertex shader?
@briantwill
@briantwill 4 жыл бұрын
In the example, the 'instance buffer' contains just x and y offsets, but you can put whatever data you want into an instance buffer, including different scaling factors for each instance. The example uses gl_InstanceID instead just to demonstrate how it might be useful.
@IslandHermit
@IslandHermit 4 жыл бұрын
How is the binding between vertex arrays and the location numbers in the shader determined? Are they simply the order in which the vertex arrays were created?
@briantwill
@briantwill 4 жыл бұрын
The (location = n) on the input, where n corresponds to the VAO index. Note aInstanceMatrix is a mat4 with (location = 3), and by virtue of being 16 floats in size, it also encompasses indexes 4, 5, and 6.
@IslandHermit
@IslandHermit 4 жыл бұрын
@@briantwill Sorry, I wasn't clear. It's the values of 'n' that I'm asking about. For example, in your code you call glGenBuffers() to create instanceVBO and three lines later you enable vertex attrib array '2'. How do you know (or how do you tell OpenGL) that instanceVBO is attrib array 2? Is it the glBindBuffer() call immediately after that sets up that association?
@briantwill
@briantwill 4 жыл бұрын
@@IslandHermit glEnableVertexAttribArray(0) enables index 0 of the VAO. glVertexAttribPointer(0, ...) sets the currently bound buffer to index 0 of the VAO So whichever glBindBuffer() call that was prior to glVertexAttribPointer() specifies the relevant buffer. Does this answer your question?
@IslandHermit
@IslandHermit 4 жыл бұрын
@@briantwill Yeah, that does. Thanks.
@noahwilliams8996
@noahwilliams8996 4 жыл бұрын
How often is this actually used? The app would need to remember that each object is the same object, and how often do you really need a huge number of the same object?
4 жыл бұрын
foliage, particle effects etc.
@squarerootof2
@squarerootof2 3 жыл бұрын
Lmfao! Always?
@noahwilliams8996
@noahwilliams8996 3 жыл бұрын
@@squarerootof2 Be rational! What video games are going to have that many repeated models?
@squarerootof2
@squarerootof2 3 жыл бұрын
@@noahwilliams8996 That question's been answered. This is not about character models. You're a bright guy. I like your playlists. Learn a little bit more about graphics cards and how they work if you're interested. OpenGL is a good place to start. I can be pretty rational if you just round me off to a few significant digits :)
@Mugistan
@Mugistan 3 жыл бұрын
@@noahwilliams8996 I'm not sure if what I'm saying is true but It would be good if you're doing a 2D thing since well most textures would be put on a quad so you just need to slap the Texture ID to to the buffer
OpenGL - PBR (physically based rendering)
12:47
Brian Will
Рет қаралды 29 М.
Let's all try it too‼︎#magic#tenge
00:26
Nonomen ノノメン
Рет қаралды 43 МЛН
маленький брат прыгает в бассейн
00:15
GL Show Russian
Рет қаралды 3,8 МЛН
原来小女孩在求救#海贼王  #路飞
00:32
路飞与唐舞桐
Рет қаралды 65 МЛН
Glow Stick Secret (part 2) 😱 #shorts
00:33
Mr DegrEE
Рет қаралды 30 МЛН
Vertex Buffer Objects and Vertex Array Objects
8:35
GetIntoGameDev
Рет қаралды 22 М.
OpenGL (2024) for the Absolute Beginner #1... Why Bother?
9:45
Code Imposter
Рет қаралды 2,3 М.
OpenGL - shadow maps (for directional lights)
17:32
Brian Will
Рет қаралды 21 М.
OpenGL glDrawElementsInstanced
17:49
Jamie King
Рет қаралды 11 М.
OpenGL Tutorial 21 - Instancing
4:56
Victor Gordan
Рет қаралды 17 М.
OpenGL - normal maps
13:23
Brian Will
Рет қаралды 10 М.
OpenGL - deferred rendering
9:42
Brian Will
Рет қаралды 30 М.
[Unity] GPU Instancing Tutorial
16:38
Kyle Andrews
Рет қаралды 44 М.
Let's all try it too‼︎#magic#tenge
00:26
Nonomen ノノメン
Рет қаралды 43 МЛН