GLSL Shaders | Coding a 2D Game Engine in Java #8

Sdílet
Vložit
  • čas přidán 7. 06. 2024
  • Join the Discord: / discord
    In this tutorial, I go over how to finalize our shader class so that it can have variables uploaded to it via uniforms. I also go over a little bit about how the GLSL language is formatted, and how the communication between the GPU and the CPU occurs for our shaders. At the end, I show how you could use the shaders to convert an image to black and white, or to use a noise function over the color that we were using.
    Code for this video: github.com/codingminecraft/Ma...
    ---------------------------------------------------------------------
    Website: ambrosiogabe.github.io/
    Github: github.com/ambrosiogabe
    Here are some books I recommend if you want to learn about game engine development more thoroughly. I do not profit off any of these sales, these are just some books that have helped me out :)
    My Recommended Game Engine Books:
    Game Engine Architecture: www.gameenginebook.com/
    Game Physics Cookbook (Read this before the next physics book): www.amazon.com/Game-Physics-C...
    Game Physics (Ian Millington): www.amazon.com/Game-Physics-E...
    Game Programming Patterns (Free): gameprogrammingpatterns.com/
    My Recommended Beginning Game Programming Books:
    JavaScript Game Design: www.apress.com/gp/book/978143...
    My Recommended Java Books:
    Data Structures/Algorithms: www.amazon.com/Data-Structure...
    LWJGL (Free, but I haven't read this thoroughly): lwjglgamedev.gitbooks.io/3d-g...
    Outro Music: www.bensound.com/royalty-free...

Komentáře • 33

  • @greghcarr8192
    @greghcarr8192 Před rokem

    Great tutorial as always. I think this is one of the densest and most instructive graphics courses out there. This is absolutely amazing stuff. I'm learning so much so quickly from this.

  • @c8ff
    @c8ff Před 2 lety +2

    Man, i never really undestood shaders... But with your explanation it's really clear now, i guess i should've watched this series before doing my own game based off a 4 year old tutorial. Thank you!

  • @simonlegtenborg1618
    @simonlegtenborg1618 Před rokem

    You have my respect, this video series is great :)
    A hint to upload the matrices in a nicer way:
    int varLocation = glGetUniformLocation(shaderProgram, varName);
    glUniformMatrix4fv(varLocation, false, mat3.get(new float[9]));

  • @Snowmanver2
    @Snowmanver2 Před 2 lety +1

    I can barely keep up with you at your normal pace, and this time to make things worse you sped it up, hahahah. Thanks for another amazing video, Gabe!
    P.S.: I wonder why your square moves smoothly when you run the program, whereas mine kind of jumps forward, making abrupt jerky motions instead. Would be deeply obliged if you could come up with any suggestions. Thanks in anticipation!

    • @GamesWithGabe
      @GamesWithGabe  Před 2 lety +2

      Thanks An :)
      Also, I'm not sure if I have it fixed at this point in the series, but there is an issue with the way I use the Time.getTime() function. I fix this later in the series, but that may be what's causing it

    • @Snowmanver2
      @Snowmanver2 Před 2 lety

      @@GamesWithGabe thank you for your prompt response! Looking forward to completing the series, cheers!

  • @hyperocket3279
    @hyperocket3279 Před 4 lety +1

    It's changing as it moves most likely because that noise function is like random so when the main function is called a new noise is created changing the noise.

    • @spidernh
      @spidernh Před 2 lety

      If I'm understanding correctly it's not that, since it's using a seed for the noise.
      I think the reason it's changing when it moves because it's using the position of the pixel along with the seed to create the noise, so when it moves it has new noise.

  • @Often_Guy
    @Often_Guy Před rokem +1

    Despite me using the same version as you do, mine is a bit laggy, is it because of how much storage my computer has? Because that is true, there is only like 5+ GB left...

  • @itsnova817
    @itsnova817 Před 2 lety

    Can you please help me? At 16:40 when he's uploading the float uniform, his square does the normal thing, while mine is just black! I even have the same code in the uploadFloat() function!

  • @anangelsdiaries
    @anangelsdiaries Před 10 měsíci

    A cool thing you can do instead of vec4(avg, avg, avg, 1), is to use vec3(avg). Since the constructor is smart enough to know, only one value means you want to repeat the thing you can avoid repetition in such cases by simply writing vec4(vec3(avg), 1).

  • @Luuke_
    @Luuke_ Před 4 lety

    Can you recommend any good book for OpenGL (and Java)?

    • @GamesWithGabe
      @GamesWithGabe  Před 4 lety

      Hey Luca, I don't have any experience with java/lwjgl books, but I did follow one chapter in this book lwjglgamedev.gitbooks.io/3d-game-development-with-lwjgl/content/ and it seemed pretty solid. I usually go to learn opengl which is written for c++, but it translates pretty good to java

  • @alexandruantoci2691
    @alexandruantoci2691 Před 3 lety

    love u

  • @LawMasterTimmy
    @LawMasterTimmy Před 2 lety

    Hello, when I run the program my shader flickers super quickly, it did this before I started this video. I followed last video and it did not do this super fast flicker, I do not know if it could be the glsl support plugin or not and I do not know what could be the cause for this as it was working fine before. Anyways great video, you can still make out what is happen with the shader, but it just flickers super fast *EDIT:* *Seems to work fine now, do not know what could have caused it*

    • @GamesWithGabe
      @GamesWithGabe  Před 2 lety +1

      Hey TRS, I'm glad it's working good now. It could be because of the algorithm I used for the random numbers. I believe since it was using floating point numbers it would have small errors from frame to frame that would cause a flickering, it might have been something different in your case though, but I'm glad it works now :)

  • @no1ofinterst
    @no1ofinterst Před 2 lety +2

    Just as a note to anyone who might have this issue. You need to make sure you have a beingUsed = false; to the detach method of the Shader. Very important.

  • @hyperocket3279
    @hyperocket3279 Před 4 lety +4

    For some reason, the top triangle does not have the lines affect like yours does. Both triangles look identical; they both resemble the bottom triangle in your project. I copied the code from your git hub...same effect.

    • @GamesWithGabe
      @GamesWithGabe  Před 4 lety +7

      That's strange, I just cloned my repo and started it up as a new project and got the same result as the video. You don't have to worry about it too much though, because I'm pretty sure I get rid of this code in the next tutorial anyways as it was just to demonstrate the power of shaders :)

    • @piCtrues
      @piCtrues Před 3 lety +1

      i just found out after watching the next video, "Texture Loading in LWJGL3" in the playlist, that the UV Coordinates in the vertexArray can create these lines, just if you were curious. i do not know if it happens to be the problem but it certainly is one probability. so if you are still curious try out changing the UV Coordinates in the vertexArray from the next Video a bit. :D

    • @davidmarinho2848
      @davidmarinho2848 Před 3 lety +2

      The same happened to me, and after replacing my classes with Gabe's classes from GitHub I found that in some way the color has an influence on the noise function.
      I was using these colors:
      0.0f, 0.0f, 0.0f, 1.0f,
      1.0f, 0.0f, 0.0f, 1.0f,
      0.0f, 1.0f, 1.0f, 1.0f,
      1.0f, 1.0f, 0.0f, 1.0f,
      and after replacing these colors to:
      1.0f, 0.0f, 0.0f, 1.0f,
      0.0f, 1.0f, 0.0f, 1.0f,
      1.0f, 0.0f, 1.0f, 1.0f,
      1.0f, 1.0f, 0.0f, 1.0f,
      My square started doing the same as Gabe's square.
      I hope that this was what happened with you too :)

  • @VoylinsLife
    @VoylinsLife Před 2 lety

    Please correct me if I'm wrong, but the camera is actually also just a shader or at least part of it?

    • @GamesWithGabe
      @GamesWithGabe  Před 2 lety +1

      Hey voylins life! The camera is just a container for the a view matrix, and often times a projection matrix. Shaders are small programs that essentially run per vertex and pixel on the GPU. You usually use a cameras projection and view matrix to transform an object from world space to screen space by uploading the uniforms to the shader, so they definitely can be connected in a way :)

    • @VoylinsLife
      @VoylinsLife Před 2 lety

      @@GamesWithGabe Thank you, I have a better understanding of it now ^^

  • @pytmkyt7558
    @pytmkyt7558 Před 2 lety

    how can I add multiple shaders a once?

    • @GamesWithGabe
      @GamesWithGabe  Před 2 lety

      You can compile more shaders and bind the shader that you want to use before submitting the draw call

    • @pytmkyt7558
      @pytmkyt7558 Před 2 lety

      @@GamesWithGabe thanks Gabe, I love your video's

  • @ParalyticAngel
    @ParalyticAngel Před 10 měsíci

    hmm, and again. My code can only show still standing pictures. No movement till now and the code has no issues.^^
    If this is continuing so, my Mario game will just be a portrait of the start window.^^ xDDDD

  • @sihleebuthelezi9231
    @sihleebuthelezi9231 Před 2 lety

    My box appears on the top right corner, HELP PLEASE

    • @GamesWithGabe
      @GamesWithGabe  Před 2 lety

      Hi Sihlee, can you provide more detail? Is your box in the top right corner of the window? If it is then you might want to double check your vertices and make sure they are the correct locations. Did you resize the window after starting the application? If you did you need to call glViewport to specify the new window size. Is your box drawing from the right corner to the bottom-left? If that's the case you may have a problem with the way your converting world coordinates to window coordinates, or you may just have the camera on the wrong side of the square making it looks like it's drawing backwards.