Vulkan For Beginners Tutorial #1
11:44
Пікірлер
@JuanGarcia-lo2el
@JuanGarcia-lo2el 19 сағат бұрын
Hello There! I love your tutorials, I almost done with the animation series. Where can I be in touch with you to send you some questions?
@OGLDEV
@OGLDEV 19 сағат бұрын
Thanks! you can email me at [email protected]
@StinkySkunk100
@StinkySkunk100 3 күн бұрын
I'm glad I found this. I've never used OpenGL (or C++ for that matter) and my first project was going to do an infinite terrain generator. I implemented it by generating squares of terrain, with the normal, texture coordinates, and height values and just passing all that into the vertex shader and it converted it to world space before passing it to the fragment shader. Though I really wanted to do tessellation because I thought it was really neat and would allow for much bigger landscapes. I was about ready to give up until I found this and your other videos which have been the best explanation I've seen on tessellation shaders. If I understand it right for something like a procedural generated terrain you would create each patch you generate as a 1x1 grid but also pass in a heightmap generated for each patch. Then inside the tessellation evaluation shader that's when the actual Y coordinates are mapped to each vertices that are created by the tessellation control shader. Then finally mapping it by scaling and translating it by whatever the world scale is (such as 64)?
@OGLDEV
@OGLDEV 2 күн бұрын
You can create the grid from 1x1 squares (patches) and scale them up by the world scale in the vertex shader, OR, you can scale them already in the vertex buffer and save up one multiplication. You usually use one heightmap for the entire grid and not just for a single patch. As you said, we sample the height in the evaluation shader so basically the grid is flat in the vertex buffer. I guess you can also scale it in the TES but I haven't tried that.
@darkmissionofficial
@darkmissionofficial 4 күн бұрын
These tutorials are clear than others out there, Thank you bro 😘
@OGLDEV
@OGLDEV 4 күн бұрын
Glad you like them!
@darkmissionofficial
@darkmissionofficial 3 күн бұрын
@@OGLDEV compare opengl with vulkan make me easier to understand ❤
@OGLDEV
@OGLDEV 3 күн бұрын
OpenGL is great way to start
@RealCatDev
@RealCatDev 4 күн бұрын
9,11k subscribers? niceee
@OGLDEV
@OGLDEV 4 күн бұрын
wow...
@linearz
@linearz 6 күн бұрын
In my opinion as a beginner, debugging tool such as RenderDoc should be introduced in any graphics programming tutorial on the first day, after drawing the first triangle.
@OGLDEV
@OGLDEV 5 күн бұрын
I agree and it's been on my todo list for quite some time. I'm not familiar with RenderDoc so I will try to find some time to learn it. I've been using apitrace which is very nice but probably less capable than RenderDoc.
@linearz
@linearz 5 күн бұрын
@@OGLDEV RenderDoc saves me a lot of time, especially for stupid bug from my own mistakes 😅.
@PaulPaulPaulson
@PaulPaulPaulson 6 күн бұрын
I knew most of WHAT vulkan is doing but this video really helps to understand WHY it's doing it that way. Thank you!
@OGLDEV
@OGLDEV 6 күн бұрын
You're welcome!
@OGLDEV
@OGLDEV 8 күн бұрын
Clone the sources: git clone --recurse-submodules github.com/emeiri/ogldev.git If you want to get the same version that was used in the video you can checkout the tag 'VULKAN_09'. Build on Windows: Open the Visual Studio solution: ogldev\Windows\ogldev_vs_2022\ogldev_vs_2022.sln Build the project 'Vulkan\Tutorials\Tutorial09'
@linearz
@linearz 9 күн бұрын
Yes, I enjoy this video 😊. Watching for the 2nd time, better understanding now. Will watch again in the future.
@OGLDEV
@OGLDEV 8 күн бұрын
:-)
@pynimp
@pynimp 10 күн бұрын
what is this, i nee in this world, where is the start poin to learn?
@OGLDEV
@OGLDEV 9 күн бұрын
kzbin.info/www/bejne/e6SogWyff7B1nrc
@harry-ie5xd
@harry-ie5xd 11 күн бұрын
great tutorials i didn't know where to begin until i found this but im having a issue where my thing flips back and forth very fast if i could get some help that would be great (i know im posting this 3 years after the video was made so im not expecting a response) :-) ps: on windows using visual studio 2022
@OGLDEV
@OGLDEV 10 күн бұрын
Thanks! maybe you can share more info on the problem. What do you mean it flips back and forth? Is it related to the uniforms? Perhaps it is just a matter of frame rate being too fast or the uniform value changes too drastically.
@PP-ss3zf
@PP-ss3zf 13 күн бұрын
thanks for this video. in general terms, how do i ensure that 180 degrees lock on the vertical look of the camera? im using threejs (javascript library). im having trouble with my Z (roll) axis - i apply quaternion to X and Y properly and it works but its making effect on Z as well. Maybe the X and Y axis used for quaternion is wrong?
@OGLDEV
@OGLDEV 12 күн бұрын
You're welcome! What do you mean by 'a 180 degrees lock'? Are you referring to gimbal? In general quaternions are the solution to a gimbal. Are you applying yaw and pitch correctly but as a side effect you're also getting a roll? Maybe you can share some code as an example.
@OGLDEV
@OGLDEV 15 күн бұрын
Clone the sources: git clone --recurse-submodules github.com/emeiri/ogldev.git If you want to get the same version that was used in the video you can checkout the tag 'TUT_46_FREETYPEGL'. Build on Windows: Open the Visual Studio solution: ogldev\Windows\ogldev_vs_2022\ogldev_vs_2022.sln Build the project 'OpenGL Tutorials\Tutorial46_FreetypeGLDemo'
@linearz
@linearz 15 күн бұрын
I have to set transpose param for glUniformMatrix4fv to GL_FALSE, otherwise it's not working properly. But I don't understand why :)
@OGLDEV
@OGLDEV 15 күн бұрын
If you specify the matrix in column major order you need to set transpose to GL_FALSE. Otherwise (row-major) use GL_TRUE.
@linearz
@linearz 15 күн бұрын
@@OGLDEV GLM is column major, TIL. Thank you for the explanation.
@linearz
@linearz 16 күн бұрын
I'm following your tutorial with GLFW and with different programming language. Now, I understand why I have to use VAO from the start, the other tutorial I followed to get me started is using Core Profile.
@OGLDEV
@OGLDEV 16 күн бұрын
Thanks, so everything is ok?
@linearz
@linearz 16 күн бұрын
@@OGLDEV yup, everything is working well. Thanks again!
@OGLDEV
@OGLDEV 16 күн бұрын
You're welcome :-)
@wangyangshi
@wangyangshi 16 күн бұрын
Good video, simple, clear, step by step. ❤❤
@OGLDEV
@OGLDEV 16 күн бұрын
Thank you! 🙂
@linearz
@linearz 17 күн бұрын
It's not to late to say thank you. I've learn a lot.
@OGLDEV
@OGLDEV 17 күн бұрын
You're very welcome!
@tuananhnguyenba1827
@tuananhnguyenba1827 17 күн бұрын
Is there a sound code?
@OGLDEV
@OGLDEV 17 күн бұрын
Sure, here it is github.com/emeiri/ogldev/tree/master/TerrainWater
@vvgr409
@vvgr409 18 күн бұрын
I like the fact that you compare Vulkan to OpenGL when you explain Vulkan. Learning Vulkan without any graphics experience is pretty hard and it's much easier to understand it when you know how Vulkan things can be translated to OpenGL.
@OGLDEV
@OGLDEV 18 күн бұрын
Thanks!
@chrispizz1327
@chrispizz1327 20 күн бұрын
Thank you , now I understand what you explained to me few weeks ago 👍
@OGLDEV
@OGLDEV 19 күн бұрын
Glad to help!
@daveyhu
@daveyhu 20 күн бұрын
Thank you ever so much for this!
@OGLDEV
@OGLDEV 19 күн бұрын
My pleasure!
@CodeX-xyxy
@CodeX-xyxy 20 күн бұрын
when look at openGL vs Vulkan benchmarks unfortunately i cannot see any reason to switch from 100 lines of code to drawing triangle to 1000 lines of code to drawing triangle
@OGLDEV
@OGLDEV 19 күн бұрын
If you don't hit a performance wall with your specific game/app using OpenGL then I guess there is no real motivation to switch to Vulkan. Both Vulkan and DX12 originated from developers telling the HW vendors that they wanted more control over the GPU in order to extract every bit of performance from it.
@CodeX-xyxy
@CodeX-xyxy 19 күн бұрын
@@OGLDEV Thanks for you time sir
@vvgr409
@vvgr409 18 күн бұрын
Comparing Vulkan to OpenGL in terms of "how many lines of code I need to write to render triangle" doesn't make any sense. Sure Vulkan requires a lot of boilerplate to start but that doesn't mean doing everything else will require another hundreds lines of code. In fact when you have triangle with additional few hundreds lines of code you can render models loaded from file with textures and simple lighting.
@hrvatskistakor23
@hrvatskistakor23 20 күн бұрын
Thank you for all your work. Your entire channel is consistent with good learning content. Vulkan is really hard for me to focus on when trying to read about it, don't even want to mention digging through examples, even though i find them easier to navigate recently. Having it explained in the video format really helps a lot. The more detail the better...💪💪💪
@OGLDEV
@OGLDEV 19 күн бұрын
Happy to hear that!
@AttaKru
@AttaKru 20 күн бұрын
great explanation, i like that you come from OGL and base the VK explanation on top of that ... i can't imagine how one learns starting from VK
@OGLDEV
@OGLDEV 19 күн бұрын
Thanks :-) Maybe I need to call this series 'Vulkan For OpenGL developers'...
@OGLDEV
@OGLDEV 20 күн бұрын
Clone the sources: git clone --recurse-submodules github.com/emeiri/ogldev.git If you want to get the same version that was used in the video you can checkout the tag 'VULKAN_08'. Build on Windows: Open the Visual Studio solution: ogldev\Windows\ogldev_vs_2022\ogldev_vs_2022.sln Build the project 'Vulkan\Tutorials\Tutorial08'
@Brmngm
@Brmngm 20 күн бұрын
You could use atan2(x,y) to get angle in a range from -п to п without need to check quadrants.
@OGLDEV
@OGLDEV 16 күн бұрын
Thanks for the feedback! I updated the code with your suggestion. Notice that I only did it in the newer Common/ogldev_basic_glfw_camera.cpp which is what I'm using right now and not in all the local copies of camera.cpp in the preceding tutorials before I switched to GLFW.
@ducroit
@ducroit 20 күн бұрын
Hi, I encountered some run errors with tutorials 31 to 32 (piking), 34 to 38 (shadow) and 40(Skeletal animation). The tutorial 33(sprite) is run fine. First I had the error of the texture2D function at line 319 and 513 in lighting_new.fs, I saw that the function is deprecated, so I put the texture function instead. "Error compiling '../Common/Shaders/lighting_new.fs': '0:319(21): error: no function with name 'texture2D' 0:319(21): error: type mismatch 0:319(21): error: operands to arithmetic operators must be numeric 0:513(19): error: no function with name 'texture2D' 0:513(19): error: operands to arithmetic operators must be numeric 0:518(40): warning: `TempColor' used uninitialized" As a result, I had the error with EdgeDistance0 in lighting_new.fs: "Error linking shader program: 'error: vertex shader output `EdgeDistance0' specifies no interpolation qualifier, but fragment shader input specifies noperspective interpolation qualifier" While trying to remove the noperspective qualification, I had the following error : "!!! Debug callback !!! Debug message: id 1, GL_INVALID_OPERATION in glDrawElements Message source: API Error type: Error Severity: High" I don’t know if the error is from my opengl (4.6) and glfw(3.3.6) versions. Could you please try to check out on your side?
@OGLDEV
@OGLDEV 19 күн бұрын
I added the missing 'noperspective' to all the vertex shaders where it was missing and replaced texture2D with texture. Please let me know if you still have problems with any of these tutorials. Thanks for the feedback!
@ducroit
@ducroit 19 күн бұрын
@@OGLDEV Thank you for responding so quickly! But I still have problems when I try to run these tutorials after pull your update : "Invalid shader program: 'active samplers with a different type refer to the same texture image unit' Warning! Unable to get the location of uniform 'gWireframeColor' !!! Debug callback !!! Debug message: id 1, GL_INVALID_OPERATION in glDrawElements Message source: API Error type: Error Severity: High"
@OGLDEV
@OGLDEV 18 күн бұрын
I pushed a fix to the 'active samplers...' error. Let's see if it improves something.
@ducroit
@ducroit 17 күн бұрын
@@OGLDEV Everything works now! Thank you very much, I learned a lot with your tutorials.
@OGLDEV
@OGLDEV 17 күн бұрын
Glad to hear!
@hasanshafy_
@hasanshafy_ 21 күн бұрын
I'm getting quite a lot of errors after trying to build from your repository. I've installed everything according to the video, although I'm using Git instead of Tortoise Git, I reckon that shouldn't be a problem. Cannot open include file: '3rdparty/meshoptimizer/src/meshoptimizer.h': No such file or directory Tutorial45, few Vulkan errors as well.
@OGLDEV
@OGLDEV 19 күн бұрын
Please check question #7 on ogldev.org/faq.html. Let me know if anything is missing.
@hasanshafy_
@hasanshafy_ 19 күн бұрын
@@OGLDEV Thank you. Will get back If I can't fix it.
@tematoscybersage5626
@tematoscybersage5626 22 күн бұрын
Thank you. Wooooah, I tried to use ftgl lib which looks like pretty similar, but it just won't to read lib definitions, I think it is just too old. Is it possible to generate vertices from fonts with that library to generate 3D volumetric fonts?
@OGLDEV
@OGLDEV 19 күн бұрын
You mean with the FreetypeGL library? I don't think you can generate vertices from fonts with that. AFAIK the standard font files are only 2D. If you need a 3D fonts then I guess you need a model for each letter and then render it as usual. I'm pretty sure that someone already modeled most languages and you can simply re-use this work.
@tematoscybersage5626
@tematoscybersage5626 19 күн бұрын
​@@OGLDEV Yep, that one that you used. Thank you. I wasn't able to find similar lib yet. And I was surprised about that, pretty generic feature. Also on Khronos site I saw on page where they show libs for text rendering, that with some of libs they generate 3D text(I can't attach links here). Maybe this library encapsulates some functionality of FreeType for this task. I think the process of making 3D text from fonts should be next: 1) filter edges of letter. 2) make it vertices that forms plane of letter(and optimize it ammount). 3) duplicate this plane and flip to 3.14 rads and join both planes with perpendicular faces. 4) and then pack this all in vertex buffer and render as normal 3D model.
@OGLDEV
@OGLDEV 19 күн бұрын
I would place the font image as a background picture in Blender and simply model it in 2D and then extend it backward to create the 3D volume. Can't tell which method is preferable. Highly depends on how much time you spend developing that algorithm.
@tematoscybersage5626
@tematoscybersage5626 19 күн бұрын
​@@OGLDEV yep, I think you right. no sense to spend so much time on it if there is not so much need. I think I will be using this freetypeGL lib to put 2d text notes, to explain something in 3D scenes, projecting rectangle with this text texture. Yeah, much easier to make some kind of 3D askii table of letters and signs, and pick up needed one by interpreting chars, to render 3D text. Thank you)
@miumpre2839
@miumpre2839 22 күн бұрын
Wow total shadow tech video is very good!! I have two question. first flexible bias equation is not consider texSize and not linear so i think it was to be "bias = sin(acos(NDL))*texSize" is it right?? but this equation may be heavy.. :( second your coord and vector plot in blue slide is very efficient to read can i get a name of program for make this?
@OGLDEV
@OGLDEV 15 күн бұрын
Thanks! Not sure I understand the equation with texSize. Perhaps you can share more details. Regarding the second equestion - I usually create my slides using Google docs. Which specific blue slide are you referring to?
@MrMariozzz78
@MrMariozzz78 23 күн бұрын
can i use freeglut with opengl 2.0 o more with glsl language? o it work just with glfw?
@OGLDEV
@OGLDEV 19 күн бұрын
Sure, FreeGLUT supports all versions of OpenGL.
@MrMariozzz78
@MrMariozzz78 19 күн бұрын
@@OGLDEV i need Glew o glad too or glut is enough?
@OGLDEV
@OGLDEV 19 күн бұрын
You need either GLEW or GLAD to load the functions pointers. I'm using GLEW. People who follow learnopengl.com usually go with GLAD because this is what the website is using.
@MrMariozzz78
@MrMariozzz78 19 күн бұрын
@@OGLDEV ok thank ,but i don't know how istall glad on codeblock it generata many version of opengl on website
@OGLDEV
@OGLDEV 19 күн бұрын
Hopefully you can find an answer on learnopengl.com or on one of the forums. I've never tried to use GLAD myself. Was always happy using GLEW so I never tried an alternative.
@AttaKru
@AttaKru 23 күн бұрын
I love it, so there are two animation to blend between. This helps the transition between two animations. But how is it called when two animations are played together. Like the character is running, but the upper body is playing a full sword swinging animation. Isn't that the blending? And what you implemented is called animation transitioning? Sorry, this is just hair splitting. Thanks for the great, well explained content!
@OGLDEV
@OGLDEV 19 күн бұрын
You're welcome! Transitioning a set of vertices from being animated using one set of transformations to another is called blending because you need to smoothly switch from one matrix to another. If your model was constructed so that different parts have different sets of animations and you can freely mix and match between them then this is standard animation with the additional management complexity of allowing the user to specify the animation for each part. But as long as you don't need to do anything mathematically to get this to work you are still in standard animation land.
@AHsiao112
@AHsiao112 24 күн бұрын
Your tutorials are top-notch. It's a shame I only just found your channel.
@OGLDEV
@OGLDEV 24 күн бұрын
Better late than never - glad to have you on board :-)
@ekshalibur
@ekshalibur 24 күн бұрын
thanks for the video, this should be a good fit for a compute shader :)
@OGLDEV
@OGLDEV 24 күн бұрын
This is what people keep telling me. I guess I need to make a video about it...
@jefferyduncan162
@jefferyduncan162 25 күн бұрын
Probably going to be a silly question but, I’m trying to implement fog post lighting with deferred rendering. How can i set the clear color to be the same color as the fog without it affecting the lighting calculations? If I set the clear color to anything but black it affects the light pass color results.
@OGLDEV
@OGLDEV 19 күн бұрын
The question is definitely not silly it's just that I'm not sure I understood it. Are you implementing fog as a separate pass? Why do you need to change the clear color?
@jefferyduncan162
@jefferyduncan162 19 күн бұрын
@@OGLDEV thanks for responding back. I ended up figuring out the issue sort of and working around it. I’m doing my fog in a separate pass and If the position was equal to 0 (which for some reason it is where no geometry is present), the shader was discarding in those places. I needed to get the fog color to cover those areas since some parts of the map if occluded were showing the clear color. I did a small branch and checked if the position is 0. If so I wrote the fog color and it fixed the empty parts of the map being black instead of being the color of the fog. Screen space reflections up next 😁
@OGLDEV
@OGLDEV 12 күн бұрын
Great!
@thelifelearner5618
@thelifelearner5618 Ай бұрын
can i get this code completely in pdf form
@OGLDEV
@OGLDEV Ай бұрын
Have you tried using one of the online tools to convert code to pdf?
@OGLDEV
@OGLDEV Ай бұрын
Clone the sources: git clone --recurse-submodules github.com/emeiri/ogldev.git If you want to get the same version that was used in the video you can checkout the tag 'TERRAIN13'. Build on Windows: Open the Visual Studio solution: ogldev\Windows\ogldev_vs_2022\ogldev_vs_2022.sln Build the project 'Terrain Rendering\Terrain13'
@OGLDEV
@OGLDEV Ай бұрын
Notes and errata: 1. In the BasicMesh class I accidently reviewed the instanced version of the Render function but instead of the regular (non-instanced version). Both versions are the same from the material perspective.
@Hiraghm
@Hiraghm Ай бұрын
I wish there was a version of this tutorial in C
@OGLDEV
@OGLDEV Ай бұрын
I'm using a very basic version of C++ so changing it to C should not be a problem.
@alexlindgren858
@alexlindgren858 Ай бұрын
I am having trouble understanding how to get around this issue. The problem is when a triangle extends past the view frustum, starting from inside the view frustum, going behind the camera. When doing the perspective projection, the new vertex that is behind the camera gets warped around to the front again which results in the objects behind mirroring in front again. When i made my first 3D renderer, i used the CPU with lists of vertices instead of fixed lengths. So what i would do back then, was to duplicate the vertex behind the camera and project one towards one of the vertices that where in front of the camera, onto the near plane. Then do that again with the other one, projecting it towards the second vertex that where in front of the camera. This arrangement would make a quad that would essentially be the same triangle, but that it was cut by the near plane. Here is where the problem arises, now when i switched from CPU to GPU rendering with OpenGL, I can't find a way to do that again, since i cant add or remove vertices via the vertex shader. Could you help? I wanted to keep the same looks and feel as the old one while being compleatly different under the hood. And also, i might just be bad at maths ,but the formula i use for perspective projection is this simple one which gives the same result as a matrix: float t = cameraDist - cameraZ - v.z; float x_p = (cameraDist * v.x) / t - cameraX; float y_p = (cameraDist * v.y) / t - cameraY;
@OGLDEV
@OGLDEV Ай бұрын
Not sure I fully understood the first problem but this was with a software renderer. Is the problem still happening with OpenGL? The vertex behind the camera should end up being clipped and OpenGL should create a quad or whatever from what remains inside the frustum. It's possible that you don't really need to provide a solution with OpenGL. Regarding the projection equation: what is cameraDist and cameraZ? I guess the division by 't' corresponds to the perspective division that we have in OpenGL. If you look at the perspective projection matrix that we develop in the two videos you can see that most of it is zeroes which means that we usually just multiply each component of the vector by one element (except for Z which is a bit more complex). The advantage of the matrix vs your approach is that you can combine it with the world and view matrices into a single matrix.
@alexlindgren858
@alexlindgren858 Ай бұрын
@@OGLDEV because i need to have the projection calculation in the vertex shader to maximize performance, i can't control the number of vertices or create new triangles. The divisor 't' is the Z distance from the camera to the vertex, cameraZ is the Z coordiante of the camera, and cameraDist is the "FOV" of the camera, but in a weird way. Think of a pyramid representing the view frustum, the base would be the size of the window and the tip of the pyramid would be the origin of the camera, the height of the pyramid is cameraDist, so if i would want 90 degrees FOV, i would set cameraDist to be half the width of the window. So when a vertex that is behind the origin of the camera is projected, it now gets inverted due to t being negative, a similar thing happens if you write 1 / x in a graphing calculator, where x corresponds to t. The problem i tried to explain was that if i had a large triangle passing over the t = 0 plane, the resulting projection would be warped. The solution would be to either chop the triangle to a quad or to remove the triangle completely, Which is impossible to do inside the vertex shader. So how would that normally be fixed?
@alexlindgren858
@alexlindgren858 Ай бұрын
if you are wondering, here is my vertex shader: #version 330 core uniform float matrix[6]; uniform vec3 translate; uniform float renderdist; uniform float minrenderdist; uniform vec3 camera; uniform float cameradist; uniform vec2 size; uniform int prioaxis; // Input vertex attributes layout(location = 0) in vec3 position; // Position attribute layout(location = 1) in vec4 color; vec3 rotate(vec3 v) { float nx; float ny; vec3 o; if (prioaxis == 0) { // Y o = vec3(matrix[3] * v.x + matrix[2] * v.z, v.y, matrix[3] * v.z - matrix[2] * v.x); // Z nx = matrix[5] * o.x - matrix[4] * o.y; o.y = matrix[4] * o.x + matrix[5] * o.y; o.x = nx; // X ny = matrix[1] * o.y - matrix[0] * o.z; o.z = matrix[0] * o.y + matrix[1] * o.z; o.y = ny; } else if (prioaxis == 1) { // Z o = vec3(matrix[5] * v.x - matrix[4] * v.y, matrix[4] * v.x + matrix[5] * v.y, v.z); // X ny = matrix[1] * o.y - matrix[0] * o.z; o.z = matrix[0] * o.y + matrix[1] * o.z; o.y = ny; // Y nx = matrix[3] * o.x + matrix[2] * o.z; o.z = matrix[3] * o.z - matrix[2] * o.x; o.x = nx; } else { // X o = vec3(v.x, matrix[1] * v.y - matrix[0] * v.z, matrix[0] * v.y + matrix[1] * v.z); // Y nx = matrix[3] * o.x + matrix[2] * o.z; o.z = matrix[3] * o.z - matrix[2] * o.x; o.x = nx; // Z nx = matrix[5] * o.x - matrix[4] * o.y; o.y = matrix[4] * o.x + matrix[5] * o.y; o.x = nx; } return o; } vec2 project(vec3 v) { float t = cameradist - camera.z - v.z; if (t > minrenderdist) { float x1 = ((cameradist * v.x) / t) - camera.x; float y1 = ((cameradist * v.y) / t) - camera.y; return vec2(x1 / size.x, y1 / size.y); } else { return vec2(0.0, 0.0); } } out vec4 col; void main() { vec3 rotated = rotate(position + translate); vec2 projected = project(rotated); float t = cameradist - camera.z - rotated.z; gl_Position = vec4(projected, 1.0 - 1.0 / t, 1.0); col = color; }
@OGLDEV
@OGLDEV Ай бұрын
Your method seems highly unorthodox. You should transform the vertex to view space and then the camera is at the origin so you don't need to subtract cameraZ from anything. In the vertex shader we usually combine all the transformations together into a single matrix (WVP) and then you don't need all the calculations in your shader below. The projection matrix provides a simple solution for the FOV so it doesn't have to be weird. Everything between the near and far clip plane will be mapped to (-1,1) and everything outside of that range should be handled correctly by the clipper. The vertex shader is indeed not the place to add or remove vertices. The clipper does that for you in screen space.
@alexlindgren858
@alexlindgren858 29 күн бұрын
@@OGLDEV I re-implemented the perspective and rotation matrices to be the same as your implementation, but i keep getting stuck when the triangles just start flickering and popping in and out of existence when rotating, the translation matrix dossen't work as expected either. I have the same order of matrices "perspective * translation * rotation * vec4(position, 1.0);". what i also found was that if i force the w component to be 1.0, it stops flickering but i loose all sense of depth, what could be going on? theese are the matrices i am currently using: float d = 1.0f / (float) Math.tan(FOV / 2.0f); float[] perspective = new float[]{ d, 0.0f, 0.0f, 0.0f, 0.0f, d, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }; float[] translation = new float[]{ 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; float[] rotation = new float[]{ cosA, 0.0f, -sinA, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, sinA, 0.0f, cosA, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f };
@kaiweiyeo4279
@kaiweiyeo4279 Ай бұрын
Hi Etay, I managed to compile the code but there's something odd. The other inputs are correct since it's moving the camera, not the cube. PROBLEM: However, the key 'D' can be pressed for input, even though it's not a case in the switch statement.
@OGLDEV
@OGLDEV Ай бұрын
Thanks for the bug report. Turns out that I'm handing the special keys (arrows) in a function registered for the regular keys using glutKeyboardFunc. I should have registered a different callback using glutSpecialFunc and handle the arrows there. The code for 'D' is 0x64 which is used for GLUT_KEY_LEFT and this is causing the confusion.
@kaiweiyeo4279
@kaiweiyeo4279 Ай бұрын
Hi Etay, Thanks for the tutorials. PROBLEM: I ran into a strange error C2065 'M_PI': undeclared identifier. I think there is a conflict over what is M_PI in corecrt_math_defines.h (Microsoft file). SOLUTION: The solution was quite simple. Just "#define M_PI 3.14159265358979323846" in ogldev_math_3d.h just above ToRadians(x)
@OGLDEV
@OGLDEV Ай бұрын
I define _USE_MATH_DEFINES in the preprocessor config of every project which should solve this. For more details see learn.microsoft.com/en-us/cpp/c-runtime-library/math-constants?view=msvc-170 Perhaps you are building the 'release' build? I only maintain the 'debug' build.
@Brmngm
@Brmngm Ай бұрын
Lecture on a simple topic: Drawing a triangle in OpenGl, but with important extra: order of vertices and normals. Thank you sir!
@OGLDEV
@OGLDEV Ай бұрын
You are most welcome!
@miumpre2839
@miumpre2839 Ай бұрын
Very good info and explanation! thanks
@OGLDEV
@OGLDEV Ай бұрын
You're welcome :-)
@yoonhakim2455
@yoonhakim2455 Ай бұрын
Hi, I noticed that the name of drawing function got changed. In the last video it was glDrawElementsBaseVertex. Does it have something to do with adding materials and lighting? or perhaps I'm just distracted by irrelevant stuff?
@OGLDEV
@OGLDEV Ай бұрын
Wow! the video is more than two years old but because of your comment I now see that I used the wrong version of the Render function for the code review... The version in the video is for the instanced case (even though I haven't done a tutorial on instancing...) which is why glDrawElementsInstancedBaseVertex is used instead of the regular glDrawElementsBaseVertex. The file has changed a lot since then but you can simply take a look at the render function in 527 to see what I was supposed to review. The material stuff is basically the same in both versions so no problem. Thanks!
@twenty-fifth420
@twenty-fifth420 Ай бұрын
>Me talking to holographic spock during my Kobayashi Maru. “Spock, it is simple science. This is simply illogical for Vulkan! It is a no win scenario! You can’t just pass a triangle to a circle and make it work Mr Spock!” “Indeed Captain, for this test, you must somehow win the Kobayashi Maru by putting this red triangle in that blue circle hole.” “Bogus Mr Spock! It has never been done even for the highest of Vulkan wizards!” 🤨 🖖”Then I guess you will be the first to try Captain.”
@OGLDEV
@OGLDEV Ай бұрын
Shakespeare!
@samgilk5693
@samgilk5693 Ай бұрын
I'm finding that the function GetBoneTransformsBlended is very slow. I am getting ~30fps running blended animations on this model. Is that expected? Any thoughts on speeding this up?
@OGLDEV
@OGLDEV Ай бұрын
This function (and the entire class) is highly unoptimized. I consider it a reference in order to explain how animation works using Assimp. I'm sure the performance can be greatly improved. I would start by measuring and pinpointing the specific bottlenecks. This is usually the best strategy in order to avoid spending time on things that "feel" problematic but end up not affecting much of the performance. That being said, just from the top of my head I can see several functions that serially search for a matching node name which is a string comparison. You can replace the name with an index and then access the required slot directly. In addition, the algorithm handles the three transformations in the same way but you can skip a transformation if you know a-priori that it is not really part of the animation. For example, if you know that the scaling doesn't change you can ignore it entirely. These are just two quick ideas and I'm sure there are many others.
@samgilk5693
@samgilk5693 Ай бұрын
@@OGLDEV Thank you for the tips! Just using a simpler model drastically improved the performance as well.
@OGLDEV
@OGLDEV Ай бұрын
Great!
@yoonhakim2455
@yoonhakim2455 Ай бұрын
Is the positive rotation direction dependent on what coordinate system you choose? I got confused when you go 90 degrees clockwise at 15:55.
@OGLDEV
@OGLDEV Ай бұрын
Yes, it is. In a left handed coordinate system the positive direction is clockwise and in a right handed system it is counter clockwise. See more details here: butterflyofdream.wordpress.com/2016/07/05/converting-rotation-matrices-of-left-handed-coordinate-system/
@LumenBrewer
@LumenBrewer Ай бұрын
14:47 This is where I have problems. I do not know how to correctly input my path to the different directories.
@OGLDEV
@OGLDEV Ай бұрын
You can use $(SolutionDir) or $(ProjectDir) as the base where the corresponding file exists (the solution file or the project file, respectively) and use a relative path from there. Whenever I run into such problems I often start with the absolute path (which is easier) and then change it into a relative path (which is more generic).
@Werhakon
@Werhakon Ай бұрын
Note 6:07 , I had an issue where my triangle would just not do anything when building the program, and I found that it was because Scale and Delta were both of native type float, while I managed to get it working when initializing these as GLfloat instead. I was using glsl #version 460, so I'm guessing that might be why. (#version 330 wouldnt work on my end)
@OGLDEV
@OGLDEV Ай бұрын
That's weird because GLfloat should be a typedef of float. What platform is this? Can you please print sizeof(GLfloat) and sizeof(float)?
@Werhakon
@Werhakon Ай бұрын
@@OGLDEV Ignore this actually, just tried switching them back to regular float and it worked instantly. Might've been something else I did at the time that I didn't catch. Sorry about that !
@OGLDEV
@OGLDEV Ай бұрын
No problem, glad to hear it is working.
@yoonhakim2455
@yoonhakim2455 Ай бұрын
Hello. Could you explain what 0 means in HasTextureCoords(0)? and how we are able to do mTextureCoords[0][i]? I looked at the documentation and it showed that mTextureCoords is a one dimension array.
@OGLDEV
@OGLDEV Ай бұрын
The vertex may include zero or more (current maximum is 8) texture attributes. You need to call HasTextureCoords with the index of the coordinates and it will tell you whether it exists. I would have preferred an API that tells you how many tex coords exist but this is how it works. I'm only interested in the first set so I pass in zero. mTextureCoords is indeed one dimensional array but of pointers which means that every element in the array is the base of a different array. So the first index is zero for the first set of coords and the second index is 'I' for the coords of the current vertex.
@yoonhakim2455
@yoonhakim2455 Ай бұрын
@@OGLDEV Now I get it thank you. Just one more thing, do you still have the source code from the video? I looked at your github page but I couldn't find one.
@OGLDEV
@OGLDEV Ай бұрын
The source code is here: github.com/emeiri/ogldev/tree/master/tutorial18_youtube. If you want to get the same version that was used in the video (the master branch contains many changes) checkout the tag TUT_18_ASSIMP.
@yoonhakim2455
@yoonhakim2455 Ай бұрын
@@OGLDEV Thank you. your videos are awesome.
@OGLDEV
@OGLDEV Ай бұрын
Thanks!