Batch Rendering - Colors

  Рет қаралды 54,962

The Cherno

The Cherno

Күн бұрын

Patreon ► / thecherno
Instagram ► / thecherno
Twitter ► / thecherno
Discord ► thecherno.com/discord
Series Playlist ► thecherno.com/opengl
#OpenGL #BatchRendering

Пікірлер: 89
@_sevelin
@_sevelin 4 жыл бұрын
Just finished watching the old OpenGL videos, I must admit, the quality and video editing has drastically improved.
@Doylgaafs9
@Doylgaafs9 4 жыл бұрын
Hey, what is up the Cherno? We want "Hey, what is up guys" back!
@JayAnAm
@JayAnAm 4 жыл бұрын
Thx a lot, this helped a lot on my Blender addons, just had to change the built-in shader (2D_COLOR) to custom shaders (vertex and fragment) and dynamically change the position and color of my vertices to draw a custom textbox with background, text and outlines in one batch!
@lephobix
@lephobix 2 жыл бұрын
You taught me how to love OpenGL! Thanks for all the high quality content😄
@3Descape
@3Descape 4 жыл бұрын
Really liking the new, more focused videos! Keep it up, really great work you are doing here!
@oblivionronin
@oblivionronin 4 жыл бұрын
Looking at this after watching the whole series (awesome work btw) The reason we have indices buffers in the first place is to avoid being wastefull with memory. Woudl it be possible and not better to create some sort atlas of colors we need for our next render and use the generated indices of that atlas to pass color in the vertex buffer instead of copy-pasting colors mutliple time as shown @ 5:15 ? I also understand this video is made to be simple. So my question is more is that possible ?
@nevergarden5225
@nevergarden5225 2 жыл бұрын
Shoutout to my Ukrainian fans here with these colors 7:19 🥺
@Schnief
@Schnief 2 жыл бұрын
Yeah, that aged well
@bluesillybeard
@bluesillybeard 2 жыл бұрын
Hey, that was the solution I was thinking of! GLSL layouts ftw!
@colinmaharaj
@colinmaharaj 2 жыл бұрын
7:17 Shout out to the python weirdos you mean 😆
@juliancruz1927
@juliancruz1927 4 жыл бұрын
Amazing video. Can you please make a group of videos about GPU profiling and Debugging? That would be amazing. Thanks in advance!
@RadicDotkey
@RadicDotkey 4 жыл бұрын
Hi. I'm trying to implement Signed Distance Field fonts with batching, but I stumbled across one issue. When I draw a wide shadow underneath each letter using SDF shader the shadow overlaps the letters drawn previously. Do you know any way around it apart from drawing twice or creating an intermediary render buffer? If so, could you adress it in your video? The overall SDF subject is a good material for a video, with its strenghts and disadvantages in my opinion.
@mjthebest7294
@mjthebest7294 2 жыл бұрын
Nice Ukraine colors! :)
@anilkumarsingh3241
@anilkumarsingh3241 4 жыл бұрын
So, does batch rendering always come at the cost of more data on cpu(like colors in this one per vertex and duplicate vertices in the previous one)? For example, in case of rendering multiple copies of assets with millions of vertices at different location with different optical properties, can't rendering be batched without having to duplicate all the vertex data?
@sam_is_people1170
@sam_is_people1170 2 жыл бұрын
thanks!!
@fredhair
@fredhair 4 жыл бұрын
Well this is good if you want each vertex a different color however in the video both quads are the same color at each vertex. If you are looking to do a single color as shown in the video I would personally avoid sending so much data through the pipeline unnecessarily. Just send the data once and use the glVertexAttribDivisor function to specify that this color will be the same for each triangle (or 6 vertices if you know you'll only want quads). If you don't want any alpha blending also you could just send a vec3 to save sending more data.
@TheCherno
@TheCherno 4 жыл бұрын
Yep, that's definitely a valid approach as well. I'll probably address this in a future video, I wanted to keep things simple here.
@fredhair
@fredhair 4 жыл бұрын
@@TheCherno That makes sense, I like being able to specify individual vertex colors and transparency as it can lead to some nice effects.
@lukassoo
@lukassoo 4 жыл бұрын
Valid approach but not possible on an older device that supports only OpenGL ES 2 meaning glVertexAttribDivisor does not exist yet. For normal OpenGL programming these days it's probably never going to be a problem with new hardware but in my case i have to use the simplest way like in the video or upgrade.
@richardlighthouse5328
@richardlighthouse5328 4 жыл бұрын
Using vec3 or vec4 for color is worse than using integer for color. vec3 has 3 floats, one float is 4 bytes so 12 bytes. whereas using integer only uses 4 bytes. Huge improvement. Sparky game engine series included how to do that.
@fredhair
@fredhair 4 жыл бұрын
@@richardlighthouse5328 That's true, I've done that in my recent projects as its rare you actually need that many different colors! 8-bits per channel is plenty.
@harei6440
@harei6440 3 жыл бұрын
I'm your Ukrainian fan, thanks for the colors and for cool videos
@__gadonk__
@__gadonk__ 2 ай бұрын
hope you're doing fine man
@dekrain
@dekrain 4 жыл бұрын
Hi! What would you recommend for implementing flat shading? (i.e. store one attribute per face, not vertex)
@dustinhollar9710
@dustinhollar9710 4 жыл бұрын
For flat shading, you would probably continue to use the {position, color} attributes per vertex, but add another attribute for normals. Your Vertex representation might then look like: {position, normal, color}. Now what gets you the flat shading look is by using face normals rather than vertex normals, so three vertices of a single triangle will have the same normal.
@Neran280
@Neran280 4 жыл бұрын
Do your lighting calculation in the vertex shader and pass the computed color as flat out param to the fragment shader. flat means that after rasterizing you will not get interpolated colors but the same per triangle. in the fragment shader just set gl_color to the color.
@BlockAssault
@BlockAssault 4 жыл бұрын
Hey, could you do a video on texture atlas and use them in batch rendering, and then lead that on to applying shaders with different UV coords to the triangles being represented? I'm having some difficulty in producing a shader on top of a texture atlas. Assuming there is a 128 x 128 texture atlas comprising of 4 different textures that each have their own UV min and max, how can I apply a shader with a picture size of 64 x 64 onto each of those 4 textures on the 128 x 128 image?
@G1g4ntvltLP
@G1g4ntvltLP 4 жыл бұрын
You can join chernos discord server. The community is increadibly helpful and very fast! I bet you get some help for your problem there ;)
@ccricers
@ccricers 4 жыл бұрын
I've been making 1x1 pixel textures for color materials and some models have dozens, then I just learned OpenGL has texture arrays so I really only have to make one texture fetch per model. whoops...
@ymi_yugy3133
@ymi_yugy3133 4 жыл бұрын
How do I change the way colors are interpolated between vertices?
@geraldofada
@geraldofada 4 жыл бұрын
Hey Cherno, what do you think about Vulkan? Are we going to have a series about it or nah?
@Tachi107
@Tachi107 4 жыл бұрын
Man, I love music as much as you do, but I find it kinda distracting :/ What about keeping it on just during the intro?
@RafaelCamposNunes
@RafaelCamposNunes 4 жыл бұрын
I agree that is quite loud and should be at a bit more low after the intro.
@faimenDev
@faimenDev 4 жыл бұрын
5:11 HOW??????
@faimenDev
@faimenDev 4 жыл бұрын
@@trol9880 TY TY TY TY TY TY TY!!!!!
@lolcat69
@lolcat69 Жыл бұрын
i colored the quads in the first video passing a vec3 for the color in every vertex ( like what you did with texture coords ), but i am going to stay to see what you do :)
@paullipczyk5216
@paullipczyk5216 Жыл бұрын
why aren't you using a vec4? Shouldn't the values be R G B and alpha for colors?
@DrOptix
@DrOptix 4 жыл бұрын
@TheCherno, can we save vertex buffer space using a memory layout like the following one, per quad? R, G, B, A, P1.X, P1.Y, P1.Z, P2.X, P2.Y, P2.Z, P3.X, P3.Y, P3.Z, P4.X, P4.Y, P4.Z I feel we waste space mentioning the same color 4 times. I don't know maybe I'm over optimizing.
@minirop
@minirop 4 жыл бұрын
OpenGL doesn't handle that. Imagine a vertex like an index into an array (of colours, positions, etc.). i.e. I don't think there is a way to say to OGL "all my next drawn vertices will be this colour".
@richardlighthouse5328
@richardlighthouse5328 4 жыл бұрын
what is 4 floats * 8 = 32 floats * 4 bytes = 128 bytes gonna do? Modern GPU's have VRAM into gigabytes. Yes it is over optimizing.
@bartpelle3460
@bartpelle3460 4 жыл бұрын
@@richardlighthouse5328 It has nothing to do with VRAM but with bus speed.
@richardlighthouse5328
@richardlighthouse5328 4 жыл бұрын
@@bartpelle3460 Yes, forgot about that. Bus speed is very fast and only optimization you can do with colors is use unsigned integer for rgba.
@jamesmnguyen
@jamesmnguyen 4 жыл бұрын
If you really want to have only one color per quad. Try looking into Instancing.
@ragdude7323
@ragdude7323 4 жыл бұрын
Wooo
@Narblo
@Narblo 4 жыл бұрын
I use instancing for my gui but didnt meassure performance against this kind of batching. UvCoords and transforms are per instance attributes. What do you guys think? did someone did the performance test or can foresee a drawback?
@jamesmnguyen
@jamesmnguyen 4 жыл бұрын
One of the reasons we use batching is to reduce the time sepnt sending data to the GPU. Sending everything at once is faster than sending little bits multiple times. Instancing is a different approach. Send a small bit of data and per-instance data. Then let the GPU assemble the instance rather than you.
@Crisslt3
@Crisslt3 4 жыл бұрын
so a substitute for uniforms is polluting 16 bytes of memory for EVERY VERTEX?? XD seriously I'm looking forward to textures tutorial
@mcmikecreations
@mcmikecreations 4 жыл бұрын
Shout out for Ukrainian fans accepted 😁 Have you ever thought about making a Vulkan series after the OpenGL and Game Engine one?
@PcGameHunter
@PcGameHunter 4 жыл бұрын
He already answered this: "Vulkan is much more low-level and complicated, it's really difficult for some starting out with graphics to immediately jump into Vulkan. It's likely that eventually I'll have something like this for Vulkan, but for now much more of my audience will benefit from OpenGL. As a rough comparison - it's like trying to learn to make games using C++ or Unity; Unity is going to help you learn how to actually make games, whereas with C++ you'll be stuck building an engine the whole time."
@akchilov
@akchilov 4 жыл бұрын
vulkan-mare...
@ccricers
@ccricers 4 жыл бұрын
I'll give V-EZ a try. It's a wrapper framework that would try to bridge the gap between APIs like OpenGL and Vulkan.
@KennyTutorials
@KennyTutorials 3 жыл бұрын
@@ccricers Cherno already try Vulkan :) Check his last video.
@nathanpinard5132
@nathanpinard5132 4 жыл бұрын
Hey Cherno! I saw the piano at the back, do you actualy play piano?
@jonphillips4082
@jonphillips4082 4 жыл бұрын
After seeing him Sing and play guitar, my guess is, "Yep" :)
@iozsaygi
@iozsaygi 4 жыл бұрын
Can someone give me the link of the music that plays at the start?
@iozsaygi
@iozsaygi 4 жыл бұрын
@@igorteixeira2962 Thank you so much
@animania6947
@animania6947 4 жыл бұрын
I was waiting to see a multi-draw indirect 😔
@jamesmnguyen
@jamesmnguyen 4 жыл бұрын
I've only used that command when I wanted to draw multiple different 3d textured models at the same time. But it's satisfying.
@muhammadseyan8361
@muhammadseyan8361 3 жыл бұрын
can't we set the color per triangle or something? isn't this method kinda wasting memory?
@awuuwa
@awuuwa 4 жыл бұрын
this music in the beginning of this video sounds similar to "Future - Mask Off" without the singing, not so much, but it reminds me of it. just my opinion
@DrJams
@DrJams 4 жыл бұрын
Music gets a bit annoying after a few minutes.
@Doylgaafs9
@Doylgaafs9 4 жыл бұрын
Where is "what is up guys"? :(
@Dr.SexySpice
@Dr.SexySpice 4 жыл бұрын
he's not doing that since the start of the new decade
@Doylgaafs9
@Doylgaafs9 4 жыл бұрын
@@Dr.SexySpice That's the end of an era :(
@Light-wz6tq
@Light-wz6tq 4 жыл бұрын
Does anyone here know DirectX? I am trying to implement batch rendering myself, I've done OpenGL the side and I have difficulties with DirectX. this is my glsl code: #version 450 core out vec4 FSOutFragColor; in vec2 VSOutTexCoords; in flat uint VSOutTexIndex; uniform sampler2D[16] u_Textures; void main() { FSOutFragColor = texture(u_Textures[VSOutTexIndex], VSOutTexCoords); } When I do the same thing with hlsl's Texture2D it gives me: X3512: sampler array index must be a literal expression Can someone help me through? ^__^
@jvcmarc
@jvcmarc 4 жыл бұрын
in the main(), when you call the u_textures array and invoke the element by passing VSOutTexIndex I believe you can't pass a variable as the array index, it has to be a literal value that's what the error means at least
@Light-wz6tq
@Light-wz6tq 4 жыл бұрын
@@jvcmarc I knew that but thanks for replying :3
@Light-wz6tq
@Light-wz6tq 4 жыл бұрын
hi
@jalomic
@jalomic 3 жыл бұрын
Здоровеньки булы, хлопец =)
@torf1746
@torf1746 Жыл бұрын
Ahead of the times with the Ukraine colors
@__gadonk__
@__gadonk__ 2 ай бұрын
fym the war started in 2014
@TheIgoorR
@TheIgoorR 4 жыл бұрын
Like from Ukraine: ✓
@ilnev3738
@ilnev3738 3 жыл бұрын
и из России
@lukasjetu9776
@lukasjetu9776 9 ай бұрын
​@@ilnev3738a také z Česka
@obinator9065
@obinator9065 4 ай бұрын
@@ilnev3738нет
@lorenzof4787
@lorenzof4787 2 жыл бұрын
I understand that the OpenGL series was filmed over a time span of 3 years, but for someone watching it in the span of 2 weeks, there's quite a lot of cognitive dissonance going on with how the code is written. At the beginning of the series he basically spent a whole episode writing code to parse the shader so that it could be read from 1 file, and here he is with 2 separate files for vertex and fragment shader! ahah There are other inconsistencies too, but I think that's good overall, it forces me to actually write code without mindlessly following Cherno verbatim. I've absolutely loved this series so far.
@codemastercpp
@codemastercpp 2 жыл бұрын
The inconsistencies is because he's showing code of game engine, where he originally creates the batch renderer iirc
@odismal
@odismal 4 жыл бұрын
love u cutie
@farukalpay8522
@farukalpay8522 4 жыл бұрын
Bist du deutsche?
@__gadonk__
@__gadonk__ 2 ай бұрын
der Bre ist Australier
@__gadonk__
@__gadonk__ 2 ай бұрын
Scheint aber sowohl Deutsch, als auch Russisch zu sprechen
@mohammedshoaib1635
@mohammedshoaib1635 4 жыл бұрын
First. Nope that's it. That's all I had to say.
@alexwhite6133
@alexwhite6133 4 жыл бұрын
good channel, but actually the channel is just about the basic stuff, just always reissued, don't think the Hazel Engine will ever get beyond a basic render framework ;)
@jonphillips4082
@jonphillips4082 4 жыл бұрын
Tru'Dat, Great stuff!, he's also been currently implementing Vulkan into the development version.
@WillMcCKill
@WillMcCKill 4 жыл бұрын
You could always go read code on GitHub or be a patron ;)
Batch Rendering - Textures
15:51
The Cherno
Рет қаралды 53 М.
I ACCIDENTALLY Created Hazel's Greatest Feature
18:21
The Cherno
Рет қаралды 38 М.
Китайка и Пчелка 4 серия😂😆
00:19
KITAYKA
Рет қаралды 3,5 МЛН
Harder Than It Seems? 5 Minute Timer in C++
20:10
The Cherno
Рет қаралды 121 М.
Coding Graphics in C: SetPixel, LineDraw, Moire and More!
8:36
Dave's Garage
Рет қаралды 133 М.
Let's code 3D Engine in Python from Scratch
14:55
Coder Space
Рет қаралды 373 М.
Batch Rendering - An Introduction
12:25
The Cherno
Рет қаралды 98 М.
Introduction to shaders: Learn the basics!
34:50
Barney Codes
Рет қаралды 281 М.
D5 Render 2.5 Magic: Crafting Animations Like Never Before
14:45
Show It Better
Рет қаралды 89 М.
5 Tips for FASTER Renders in Blender Cycles
13:25
Kaizen
Рет қаралды 629 М.
Китайка и Пчелка 4 серия😂😆
00:19
KITAYKA
Рет қаралды 3,5 МЛН