Vertex Formats and Vertex Buffers - 3D Games in GameMaker

Поділитися
Вставка
  • Опубліковано 12 лис 2024

КОМЕНТАРІ • 120

  • @DragoniteSpam
    @DragoniteSpam  2 роки тому +2

    3:43 The other super important aspect of triangles when it comes to 3D rendering is that, for any triangle, you can guarantee that there is exactly one plane in 3D space that passes through its three vertices. This is not necessarily the case if you have four or more points in space.

  • @pondwithducks3092
    @pondwithducks3092 3 роки тому +28

    this playlist is the holy grail of GMS tutorials, thank you

  • @NØll-Media
    @NØll-Media 3 роки тому +17

    Here is the updated vertex_add_point script for GMS 2.3
    /// @param vbuffer
    /// @param xx
    /// @param yy
    /// @param zz
    /// @param nx
    /// @param ny
    /// @param nz
    /// @param utex
    /// @param vtex
    /// @param color
    /// @param alpha
    function vertex_add_point(argument0, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10) {
    var vbuffer = argument0;
    var xx = argument1;
    var yy = argument2;
    var zz = argument3;
    var nx = argument4;
    var ny = argument5;
    var nz = argument6;
    var utex = argument7;
    var vtex = argument8;
    var color = argument9;
    var alpha = argument10;
    // Collapse four function calls into a single one
    vertex_position_3d(vbuffer, xx, yy, zz);
    vertex_normal(vbuffer, nx, ny, nz);
    vertex_texcoord(vbuffer, utex, vtex);
    vertex_color(vbuffer, color, alpha);
    }

    • @AugustHero97
      @AugustHero97 3 роки тому +2

      Savior, give this man a prize

    • @Loneway
      @Loneway 3 роки тому +3

      Thank you sir !

    • @jewfinigan863
      @jewfinigan863 2 роки тому

      This is what worked for me:
      /// @param vbuffer
      /// @param xx
      /// @param yy
      /// @param zz
      /// @param nx
      /// @param ny
      /// @param nz
      /// @param utex
      /// @param vtex
      /// @param color
      /// @param alpha
      function vertex_add_point(vbuffer, xx, yy, zz, nx, ny, nz, utex, vtex, color, alpha) {
      // Collapse four function calls into a single one
      vertex_position_3d(vbuffer, xx, yy, zz);
      vertex_normal(vbuffer, nx, ny, nz);
      vertex_texcoord(vbuffer, utex, vtex);
      vertex_color(vbuffer, color, alpha);
      }

    • @moshimooshi
      @moshimooshi Рік тому +2

      marry me

    • @St3fa9s
      @St3fa9s 9 місяців тому

      you cured my depression, thank you.

  • @Kazak29
    @Kazak29 2 роки тому +4

    For anyone messing around with this code, do not repeat my mistake: the order at which you set vertex format parameters and the order at which you apply these parameters to vertex buffers must be identical. These functions are very sensitive to this.
    I accidently swapped vertex_format_add_texcoord with vertex_format_add_color without thinking and kept wondering afterwards why all my tiles suddenly lost their texture and became blue.

    • @bru57000
      @bru57000 12 днів тому

      yeah, at 6:15 he was confused. The idea behind this is that the API of the engine is working like a state machine. The format has been defined in this specific order, and the vertex buffer must match the format. OpenGL is working the same way.

  • @mayathemaster
    @mayathemaster 4 роки тому +4

    Great work. Cant wait to see the series go further into computer graphics.

  • @scutimania9248
    @scutimania9248 4 роки тому +7

    this guy is the sonic of typing

  • @Jalecko
    @Jalecko 4 роки тому +1

    this is great, i used to watch your 3d tutorials from back in 2016

  • @karlstenator
    @karlstenator 3 роки тому +1

    Howdy Michael, and happy new year!!
    I've watched this video a couple of times now. The first time was for your sense of humour, the second time was also for your sense of humour. The third time, which is now, was coming back after having a crack at using primitives as an alternative for creating vertex graphics; for example;
    //Object Draw event;
    var matrix = matrix_build(x,y,0,0,0,image_angle,1,1,1)
    matrix_set(matrix_world,matrix);
    draw_primitive_begin(pr_trianglefan);
    draw_vertex_color(400,400,c_black,1);
    draw_vertex_color(400,600,c_black,1);
    draw_vertex_color(600,600,c_black,1);
    draw_primitive_end();
    matrix_set(matrix_world, matrix_build_identity());
    The above is far simpler to code 2D shapes (less command overhead), but yet somewhat similar to what you've detailed in your video - but I'm guess at the cost of frame rate?
    Would creating graphics with primitives/matrix be far slower compared to what you've just described in this video? And can you think of any advantages/disadvantages to either or method?
    As I have my project working using primitive graphics, I can't help but notice that with roughly 100 objects the frame rate starts to drop with each new object added... (although I am also pushing the vertex data into generating 2D fixtures for Box Physics collision too, so this might also have something to do with it, guess I need to isolate the primitive drawing method vs your vertex buffer drawing method and compare performance).

    • @DragoniteSpam
      @DragoniteSpam  3 роки тому +1

      It would be about as fast either way (beginning or ending a primitive incurs a batch break, as do the matrix functions, which are especially slow) but saving the vertex data to a vertex buffer allows you to reuse them more easily - so you can work faster - and saves you the trouble of having to define every vertex every single time you try to draw something, which isn't really a problem for a single triangle but adds up quickly for larger objects.
      If you need the vertex data to change on the fly - if the physics system is allowed to deform it, for example - then you might be better off using the draw_primitive functions, though. If you just need to generate the fixtures from the vertex positions, you can probably get away with just doing that in the Create event.

  • @seditt5146
    @seditt5146 4 роки тому +2

    Point List is great for Particles and things of that nature. You can enlarge the point size in the shader which would give you the equivalent of a bunch of small quads yet they can be drawn with nothing more than a single point.

    • @seditt5146
      @seditt5146 3 роки тому

      @Jaxon Valentino You....

    • @seditt5146
      @seditt5146 3 роки тому

      @@dustincash414 And you....

  • @larryteslaspacexboringlawr739
    @larryteslaspacexboringlawr739 4 роки тому +7

    i guess now with all this self isolation i should work on my much neglected game

  • @euanraagas3005
    @euanraagas3005 4 роки тому +8

    for when your writing the script i have done the same thing as what you did but it says that the" vertex_position_3d (vbuffer, xx, yy, zz,);" is undefined why is that? at 12:25

    • @St3fa9s
      @St3fa9s 9 місяців тому

      i'm also having that problem

    • @superstinkybeans
      @superstinkybeans 8 місяців тому

      same for me, its pulling the error from xx saying it's undefined and expecting a number even though the script isn't even being called

    • @superstinkybeans
      @superstinkybeans 8 місяців тому

      I just fixed it, instead of creating parameters using '/// @param' , I put 'function vertex_add_point([11 arguments])' into the top of the script and put all the code in braces.

  • @aritelford3160
    @aritelford3160 4 роки тому

    Amazing tutorial! Truly underrated channel

  • @magicdweedoo
    @magicdweedoo 3 роки тому +1

    hey thanks so much for doing these tutorials my man, learning a lot

  • @bru57000
    @bru57000 12 днів тому

    6:15 I think the vertex_format_end() returning the ID makes sense instead of vertex_format_start(). When you come form hardcore code in OpenGL world (and more obviously from fixed function pipeline), the API of the graphical engine is working like a state machine. The actual ID is returned upon completion of the state machine, when you reach the end state. If the ID was created earlier, then the ID would point to a structure that is in an inconsistent state (i.e. not fully defined). Imagine what could happen if you use this ID before it is actually defined with all the vertices, colors, texture coords.

  • @betatester03
    @betatester03 4 роки тому

    Just discovered your channel. Very good stuff. Eagerly awaiting future content.

  • @kaspiannilsen646
    @kaspiannilsen646 4 роки тому

    Really good and thorough explanations. Love it!

  • @PrimitiveAspid
    @PrimitiveAspid 2 роки тому +2

    The triangles won't draw

  • @subjectnamehere-
    @subjectnamehere- 3 місяці тому

    If your triangle isn't being drawn:
    It's POSSIBLY to do with the camera being in the wrong place.
    To fix this, replace the camera_set_view_mat script in the draw event with this:
    camera_set_view_mat(camera, matrix_build_lookat(0, 0, 400, room_width, room_height, 0, 0, 0, -1));
    i'd have explained it more but i'm not the best at wording stuff.

    • @lazyursidae
      @lazyursidae Місяць тому

      well that fixed my issue! thanks kind stranger

  • @Polytricity
    @Polytricity 3 роки тому

    Awesome stuff, super clear too!

  • @Thepinkshark115
    @Thepinkshark115 4 місяці тому

    Herro! Started getting into this series and had the same problem with getting the error. ERROR in action number 1 of create event for object : vertex position 3d argument 1 incorrect type (undefined) expecting a vertex_buffer etc.

  • @gnarofox5372
    @gnarofox5372 Рік тому +1

    estuve 30 minutos adivinando porque el triangulo no se dibujaba y era que la camara estaba muy baja como para ver el triangulo

  • @superstinkybeans
    @superstinkybeans Місяць тому

    My floor and player textures are drawing fine, but when I do a shadow and an enemy the texture is drawing the specified sprite, then a strip of sprites. I'm doing the same vertex_submit with sprite_get_texture for them so I don't know why this is happening
    I saw a reddit post saying it has something to do with VRAM?

    • @DragoniteSpam
      @DragoniteSpam  Місяць тому

      usually this happens if some or all of your texture pages aren't on their own texture page when they should be

  • @christinehaylett4181
    @christinehaylett4181 2 роки тому

    Is there a follow up video on zbuffer/depth ?, could really use it please.

  • @KaziiTheAvali_inactive
    @KaziiTheAvali_inactive 3 роки тому

    the cool thing for gms2 is that all you have to do is middle click to find out what somthing is. when i dont know what a code does i middle click it and it gives me stuff about it

  • @asbestositgets1104
    @asbestositgets1104 4 роки тому +1

    Awesome video it was extremely helpful, but is there any way that I can rotate my vertices around a point to make a rotating triangle?

  • @Jojokesuke
    @Jojokesuke 4 роки тому

    following this tutorial make me wanna remake Kirby's Dream Course

  • @ozmainia9210
    @ozmainia9210 3 роки тому +1

    I'm so confused? I've checked my code against the video however when I run the game the triangle never appears? Any idea what could have gone wrong? The Camera shows the same it's just the triangles that don't appear?

    • @pikuhana
      @pikuhana 3 роки тому +4

      I figured it out, you need to change the camera objects draw function. Inside the draw function make sure that in camera_set_view_mat, the matrix has 400 as the 3rd entry

    • @Pedro-S1lva
      @Pedro-S1lva 2 роки тому +1

      @@pikuhana hero,it works,thanks

    • @strifestrives5454
      @strifestrives5454 2 роки тому

      @@pikuhana THANKS, boy I was so confused

    • @strifestrives5454
      @strifestrives5454 2 роки тому

      @Clown Triangle was being drawn out of view, so changing the perspective puts it in view

  • @doc838
    @doc838 2 роки тому

    question and what to write in the script on the new version of the engine

    • @DragoniteSpam
      @DragoniteSpam  2 роки тому

      ua-cam.com/video/n8-MuIuOQFE/v-deo.html

  • @jennjennjenn61992
    @jennjennjenn61992 Рік тому

    what to do if I followed code exactly and no triangle appears?

    • @DragoniteSpam
      @DragoniteSpam  Рік тому +1

      Check the example project

    • @jennjennjenn61992
      @jennjennjenn61992 Рік тому

      @@DragoniteSpam when I downloaded the example project it gave me a blue and white checkered ground, which I think is the next video

  • @GCMillhouseTVOld
    @GCMillhouseTVOld 5 місяців тому

    15:11 done the same thing but Triangle doesn't appear

  • @fourriversfarm
    @fourriversfarm 4 роки тому +2

    Do you know when the next part will be published? Id really love to see how to use the texcoord and normal formats! :D

    • @DragoniteSpam
      @DragoniteSpam  4 роки тому +4

      Probably next week.

    • @fourriversfarm
      @fourriversfarm 4 роки тому

      @@DragoniteSpam Cool, any resources you can link me to that would help me set up texcoord? Id really love to render these flowers in my scene lol

    • @DragoniteSpam
      @DragoniteSpam  4 роки тому +1

      @@fourriversfarm For UV mapping in general, this video looks pretty decent: ua-cam.com/video/dj0uXid9oGo/v-deo.html
      I also made this a few years ago: ua-cam.com/video/ajl3l0gu34k/v-deo.html
      Other than that, just opening a model in Blender or Game Maker Model Creator and fiddling with the texture UVs could be pretty useful, you'll get a feel for how textures wrap around the faces that way.

    • @fourriversfarm
      @fourriversfarm 4 роки тому

      @@DragoniteSpam Great! Thank you

    • @DragoniteSpam
      @DragoniteSpam  4 роки тому +1

      @@fourriversfarm Have fun!

  • @mimithinks7
    @mimithinks7 3 роки тому

    I was tired trying to write everything down so I could format my own code as I get better but then I kept misspelling everything until my Bluetooth decided to let me know they are dying and man am I awake now... And sleep send help

  • @joelamaster7200
    @joelamaster7200 2 роки тому

    For some reason there is an error on vertex_add_point script on line 25 saying it is expecting a number. Any help?

    • @PASSARU
      @PASSARU 2 роки тому +1

      This was pre-2.3, you need to define the script contents in functions now

    • @joelamaster7200
      @joelamaster7200 2 роки тому +1

      @@PASSARU okay thanks

  • @zeldwaugh5703
    @zeldwaugh5703 3 роки тому

    How are fps? I have a GTX 1080. What do you think fps would be like with 20k plus triangles with pos, text, color, and normals? Just basically wondering how fast the vertex buffers actually are for the quality of texturing etc.

    • @DragoniteSpam
      @DragoniteSpam  3 роки тому +1

      Depends on how you draw them. Generally speaking, 20k triangles is nothing, but if you draw them one-by-one it'll be much slower than drawing them all in the same vertex buffer.

  • @spiritlamp6324
    @spiritlamp6324 4 роки тому

    Very helpful! But is there a way to make the vertex drawings on other objects? I tried this and it didn't work.

  • @SuperNintomdo
    @SuperNintomdo 4 роки тому

    Towards the end of the video you talk about method to make sure the camera is done first by either setting it to a high depth or your other work around by calling from the objects. Is there a reason you don't just apply the camera in the draw begin step? Then everything in the regular draw step could just be done normally right?

    • @DragoniteSpam
      @DragoniteSpam  4 роки тому +2

      As far as I know that should work too, I just like having it in the same event as the rest of the draw code. I usually like to loop through objects in the camera's draw event instead of letting them draw themselves since you get more control over things that way.

    • @SuperNintomdo
      @SuperNintomdo 4 роки тому +1

      @@DragoniteSpam makes sense. Thanks.

  • @GameMakerRob
    @GameMakerRob 3 роки тому

    I was checking out the manual entry for vertex_normal and I don't understand what it means by "The above code will set the surface normal of the vertex being defined." What does surface normal mean? I'm up to 9:59 in the video and I started watching from the part about depth-sorting. I'm looking to use vertex buffers for isometric games.

    • @DragoniteSpam
      @DragoniteSpam  3 роки тому

      Normals come into play when you start doing 3D lighting: ua-cam.com/video/mspdUDlVEXI/v-deo.html
      If you don't need that don't worry about it (you can either set it to all 0s, or get rid of completely).

    • @GameMakerRob
      @GameMakerRob 3 роки тому

      @@DragoniteSpam So "surface normal" relates to 3D lighting?

    • @DragoniteSpam
      @DragoniteSpam  3 роки тому +1

      @@GameMakerRob You can also use them to evaluate physics responses when things collide, but for the most part yes.

    • @GameMakerRob
      @GameMakerRob 3 роки тому

      @@DragoniteSpam OK thank you :)

  • @akshayazariah
    @akshayazariah 4 роки тому

    Unrelated, but can you make an updated series for writing extensions?

    • @DragoniteSpam
      @DragoniteSpam  4 роки тому +1

      I made this one a few years ago on DLLs:
      ua-cam.com/video/jkgMxrDvwPs/v-deo.html
      but GMS1 / 2 changed the extension systems by a fair amount, so revisiting that one might not be a bad idea . . .

  • @plazer2044
    @plazer2044 3 роки тому

    Can one put the vertex creation code on a step event or would that create an infinite amount of vertex or cause some other problem?

    • @DragoniteSpam
      @DragoniteSpam  3 роки тому

      would not recommend doing that in the step event unless you have to, even if you delete them properly when you're finished it could slow the game down if you're generating too much of it

    • @plazer2044
      @plazer2044 3 роки тому

      @@DragoniteSpam Then, What can I do to move the vertex with inputs?

    • @DragoniteSpam
      @DragoniteSpam  3 роки тому

      @@plazer2044 ua-cam.com/video/IeoAzmFdu6k/v-deo.html

  • @beckburns5038
    @beckburns5038 2 роки тому

    I may just be stupid or something but did you define your functions? They’re not working for me and I’m not sure why?

    • @DragoniteSpam
      @DragoniteSpam  2 роки тому

      This was pre-2.3, you need to define the script contents in functions now

  • @Ragnark1
    @Ragnark1 4 роки тому

    Should vertices be entered clockwise or counter-clockwise? I noticed you entered yours in clockwise.

    • @DragoniteSpam
      @DragoniteSpam  4 роки тому

      Generally you see them clockwise, although if you need them to be counterclockwise for whatever reason you can set the culling direction to counterclockwise. Ultimately it's more important that everything in the game is consistent with everything else in the game.

    • @Ragnark1
      @Ragnark1 4 роки тому

      @@DragoniteSpam Okay: Interesting: docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/drawing/gpu/gpu_set_cullmode.html
      I had seen the d3d article and didn't realize it was referring to 1.4.

    • @DragoniteSpam
      @DragoniteSpam  4 роки тому

      @@Ragnark1 Yeah they added the ability to define the culling direction in 2, it's not something that's usually useful but is nice on occasion - if you want to render something inside-out, for example.

    • @Ragnark1
      @Ragnark1 4 роки тому

      @@DragoniteSpam I have been reading tons of material that states that OpenGL's winding order for vertices is actually counter-clockwise. Does GMS have a preference or best-practice?

    • @DragoniteSpam
      @DragoniteSpam  4 роки тому

      @@Ragnark1 Aside from what I mentioned earlier, not really. As far as I'm aware the documentation doesn't prefer one over the other or anything.

  • @hhcdghjjgsdrt235
    @hhcdghjjgsdrt235 4 роки тому

    Ive already switched to unity and learning C#. missing game maker......

    • @sartanko
      @sartanko 4 роки тому +2

      C# seriously breaks my brain.

    • @hhcdghjjgsdrt235
      @hhcdghjjgsdrt235 4 роки тому

      @@sartanko then what about me ? Im a civil engineer.

  • @Lucky_guy508
    @Lucky_guy508 11 місяців тому

    13:30 hey so I wrote this all out but for some reason I keep getting an error saying there is something wrong with line 25 and it’s expected a number in the parentheses bit there is numbers there;-;

  • @zelenqk_brat
    @zelenqk_brat 2 роки тому

    "When you cut a triangle u always end up wih 2 triangles no matter how hard u try" - PFFFFF CAP i just cut them horizontally

  • @ps4ljaska683
    @ps4ljaska683 10 місяців тому

    :DDDD gg

  • @hati3813
    @hati3813 Рік тому

    📝🐀

  • @96isthebestnumber
    @96isthebestnumber 6 місяців тому +1

    ERROR in
    action number 1
    of Create Event
    for object obj_camera:
    vertex_color argument 3 incorrect type (undefined) expecting a Number (YYGF)
    at gml_Script_vertex_add_point_new (line 19) - vertex_color(vbuffer, color, alpha)
    ############################################################################################
    gml_Script_vertex_add_point_new (line 19)
    gml_Object_obj_camera_Create_0 (line 24) - vertex_add_point_new(v_buffer, x1, y1, 100, 0, 0, 1, c_white, 1)
    Also i am using 2023 version maybe its because of this

    • @DragoniteSpam
      @DragoniteSpam  6 місяців тому

      Nope, check your code again

    • @96isthebestnumber
      @96isthebestnumber 5 місяців тому

      @@DragoniteSpam no i reapeted all like in video... also the error is because of vertex_add_point function.

    • @DragoniteSpam
      @DragoniteSpam  5 місяців тому

      @@96isthebestnumber Trust me, you've missed something.