OpenGL Low-Poly Terrain Tutorial

  Рет қаралды 95,965

ThinMatrix

ThinMatrix

Күн бұрын

An explanation and comparison of 4 different techniques for generating and rendering a low-poly terrain.
Try the runnable demo:
www.dropbox.com/sh/k50zuozclu...
Finished code on GitHub:
github.com/TheThinMatrix/LowP...
Download the finished code (requires lwjgl.jar and lwjgl_utils.jar):
www.dropbox.com/sh/51wukf4u07...
Download the starting code (requires lwjgl.jar and lwjgl_utils.jar):
www.dropbox.com/sh/dtbx5d15py...
Full OpenGL tutorial playlist:
• OpenGL 3D Game Tutorials
Procedural Generation Tutorial:
• OpenGL 3D Game Tutoria...
Geometry Shader Tutorials:
• OpenGL Tutorial 49: Ge...
• OpenGL 3D Game Tutoria...
Support the series on Patreon: / thinmatrix
Facebook Page: / thinmatrix
Twitter: / thinmatrix
Tumblr: / thinmatrix
Instagram: / thin_matrix
Check out my game on IndieDB: www.indiedb.com/games/equilinox
End of video music- Kai Engel, "Waking Stars":
freemusicarchive.org/music/Kai...

Пікірлер: 145
@snowyleopard13
@snowyleopard13 6 жыл бұрын
You're a genius. Was looking for something like this. Had worked around with the flat modifier but I also came across the issue with the lighting. Didn't occur to me to use a hybrid method as you've described!
@DemonicGaming15
@DemonicGaming15 6 жыл бұрын
Brilliant as per usual. I'm starting this series *again* now I'm a lot more experienced, so should be able to add to it. Only thing I'll need help on is collision with objects in the world such as trees etc
@R-Games-Official
@R-Games-Official 3 жыл бұрын
Really looking forward to new Tutorials. Hope you will continue this series :)
@innye
@innye 6 жыл бұрын
Very cool tutorial as usual. I like your coding style, clean and easy to understand. I'd add one more method: using ddx(),ddy() (dFdx(),dFdy() in glsl) to compute per face normal in the pixelshader.
@ThinMatrix
@ThinMatrix 6 жыл бұрын
Ah yes, I should have done that one as well. I haven't tried it yet, but I'm guessing it would probably be more on the slow side in terms of performance, with the normal and lighting calculations having to be done per fragment. But I'll have to try it out and test it to see.
@sebastiansydow7505
@sebastiansydow7505 6 жыл бұрын
You could load the normals for each Triangle from a 1D "Buffer Texture" / 1D array accessed from vertex shader and moved to fragment shader with flat too
@fredimachadonet
@fredimachadonet 6 жыл бұрын
Thanks for the awesome tutorial Karl! I'm looking forward to watching the next ones! LYW!
@christophergoldsmith5616
@christophergoldsmith5616 6 жыл бұрын
Hey great to see another tutorial, thank you for the great content :) Would it be possible to have a mini series on 3D collision detection?
@NeilRoy
@NeilRoy 5 жыл бұрын
Very nice. I don't program in Java, but the same techniques can be applied in whatever language you prefer.
@viniciusmachado4422
@viniciusmachado4422 6 жыл бұрын
Nice to see your tutorials coming out again =)
@nicolasschleicher4263
@nicolasschleicher4263 6 жыл бұрын
thank you have been waiting for ages for this
@Karokendo
@Karokendo 5 жыл бұрын
Omg this amazing! Top tier tutorial. Congrats on equilinox btw :D
@dominicmcg2368
@dominicmcg2368 6 жыл бұрын
I recently merged the OpenGL wrapper style system (with classes for VAO, VBO, Attribute, etc..) from the code supplied with this tutorial with my engine code from the tutorials and managed to get the terrains to render correctly, but now entities render as a compressed spiky ball of vertices. I'm fairly sure its something to do with how I'm packing the vertex data into the ByteBuffer so I was wandering if you can just do it in the same order as the vertices are in when they're supplied by the improved OBJ file loader or if I have to reorder them somehow? I have also checked that normals and positions weren't becoming swapped before being loaded and that the attribute numbers of the attributes used to pack the data into the Vao are the same as those in the EntityRenderer and confirmed that neither of these was the case.
@JGunlimited
@JGunlimited 5 жыл бұрын
Thank you for sharing and teaching!
@hsunteik
@hsunteik 6 жыл бұрын
Thanks,thin matrix for all your tutorials.. Although I have not made and publish anything great yet with opengl but I will soon ..😅😀
@TheMrPokerDJ
@TheMrPokerDJ 6 жыл бұрын
yesssss dude ! needed that !
@timmeymcnerd
@timmeymcnerd 6 жыл бұрын
you are amazing! thank you for all the work you put into these tutorials. greatly apreciated! :) any chance you could go into some detail about how the batch rendering system in equilinox actually works? you explained the general idea in a video before, but i still dont understand how it is possible to render lots of different meshes in different locations with different textures in a single drawcall, without being able to change uniform variables inbetween models at all...
@tinocaer2861
@tinocaer2861 6 жыл бұрын
How could you implement this code to run the loading of the terrain on a separate thread? So like it updates the terrain independently of the main game loop! That would be cool. Thanks for the help!
@AKoribut
@AKoribut 6 жыл бұрын
How about to precalculate low poly normal map as a texture and then calculate the lighting in the fragment program? I know that this is super memory consuming but probably it can give some boost to performance
@Joern290
@Joern290 6 жыл бұрын
Best tutorials on youtube :))) !!!
@ajinkyasanas2256
@ajinkyasanas2256 2 жыл бұрын
For this I added my own per vertex lighting
@keldwikchaldain9545
@keldwikchaldain9545 3 жыл бұрын
It'd be really cool if you did some more opengl tutorials based on everything you learned on equilinox and your building game
@orr4945
@orr4945 6 жыл бұрын
Thank you very much! I understand the principal eventough I'm not a java scripted, thanks again, I liked :)
@daserstereichen
@daserstereichen 6 жыл бұрын
Amazing Tutorial! Thanks Karl! BTW wanted to ask, will there be a tutorial on menus like the ones in Equilinox ?
@ThinMatrix
@ThinMatrix 6 жыл бұрын
I'm glad you liked it :) I would like to do a tutorial series about more advanced UI features at some point, but I think I'll need a bit more time for that so it will probably have to wait until after I've finished Equilinox.
@daserstereichen
@daserstereichen 6 жыл бұрын
Thanks! I am glad your gonna cover it. I am excited for Equilinox to come out, and I sure can wait. Thanks for all the excellent tutorials, clear and to the point.
@KeNNyKennyYT
@KeNNyKennyYT 4 жыл бұрын
If i be use old the code for shadows, on the low poly terrain, its be working nice, or me need apply some changes?
@Itschotsch
@Itschotsch 6 жыл бұрын
Yay! Are you gonna explain in some future video how you project textures on a mesha like this? For example the circles you draw around a selected animal in Equilinox. I've been looking for something like this for a long time and haven't found a solution yet, so this would be quite awesome!
@TunaAlert
@TunaAlert 6 жыл бұрын
In my opinion the third method looks the best. The fact that the lighting is a bit off makes the terrain look a lot more rough and dirty and stirs it up a bit. I just think that this makes it look more natural.
@ThinMatrix
@ThinMatrix 6 жыл бұрын
That's actually the method I currently use in Equilinox :)
@TunaAlert
@TunaAlert 6 жыл бұрын
ThinMatrix please tell me that "currently" doesn't mean that you're going to change it in the future.
@MinecraftC0W
@MinecraftC0W 6 жыл бұрын
Can you shortly explain how you make a texture for a low poly asset in blender and export it?
@scewps
@scewps 6 жыл бұрын
If you find time, can we get a tutorial about god rays? :)
@viniciuslambardozzi4358
@viniciuslambardozzi4358 6 жыл бұрын
It shouldn't be that hard to get a basic version going, you just find the sun in screen space, render the sun in white and the scene in black, apply a radial blur centered on the sun and mix it with your render result. I'm trying to know if that's how it's implemented in bigger engines, but no luck finding anything about that yet ;-;
@scewps
@scewps 6 жыл бұрын
In many engines you can add a 3D godray effect into the scene manually. You could ofc use a radial blur for a simple 2D effect :)
@dominicmcg2368
@dominicmcg2368 6 жыл бұрын
One quick question about this video. What code are you using in your shader class in order to use .glsl file extensions on your shaders as opposed to .txt?
@ThinMatrix
@ThinMatrix 6 жыл бұрын
You don't need to make any changes to the code, other than updating the file path of the shader file.
@KeNNyKennyYT
@KeNNyKennyYT 5 жыл бұрын
Hi Carl. When I endured these generators together with low poly Terrain in my game engine I have a problem. I did everything right in the packaged system vao, vbo, attribute almost like you have in the code. This did not cause any problems. I'm using a hybrid version of terrain, and after generating it just I do not render. Terrain himself appears in the world with heights, this I checked by adding objects with Mouse Picker. But it is not displayed. I immediately say that I did not forget to add render(Terrain terrain, ...) method and renderers. Can be this that the with colors in the class Colour? If you know what I forgot to do write, or how to solve it?
@KeNNyKennyYT
@KeNNyKennyYT 5 жыл бұрын
I found my mistake and she was very stupid. To load the projectionViewMatrix terrain into the shader, I randomly loaded not ProjectionViewMatrix but simply projectionMatrix. I just didn’t notice as they all have the Matrix4f class, and eclipse just didn’t highlight the error.
@jojo-oq4ze
@jojo-oq4ze 6 жыл бұрын
Im using the flat method and now the player terrain collision doesn't work any more can you show or send an method to find the right triangle the player is standing on
@deependrasingh7259
@deependrasingh7259 6 жыл бұрын
Bro....your voice is really good....
@Damoygames
@Damoygames 6 жыл бұрын
I added to my Eclipse Java Build Path all the lwjgl 2.9.0 jars, and some code does not work. For instance Display.getWidth() from the "org.lwjgl.util.Display" class or the ContextAttribs class does not exist at all.. What version / jars should I use ? I don't miss a file as I added the whole 2.9.0 lwjgl library (+ openal ect...). Thanks ! :) (great vid', as always !)
@ThinMatrix
@ThinMatrix 6 жыл бұрын
The only 2 jars that you need to add to the build path are the lwjgl.jar and the lwjgl_utils.jar from the latest version of LWJGL 2. You also need to add the necessary natives for your OS. If you are getting those errors then it would suggest that the two jars haven't been added properly to your build path. For more information about how to set up the project, you can check out this tutorial: kzbin.info/www/bejne/gJXOomCXiKt4d5I
@Damoygames
@Damoygames 6 жыл бұрын
My natives were probably wrong, I followed (again :p) your tutorial and it solved my problems :) Thanks for your answer !
@drubdrub1621
@drubdrub1621 6 жыл бұрын
Could you render low poly entities (trees + animals) the same way?
@gabrieljackson1524
@gabrieljackson1524 6 жыл бұрын
I think you should work with bounding box soon, I did it by myself, however it took me 4+ hours :(( and it would help a lot of people out
@MohammedPlaysMC
@MohammedPlaysMC 6 жыл бұрын
Hi, I don't suppose anyone could help me calculate normals as I have went back to using the heightmap methods so I have more control on my terrains but on the edge off each terrain it goes all dark and looks off
@ThinMatrix
@ThinMatrix 6 жыл бұрын
You need to make sure that when calculating the normals along the edges you are taking the neighbouring vertices on the next terrain into account. In the tutorials we just assumed the height of any vertex that wasn't on the current terrain to be 0, but that is not usually the case. When doing the edge vertices you need to find the actual height of the relevant vertices on the next terrain.
@MohammedPlaysMC
@MohammedPlaysMC 6 жыл бұрын
Thanks found quite a simple fix and that was just making the x and z values equal 0 and this has fixed it :D
@maksj-lewis4504
@maksj-lewis4504 6 жыл бұрын
Hi i am currently using unity and i have been looking for a tutorial about low poly terrain like equillinox for a long time but there are not many good ones, I am now thinking about swapping over from unity to opengl, what are the benefits of open and or do you know any good threads about low poly terrain for c#? Thank you so much! love your videos
@slimelp9207
@slimelp9207 6 жыл бұрын
Maksym JL I think when you use opengl and code and not unity, you have more possiblities of adding things and controlling them. Contra is that it takes more time.
@slimelp9207
@slimelp9207 6 жыл бұрын
IDVert3X Thats right.
@marcasrealaccount
@marcasrealaccount 6 жыл бұрын
Could you do a tutorial about multithreading and chunk loading
@iso_2013
@iso_2013 6 жыл бұрын
Awesome. But can we get a tutorial for your awesome water in Equilinox? :D
@ThinMatrix
@ThinMatrix 6 жыл бұрын
That will be the next tutorial :)
@iso_2013
@iso_2013 6 жыл бұрын
Cool. Looking forward to it :D Also a complex physics (using JBullet or something) tutorial and a save data tutorial would be extremely useful as well
@brokenmatrix366
@brokenmatrix366 6 жыл бұрын
He doesn't use JBullet, and there are a lot of tutorials already out there, so that would be a waste of his time.
@iso_2013
@iso_2013 6 жыл бұрын
Hence "or something." I want to know how he does physics.
@brokenmatrix366
@brokenmatrix366 6 жыл бұрын
For here all he is doing is checking the hightmap value so stuff doesnt fall through the world I have missed a bunch, he might of added something else for bouncing fruit etc, idk. And for his old game, he just used AABB, he said so in one of his early tutorials. And for your second thing that I didn't see at first, for save / loading you can just write a file to your res folder using java I/O there are a million tutorials on how to do this, there is no way he will do one because he has denied all non-game related tutorials in the past.
@dominicmcg2368
@dominicmcg2368 6 жыл бұрын
Hey ThinMatrix, working to debug the shadow map code in my engine and am having a problem. Entities rendered to the shadow map are rubber banding all over the place causing the shadows in the world to flicker and jump around, not at all like how they appeared in the tutorial. I think the problem lies in the shadow box class and how the projectionMatrix is calculated from it but I can't see any problems with the maths. I appreciate that I'm asking a lot of questions in video comments, for which I apologise, but its frustrating that I can't seem to make any progress on this after weeks spent debugging it.
@dominicmcg2368
@dominicmcg2368 6 жыл бұрын
Managed to fix this problem... turns out it was to do with a fundamental misunderstanding of how JOML stores the result of matrix operations which I feel like a complete idiot for. Now I have the problem that all entities cast their shadow in a 25 times in a 5x5 grid surrounding them and I'm not sure why...
@ThinMatrix
@ThinMatrix 6 жыл бұрын
Could you show me a screenshot of this new problem please?
@dominicmcg2368
@dominicmcg2368 6 жыл бұрын
ThinMatrix Thanks for getting back to me so quickly! I appreciate I'm asking a lot of questions and apologise if they're getting a bit cumbersome by now. With regards to this though could I tweet a screenshot to you or would an email be better?
@sofiman8023
@sofiman8023 6 жыл бұрын
Awsome work! Your methods work with LWJGL 3 ?
@ThinMatrix
@ThinMatrix 6 жыл бұрын
Thanks! And yes they do, there's nothing specific to LWJGL 2 being used here.
@sofiman8023
@sofiman8023 6 жыл бұрын
Ok, Thank you !
@TheKroNacre
@TheKroNacre 6 жыл бұрын
Hi ! Can you please do a tutorial on Collision detection ? I am stuck on this for my own game
@sebastiansydow7505
@sebastiansydow7505 6 жыл бұрын
Collision Detection is not the easiest, but first of all can you please describe what exactly you need? Only Axis-Aligned-Boxes? Rotated Boxes (rotated which way?)? Triangles? 2D or 3D?
@TheKroNacre
@TheKroNacre 6 жыл бұрын
I need a way to "scan" or research any collision between my player (represented by a 3D ellipse) and a complex object that cannot be represensed by any simple geometry (as a house, for exemple). It may be useless and a waste of ressource to search every pixel of the two objects tho :/
@sebastiansydow7505
@sebastiansydow7505 6 жыл бұрын
It would be simple if you just have a "2D" Terrain with an altitude, not allowing you to jump on houses or anything else, as you can just represent the walls with 2D boxes expanding into infinite height. Start with Axis-Aligned-Boxes (see eg. Minecraft), as this would be the easiest way of doing things. When you want something more complicated, I'm sorry but I have no working examples as of now. If you need anything feel free to comment (like "rotated" Boxes). Already wrote one semi-working (with some not-working edge-cases) physics, then redid the physics and mid way through I realized that I really need better Utility classes, so now I'm rewriting those, then redoing the render and then get into physics... And I start to study in one and a half weeks... Some great References (alos for other things): - When needing 2D rotated boxes (read first!): www.euclideanspace.com/threed/games/examples/cars/collisions/index.htm - 2D Physics theory: www.euclideanspace.com/physics/dynamics/collision/twod/ - 3D Physics theory: www.euclideanspace.com/physics/dynamics/collision/threed/
@TheKroNacre
@TheKroNacre 6 жыл бұрын
Thanks a lot mate, i'll check this out :)
@thriemboy1706
@thriemboy1706 6 жыл бұрын
TheKroNacre there is a Video with 2d not axis aligned bounding boxes in KZbin from Leo ono. The Video can be found here kzbin.info/www/bejne/n4e7f2l9psyUbtU
@KeNNyKennyYT
@KeNNyKennyYT 5 жыл бұрын
How get a height of terrain for player? I try use the old getHeightOfTerrain() where we use barryCentric function, but it work not exactly how i expect. It gives out vertices as something wrong, and it seems to me as if inverted. Please help)
@ThinMatrix
@ThinMatrix 5 жыл бұрын
The barycentric method will still work fine as all it does is find the height at a certain point on a triangle. However, you need to make sure you are testing the correct triangle. In the earlier tutorials the terrain had a very regular pattern of triangles so we had a very simple method to determine the corner positions of the relevant triangle. In the terrain in this tutorial the grid squares have different rotations to make the pattern look a bit more random (as discussed in the video) so you'll need to take that into account when determining the vertices of the current triangle.
@KeNNyKennyYT
@KeNNyKennyYT 5 жыл бұрын
@@ThinMatrix If you're not busy, please give me the simplest example, and I'll take it from here.
@KeNNyKennyYT
@KeNNyKennyYT 5 жыл бұрын
@@ThinMatrix Can i use GridSquare class to calculate it?
@thriemboy1706
@thriemboy1706 6 жыл бұрын
What extentions in eclipse do you use for your GLSL- shaders?
@thriemboy1706
@thriemboy1706 6 жыл бұрын
Thenx apprendist im sorry for my wrong question. English isnt my mother tongue. I meant to say: what plugin does thinmatrix use for thr syntax Highlights ?
@Romejanic
@Romejanic 6 жыл бұрын
It's called eclipse shaders: sourceforge.net/projects/glshaders/
@julianbihl5054
@julianbihl5054 6 жыл бұрын
How do I install it?
@zadmu
@zadmu 6 жыл бұрын
Can you make a tutorial on under ground terrain generation, like caves and mining?
@brokenmatrix366
@brokenmatrix366 6 жыл бұрын
Look up marching cubes to start off, afterwards, you can look at dual contouring, and then the hybrid methods. If you don't have experience you REALLY need to start at marching cubes first. I doubt ThinMatrix will make a tutorial about this for a while as it is a really advanced topic.
@Nani-bk5op
@Nani-bk5op 5 жыл бұрын
Guys or someone I need help. I am using LWJGL 2.9.1 even though 3.2.whatever is out. I just didn't know how to import the resources into eclipse with the 3.whatever. Anyway, when using 2.9.1, normally I have to do this import org.lwjgl.LWJGLException; but I get this error The package org.lwjgl is accessible from more than one module: lwjgl, lwjgl.utilIs there any way to fix this? I am getting super angry over it because it is stupid. I cant code in 3D because its being a butt.
@nullvoid3432
@nullvoid3432 6 жыл бұрын
Can you make a tutorial about how to make prefab esque objects
@treysenzobell3299
@treysenzobell3299 6 жыл бұрын
How about a tutorial about clouds or tessellating terrain?
@nelala_
@nelala_ 6 жыл бұрын
notification, yayyy :3
@Jet-Pack
@Jet-Pack 6 жыл бұрын
Can't you cheat a bit and use another list of vectors (one per triangle) stored in a VAO or something? Pass on the vec3 to the fragment shader like you would pass on a uv coordinate?
@ThinMatrix
@ThinMatrix 6 жыл бұрын
Unfortunately there don't seem to be any good ways in OpenGL to provide per-face data to the shaders. You can only provide per-vertex data in the VAOs (or per-instance data when using instancing). So you can store the normals for each vertex, but the vertex is then shared between multiple triangles, and therefore the normal is shared, leading to smooth lighting. That's why the first technique involves duplicating the vertices, so that the triangles don't share any vertices/normals with other triangles.
@Jet-Pack
@Jet-Pack 6 жыл бұрын
Ah ok because it's per vertex... makes sense now! Thanks :)
@Zekronz
@Zekronz 6 жыл бұрын
Are you going to make a tutorial about deferred lighting?
@ThinMatrix
@ThinMatrix 6 жыл бұрын
Probably at some point, but I have a few other topics that I want to cover first.
@Zekronz
@Zekronz 6 жыл бұрын
Alright :)
@OhNooez
@OhNooez 6 жыл бұрын
From a fellow programmer, keep up the good work! I have been programming my own OpenGL engine (but in C++) as well for the past 4 to 5 months, with built-in multithreaded support for rendering and processing chunks. While i am not yet at the OpenGL level that you are (yet! Multithreaded data structures have taken more time than i thought), the thread pool is working with no problems. I was thinking of creating a series of tutorials about multithreading and even give code examples...would you or anyone else be interested?
@imtrying3981
@imtrying3981 6 жыл бұрын
hi im kindanew to eclipse and never really proggramed in it so could somone plz give me a refrince on how to learn or somthing... iv alwas made things in processing and unity but thay arnt realy working out togood for what i want.
@extrem2497
@extrem2497 4 жыл бұрын
I'm sorry to say this but dude without enought knowledge about java or programming you should stay away from these tutorials. You need to learn basics first. Making Game with Unity is easy, less complex and less time consuming and for inexperienced developers who make crappy games and fill AppStores with them. Coding Your Own Game from scratch (from nothing.) is different. its for experienced developers you need a solid java and programming knowledge to make awesome things. Also Its much more hard and much more complex. You Don't have fancy looking Editor as unity gives you. Only IDE, game assests and code..
@lorenzogarcia7883
@lorenzogarcia7883 6 жыл бұрын
I hope next will be the Terrain editor?
@gage2560
@gage2560 6 жыл бұрын
smooth camera ?
@BoltzmanDistribution
@BoltzmanDistribution 6 жыл бұрын
You should do a tutorial on Voxels and Voxel terrain!
@louisrist8594
@louisrist8594 6 жыл бұрын
what program did you use to do this
@ThinMatrix
@ThinMatrix 6 жыл бұрын
The only program used in this tutorial is Eclipse (the IDE).
@BrenFirely
@BrenFirely 4 жыл бұрын
What app he use?
@janko8115
@janko8115 6 жыл бұрын
Why do you use lwjgl 2 when lwjgl 3 is released ?
@ThinMatrix
@ThinMatrix 6 жыл бұрын
I just haven't got round to learning about LWJGL 3 yet because the game I'm working on still uses LWJGL 2 (I started it before LWJGL 3 was released). Once I've finished my game I'll start using LWJGL 3 :)
@SkyFly19853
@SkyFly19853 4 жыл бұрын
So, can it be done in Python?
@marxy3720
@marxy3720 6 жыл бұрын
Hi, Thin Matrix! Can you do, a very far away day, a tutorial on how to make a semi-transparent model\texture? Because I would be very happy to see it on this channel ... [I'm here from one of the first tutorials (15)]
@Sylfa
@Sylfa 6 жыл бұрын
Translucent models are a bit awkward, you have to render them last to get the depth buffer to behave (or without writing the depth, but then they can be hidden by objects behind them unless they are drawn after all solid objects). If your fine with only seeing the nearest transparent object then just separate all such objects from the solid ones and render them after the solids. Getting a mist like effect is much more involved sadly (try googling soft particles and mist rendering if you can't wait for a tutorial). Some games simply skip the whole pain by doing a screen door like effect, so the semi transparent object is fully solid but only part of the pixels are rendered (in this case, look at the discard glsl function for the pixel shader), in this case you don't have to sort your transparent objects.
@marxy3720
@marxy3720 6 жыл бұрын
Thanks for answering me!! :D I will try it when I have time.
@witzur5695
@witzur5695 6 жыл бұрын
I love you.
@abdousekhi4933
@abdousekhi4933 2 жыл бұрын
please do a tutoriel how we can render vidéo with opengl
@cocotyn
@cocotyn 5 жыл бұрын
did anyone who want to help implemented this generation with a heightmap and our regular terrain, cant' figure it out ='(
@cocotyn
@cocotyn 5 жыл бұрын
The geometry method, i'm not sure on how to do it
@Suppenfischeintopf
@Suppenfischeintopf 6 жыл бұрын
So OpenGL still doesn't have per real face normals?
@Sylfa
@Sylfa 6 жыл бұрын
Doesn't look like DirectX does either, but perhaps you were just lamenting the fact, not missing it.
@GieneqAD
@GieneqAD 6 жыл бұрын
Why dont u use instancing? As far as I know instancing is always faster solutn than geometry shader (which is not supported in many devices)
@ThinMatrix
@ThinMatrix 6 жыл бұрын
This isn't really a situation where instancing would be useful. Instancing is used when rendering the same mesh many times. In this situation we only have one mesh, the whole terrain. Perhaps you were thinking of treating each quad as a separate mesh, but we can't really do that because each quad has a different shape and colour. But as shown in the video, using the geometry shader isn't a very good solution either because of its performance.
@GieneqAD
@GieneqAD 6 жыл бұрын
ThinMatrix Yea I've seen many situations where ppl were using geometry shader wherever they could, that why I asked. Thanks you are definitely right ;) Really well done, keep working!
@enderprogames8827
@enderprogames8827 6 жыл бұрын
I’m sorry but I don’t know how to add the code into the project, sorry I’m new.
@enderprogames8827
@enderprogames8827 6 жыл бұрын
coden4 hah I’m sorry for annoying you, I know how to add code but I just got confused with something, thanks anyways. I really love your channel and videos.
@Speiger
@Speiger 6 жыл бұрын
Well i would like to know how my solution would compare. Instead of making 4 vertexes per quad. I suggest 1 vertex per quad and a vec4 for the heights in the model. Then use a shader that converts the position of the 1 vertex + the vec4 into a quad in the geomitry shader it also can use the normal from the vertex and the color from it. Ofcourse you no longer can have a mixed color but then again the hybrid solution cant do that either. It would reduce the passive GPU memory usage by a lot since there is less data: - 8-12 byte for the vertex position, - 12 byte for the normal - 4-16 byte for the color (either as byte or as float) - 4-16 byte for the heights (as byte or float) So lets say worst case: My idea is 56 byte per quad instead of 160 byte per quad in the normal shader with duplicated vertexes. (4 x pos, 4x normals, 4x color) on top of that the indecies buffer falls away with this type of a system since you have no indecies here and dont need one. and the idea is that this uses more memory the more is actually being rendered. Like a "Passive" mode and a "active" mode. i have not tested it i just tried to think of a system. And also the question is: if a vertex is not on the screen or cant be seen for some reason will it be thrown into the geometry shader?
@ThinMatrix
@ThinMatrix 6 жыл бұрын
That's an interesting idea! It would definitely be the lowest cost in terms of memory, but I'd guess that the performance wouldn't be as good as some of the other techniques just because of the use of the geometry shader. Even using a simple geometry shader with barely any processing at all affects performance quite a bit. I'd have to test it to be certain though. The other thing to note is that each quad would use the same colour for both of its triangles, unless you added a second colour attribute to the vertex. Same for the normal, you'd need to store two for the vertex, one for each triangle. Or just don't store it at all and calculate it in the geometry shader. To reduce memory cost even more you could just use the index of the vertex instead of the vertex position. The x,z coords could be calculated based on the index in the geometry shader. Then you'd have: index: 4 bytes colour1: 4 bytes colour2: 4 bytes heights: 8 bytes (4 shorts would probably do) = 20 bytes per vertex/quad, so for the 1000x1000 terrain that's 20MB. Pretty good! Performance probably wouldn't be too great though with the extra per-face calculations, but memory-wise it's very good. And yes, even vertices outside the screen have to go through the geometry shader. Clipping happens after the geometry shader.
@Speiger
@Speiger 6 жыл бұрын
Well if you have a chunk based system in your hand and draw only the chunks you can see that could be not as bad as people think. I am planning on a top down game so the amount of work added to the shader wouldnt be effecting even low powered gpus since this would only count for the terrain. For the byte count i doubt that would be enough with 2 shorts. Some worlds could be bigger then 65k in size and doing that would not work properly. Sadly OpenGL does not have a Medium (3 byte number) from what i saw. But on the other hand that is based on what you want to design. I think a geometry shader aproach would be better for my system since you have only a top down view (with a slight angle) so thats being fine. But on a Equlinox aproach that could be something that would hurt performance a lot. What i would like to know is what do you think about dynamic memory allocation/releasing of the GPU ram? Since we have only 1GB (weakest GPU case i go with) Should be everything (in parts of terrain) being stored on the GPU even so you are far away from it? I was thinking to do like you did a renderquere (but with linkedlists instead of array ones "Trying to point out a lag issue") and reload chunk renderdata based on where the player is. If he is far away enough it gets removed if he comes closer it gets readded to the GPU and when he is close enough its getting renderered again. Basically a 3 radius type of a thing. I was even thinking about using a players ram with the chunks. Basically precalculating all vertex data buffereing it in the Ram and when the camera comes close to it really quick inject the data into the GPU ram instead of recalculating it on request. i am walking with a chunk aproach in my head right now where i generate models / terrain in code and have a vertex builder helper too which uses more GPU memory since there is duplicated models on the other hand i have less draw calls on the static objects.
@meatbyte
@meatbyte 6 жыл бұрын
Awesome
@thriemboy1706
@thriemboy1706 6 жыл бұрын
Great tutorial and I think I will give it a shot in my engine as well. But my question has nothing to do with it. Sorry about that. So here it is: I added Clipspace Frustum Culling into my engine. It works well for testing wether a point is in the view frustum but I can't figure out what the calculations would be for a sphere test. my code looks something like this: clipPoint = mvpMatrix * pointToTest; if(clipPoint.x< - clipPoint.w && clipPoint.x > clipPoint.w) // is this even correct // and so on but how do i get the radius of the sphere into the calculations if it is unclear what i mean i could also make a video on my channel about it thank you for the help and sorry again for my question
@Sylfa
@Sylfa 6 жыл бұрын
See if this link doesn't help: gamedev.stackexchange.com/questions/86000/fast-exact-frustum-culling-for-sphere
@thriemboy1706
@thriemboy1706 6 жыл бұрын
MrSylfa i already checked that forum
@matthiasBdot
@matthiasBdot 6 жыл бұрын
Seems a bit overcomplicated.. i'd just provide an extra buffer with precalculated face normals or provide two extra indices which would give a vertex access to the other face vertices to calc the avg face normal in the vshader if you need it animated
@ThinMatrix
@ThinMatrix 6 жыл бұрын
How would you provide the extra buffer to the vertex shader? As far as I'm aware there's no easy way of providing per-face data to the shaders. Using two extra indices per vertex would also only work if the mesh is "split", as shown in the first technique, but then you might as well just provide the normal seeing as it's only 4 bytes (when using packed normalized ints). Unless, as you said, you need to animate it.
@matthiasBdot
@matthiasBdot 6 жыл бұрын
ThinMatrix you are right.. just read, that it is a open gl limitation not supportin multiple index buffers.. sad. There would not be a way without a memory overhead. I like the geometry shader version the most.. it's how it supposed to work being probably more efficient in future with cleaner maintainable code. As soon you start dublicating vertices in an odd manner it will cost you time to adapt it later while you could use that time to improve the overall performance more optimizing something else. You can also simply adapt the geometry shader to animate the water etc.
@ThinMatrix
@ThinMatrix 6 жыл бұрын
For my game "Equilinox" I use the "flat" technique, which also doesn't duplicate any vertices and is the fastest performer. It doesn't quite give the correct lighting, but I kind of like the pattern it creates. It's a shame that the geometry shader seems to have such a performance overhead - it definitely is the cleanest method and the one that makes the most sense.
@matthiasBdot
@matthiasBdot 6 жыл бұрын
I like your Equilinox Vlogs :)
@roko567
@roko567 6 жыл бұрын
you should get a pop filter
@saladgaming7146
@saladgaming7146 6 жыл бұрын
Is OpenGL and LWJGL 2 different languages?
@ThinMatrix
@ThinMatrix 6 жыл бұрын
OpenGL is an API, LWJGL is a Java library which provides access to that OpenGL API. To use OpenGL in other programming languages you would use a different library.
@ThinMatrix
@ThinMatrix 6 жыл бұрын
Part of using OpenGL involves writing programs that run on the GPU, and this does require the use of a different language, called "GLSL".
@marcasrealaccount
@marcasrealaccount 6 жыл бұрын
If you have wanted to have the camera move in the direction that your looking in (both yaw & pitch) then, here is your lucky code: In the camera code: public void moveLocalZ() { float xzLength = (float) Math.cos(Math.toRadians(-pitch)) * localVelocity.z; float dx = xzLength * (float) Math.sin(Math.toRadians(yaw)); float dz = xzLength * (float) Math.cos(Math.toRadians(yaw)); float dy = localVelocity.z * (float) Math.sin(Math.toRadians(-pitch)); position.x = dx; position.y = dy; position.z = dz; } public void moveLocalY() { float xzLength = (float) Math.cos(Math.toRadians(-(pitch - 90))) * localVelocity.y; float dx = xzLength * (float) Math.sin(Math.toRadians(yaw)); float dz = xzLength * (float) Math.cos(Math.toRadians(yaw)); float dy = localVelocity.y * (float) Math.sin(Math.toRadians(-(pitch - 90))); position.x = dx; position.y = dy; position.z = dz; } public void moveLocalX() { float xzLength = localVelocity.x; float dx = xzLength * (float) Math.sin(Math.toRadians(yaw - 90)); float dz = xzLength * (float) Math.cos(Math.toRadians(yaw - 90)); position.x = dx; position.y = dy; position.z = dz; } This will make you able to move the camera in the relative coordinates of the camera. thats the reason the names are moveLocal"Local Direction" (Z - Forwards, X - Sideways, Y - up) The argument localVelocity a Vector3f that will change depending on the buttons pressed (W&S change the Z, A&D change the X, Q&E change the Y) the Q&E can be changed to LeftShift & Space if you want to, but here is the basic calculation of the Speed: Still in the camera code: public void calculateSpeed(float maxSpeed) { if (Keyboard.isKeyDown(Keyboard.KEY_W)) { if (localVelocity.z > maxSpeed) localVelocity.z = maxSpeed; if (localVelocity.z < maxSpeed) localVelocity.z += acceleration; } if (Keyboard.isKeyDown(Keyboard.KEY_S)) { if (localVelocity.z < -maxSpeed) localVelocity.z = -maxSpeed; if (localVelocity.z > -maxSpeed) localVelocity.z -= deAcceleration; } if (Keyboard.isKeyDown(Keyboard.KEY_A)) { if (localVelocity.x > maxSpeed) localVelocity.x = maxSpeed; if (localVelocity.x < maxSpeed) localVelocity.x += acceleration; } if (Keyboard.isKeyDown(Keyboard.KEY_D)) { if (localVelocity.x < -maxSpeed) localVelocity.x = -maxSpeed; if (localVelocity.x > -maxSpeed) localVelocity.x -= deAcceleration; } if (Keyboard.isKeyDown(Keyboard.KEY_E)) { if (localVelocity.y > maxSpeed) localVelocity.y = maxSpeed; if (localVelocity.y < maxSpeed) localVelocity.y += acceleration; } if (Keyboard.isKeyDown(Keyboard.KEY_Q)) { if (localVelocity.y < -maxSpeed) localVelocity.y = -maxSpeed; if (localVelocity.y > -maxSpeed) localVelocity.y -= deAcceleration; } if (!Keyboard.isKeyDown(Keyboard.KEY_W) && !Keyboard.isKeyDown(Keyboard.KEY_S)) { localVelocity.z = 0; velocity.z = 0; } if (!Keyboard.isKeyDown(Keyboard.KEY_A) && !Keyboard.isKeyDown(Keyboard.KEY_D)) { localVelocity.x = 0; velocity.x = 0; } if (!Keyboard.isKeyDown(Keyboard.KEY_Q) && !Keyboard.isKeyDown(Keyboard.KEY_E)) { localVelocity.y = 0; velocity.y = 0; } } And then the move method: public void move(float maxSpeed) { calculateSpeed(maxSpeed); calculateYaw(); //Calculates the yaw, you should have this done allready calculatePitch(); //Calculates the pitch, you should have this done allready moveLocalZ(); moveLocalX(); moveLocalY(); yaw %= 360; updateViewMatrix(); } I wanna give a shoutout to this article that i read from and it might help others: stackoverflow D O T com/questions/18158238/how-to-make-a-camera-move-in-the-direction-it-is-facing-in-java (Change the "D O T" to ".") (It all will make sence when you read the answer to the question) (The cos & sin methods are Math.cos & Math.sin but instead of using just the yaw & pitch in there you'l have to use Math.toRadians(yaw) & Math.toRadians(pitch). If you get an error im glad to help out, and you can easily do an interpolational movement so its smoother
@hitshot
@hitshot 5 жыл бұрын
multiplayer?
@dandranitzki9537
@dandranitzki9537 6 жыл бұрын
All I see is gray... help please!!!!!!!!!!!!!
@dandranitzki9537
@dandranitzki9537 6 жыл бұрын
It's probably me being stupid
@joshuathenerd
@joshuathenerd 6 жыл бұрын
I have no idea how to code java
@thenimalu
@thenimalu 6 жыл бұрын
Haha, noooo... i wanted to make such a low poly terrain and failed and just yesterday i deleted my lwjgl files
@vincentkuhlmann
@vincentkuhlmann 6 жыл бұрын
Around 15:17 you use the symbol "Mb" to abbreviate megabytes. This is however very misleading, since the small letter "b" is reserved for bits and the capital letter "B" for bytes. Since this makes a quite substantial difference it is good practice to always use the correct symbol, even when it doesn't really matter that much like in this case. (The expressing in bits rather unusual though for computer processing. In computer communication on the other hand, like network speed (in Mbps or Kbps) it is used.) Just wanted to make you aware about it for the future. Keep up the good video's and progress as always!
@water2986
@water2986 3 жыл бұрын
11:00
@Omaritoo
@Omaritoo 6 жыл бұрын
why the dislikes tho ?
@janrobinkautz742
@janrobinkautz742 6 жыл бұрын
Can you make a tutorial about displacement maps?
OpenGL Low-Poly Water Tutorial
22:01
ThinMatrix
Рет қаралды 92 М.
How I Implemented Shadows in my Game Engine
7:45
ThinMatrix
Рет қаралды 93 М.
Sigma Girl Education #sigma #viral #comedy
00:16
CRAZY GREAPA
Рет қаралды 70 МЛН
Cute Barbie gadgets 🩷💛
01:00
TheSoul Music Family
Рет қаралды 72 МЛН
🍟Best French Fries Homemade #cooking #shorts
00:42
BANKII
Рет қаралды 15 МЛН
Heightmaps // Terrain Rendering episode #1
20:20
OGLDEV
Рет қаралды 12 М.
Computer Graphics Tutorial - PBR (Physically Based Rendering)
13:40
Victor Gordan
Рет қаралды 30 М.
The ONE Texture Every Game NEEDS
9:00
SimonDev
Рет қаралды 247 М.
HOW TO BLEND SKELETAL ANIMATIONS // OpenGL Tutorial #42
8:04
How Procedurally Generated Terrain Works
6:24
TheHappieCat
Рет қаралды 135 М.
Coding Challenge 11: 3D Terrain Generation with Perlin Noise in Processing
22:44
Practical Procedural Generation for Everyone
31:30
GDC
Рет қаралды 408 М.
I made a better Ray-Tracing engine
17:38
NamePointer
Рет қаралды 242 М.
Coding Challenge #85: The Game of Life
38:20
The Coding Train
Рет қаралды 677 М.
MAIZEN But Everything is weird - MAIZEN Minecraft Animation #shorts
0:27
Kamui - Minecraft Animation
Рет қаралды 28 МЛН
Which level took the longest??
0:34
A4
Рет қаралды 3,6 МЛН
Maze Challenge with Sonic and Knuckles #minecraft #sonic
0:22
SonicCraft
Рет қаралды 11 МЛН
Открываю Minecraft box
0:27
Mikha Zen
Рет қаралды 1,7 МЛН
СЛИЗЬ vs ДРУГ в РОБЛОКС! Roblox #роблокс #roblox
0:33
ВЛАДУС ИГРАЕТ
Рет қаралды 1,7 МЛН
Bling Bang Bang Born fight: Aaron Vs Zane #minecraftshorts
0:13
BigBlockCraft
Рет қаралды 13 МЛН