The Endless Grid (re-uploaded)

Поделиться
HTML-код
  • Опубликовано: 13 окт 2024

Комментарии • 23

  • @OGLDEV
    @OGLDEV  4 дня назад +4

    Note: I had to re-upload the video with a different music due to a copyright warning.
    Clone the sources:
    git clone --recurse-submodules github.com/emeiri/ogldev.git
    You can find the shaders here:
    Vertex shader: ogldev/DemoLITION/Framework/Shaders/GL/infinite_grid.vs
    Fragment shader: ogldev/DemoLITION/Framework/Shaders/GL/infinite_grid.fs
    If you want to get the same version that was used in the video you can checkout the tag 'TUT_54_ENDLESS_GRID'.
    Note about the white dots: in the area locked between two horizontal lines the result of 'mod(WorldPos.z, gGridCellSize) / dFdy(WorldPos.z)' is 1 or more which leads to a black color. This is explained in the video. In the area locked between two vertical lines the result of 'mod(WorldPos.x, gGridCellSize) / dFdx(WorldPos.x)' is one or more for the same reason. The dudv vector combines all the derivatives on all directions and components into a single vec2 and using the max2 function on that vector returns the maximum of the two components. This means that along a horizontal line we will get the the result from the X derivative of X and along a vertical line we will get the same with Y. So we end up with a black color on both. Only in the places where they meet we get a zero alpha which leads to white.

    • @nooan79
      @nooan79 2 дня назад

      Great tutorial. I'd like to port this shader to my engine. Where is the fragment shader source in the repo ? I can't seem to find it

    • @OGLDEV
      @OGLDEV  2 дня назад

      Thanks! The fragment shader is here: github.com/emeiri/ogldev/blob/master/DemoLITION/Framework/Shaders/GL/infinite_grid.fs

  • @PGSkep
    @PGSkep 4 дня назад +1

    This looks great, my current implementation has very poor performance as I'm actually using line geometry, I'm going to check this out

  • @coxsj
    @coxsj 4 дня назад

    Great! thanks for sharing! Also + 1 for the historic quote at 12:27!! 😀

    • @OGLDEV
      @OGLDEV  4 дня назад

      You're the first to notice ;-)

    • @coxsj
      @coxsj 4 дня назад

      @@OGLDEV Haha!! I'm sure others will notice too I really appreciate all the effort that goes into your videos and the care you take in walking through your code. It's very helpful. Things like shaders are somewhat opaque for folks like me who are old to programming/c++ but new to graphics programming. Thanks again!!

    • @OGLDEV
      @OGLDEV  4 дня назад

      You're welcome!

  • @aakashs1806
    @aakashs1806 4 дня назад

    Its useful even in cad software

  • @seathleths6595
    @seathleths6595 4 дня назад

    How you draw this without VBO or VAO? I searched across Internet and find nothing about how to draw directly from vertex shader. Everyone say that you must setup some information to shader. So how does it work?

    • @OGLDEV
      @OGLDEV  3 дня назад +1

      This is explained in the video from 1:45 to 3:12... In a nutshell, you can place vertex data in a global array in the vertex shader and access it using a system generated variable called gl_VertexID. This variable is automatically incremented by 1 in every execution of the vertex shader. You just need to call glDrawArrays(GL_TRIANGLES, 0, 6) on the application side to start the process of rendering two triangles. In the vertex shader you need an array with six vertices. This is very useful for techniques that rely on a very specific geometry, for example, a full screen quad. Instead of creating the same vertices in a vertex buffer you put them directly into the vertex shader.

    • @seathleths6595
      @seathleths6595 3 дня назад

      @@OGLDEV Hmmm. Interesting. I don't know why but i did the same things and glDrawArrays draw nothing. Can it depend on hardwhere or this is definitely mistake in code?

    • @OGLDEV
      @OGLDEV  3 дня назад

      It doesn't depend on the hardware. Can be a problem with the winding order (you are viewing the backside of the triangle). You can change the order inside the vertex shader or turn off culling using glDisable(GL_CULL_FACE).

    • @seathleths6595
      @seathleths6595 3 дня назад

      ​​​@@OGLDEV Still doesnt work😅. Well i fixed this. It required to create and bind VAO with no any vertex or inndex data just empty vao, but progam refused to draw anythig without VAO binding. Thanks a lot and exuse me for disturbig.

    • @OGLDEV
      @OGLDEV  3 дня назад +1

      Interesting. This is one point where some drivers allow rendering without a VAO and some don't. But I always thought that this is true when you use a vertex buffer and was not relevant to this technique.

  • @aswinaswin5672
    @aswinaswin5672 4 дня назад

    please please do read this comment and reply.
    i an computer science graduate from india, i every every interested in game development using c++ without game engine like unity or unreal. In youtube i could easily find 2d game tutorial series using sfml and etc. But it is very very difficult to find tutorials for 3d game development with uses openGL or vulkan libraries.
    Please do suggest me where should i start 3d game development. Even if it is an Coursera course, i can affort. Please to say the steps or roadmap for 3d game development. i wanted to make games like gta. please to reply. KIND REQUEST

    • @OGLDEV
      @OGLDEV  4 дня назад +2

      GTA is a Triple-A game created by hundreds of people and a budget of tens of millions of dollars so you need to be careful and set goals that are ambitious, yet reachable. Most of the books out there usually deal with some aspect of game development like graphics, math and physics. If you simply search for "game programming" you can find a few introductory texts that explain how to use OpenGL/DirectX and along the way develop simple games. I actually own a few of these books and they are on my reading list so I can't recommend anything at this point. If you're interested in developing an open world game in the spirit of GTA then I would suggest doing some research and brainstorming (either yourself or with the help of others) about what this means from the point of view of requirements. Ask yourself what kind of problems you will need to solve and then try to solve them in a series of demos that can be combined into a prototype of the actual game. For example, I saw a video once about how they prototyped Uncharted using an extremely basic terrain without any textures because they wanted to develop and test the core movements of the character - jumping, grabbing rocks, etc. For GTA you need to start with some model of the city. Either create it yourself or get it from somewhere. Now you need a camera which follows the character from the back. You can start with a box instead of the character. This will show you the city from the street level. Next you need to handle the collision with the buildings and stuff. How do you tag and identify the different types of objects out there? Unity and Unreal provide various collider objects that take care of that. There are many collision detection algorithms to be explored. Each algorithm is suited for a different context. Next you need to animate the character so you need a rigged model. I have an entire series on skeletal animation that you may want to check. From there you move to NPCs (requires some AI), battles (collision detection again..), etc. Hope this helps. Good luck!

    • @aswinaswin5672
      @aswinaswin5672 3 дня назад +1

      @@OGLDEV Thanks a Lot!

  • @hexcrown2416
    @hexcrown2416 3 дня назад

    Hmm now i kinda want to try making this but using smoothstep instead of the dFdx/y functions since then you should get free AA.

    • @OGLDEV
      @OGLDEV  3 дня назад

      I guess you can do this by calculating the distance from the pixel to the camera. The derivative functions have a nice property where they adapt to the angle between the grid and the view vector.