Frustum Culling // Terrain Rendering episode #9

  Рет қаралды 5,528

OGLDEV

OGLDEV

Күн бұрын

In this video we implement Frustum Culling in order to avoid rendering patches which are outside the camera's field of view.
"Focus on 3D Terrain Programming" by Trenk Polack: www.amazon.com/Focus-Terrain-...
Timecodes:
0:00 Intro
0:38 Example
2:40 Frustum Culling for terrains
3:33 Recap of the 3D pipeline
5:31 Clipper example
6:42 Method #1: View Space Culling
8:06 Code review
11:02 Demo #1
11:29 Method #2: World Space Culling
16:38 Code review
19:54 A problem with the implementation
20:40 Next steps and outro
Make sure to watch all the previous tutorials in the "OpenGL For Beginners" playlist at • OpenGL for Beginners
Please visit ogldev.org to see more of my tutorials on modern OpenGL.
Link to source: github.com/emeiri/ogldev/blob...
If you want to get the same version of the code that was used in the video checkout the tag 'TERRAIN9'.
OpenGL 4.6 specification: www.khronos.org/registry/Open...
Feel free to comment below.
Email: ogldev1@gmail.com
Instagram: @ogldev1
Github: github.com/emeiri/ogldev.git
Twitter: @ogldev
One time donations (Paypal): ogldev.org/donate.html
Patreon: / ogldev
Credits:
Track: Eight - Land of Fire [Audio Library Release]
Music provided by Audio Library Plus
Watch: • Eight - Land of Fire |...
Free Download / Stream: alplus.io/eight
Sound effects obtained from www.zapsplat.com
Enjoy,
Etay Meiri
#opengl #ogldev #opengtutorials

Пікірлер: 20
@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 'TERRAIN9'. Build on Linux: cd ogldev/Terrain9 && ./build.sh Build on Windows: Open the Visual Studio solution: ogldev\Windows\ogldev_vs_2022\ogldev_vs_2022.sln Build the project 'TerrainRendering\Terrain9'
@grengren6421
@grengren6421 Жыл бұрын
I love this series. I have learned so much from you. Thank you for these wonderful tutorials and sharing your knowledge with us.
@OGLDEV
@OGLDEV Жыл бұрын
You're welcome :-)
@KeyError
@KeyError Жыл бұрын
This approach has other downsides as well. Since it only checks if any points of the bounding box intersect the view frustum, it will also fail if a bounding box overlaps the view frustum so that all of its points are outside, but on opposite sides (for example the bounding box of a room that the camera is inside). A better solution would be to check for overlap of convex hulls by asking “is there any view between these two objects?”. This is difficult to compute in 3D, but easy to compute in 1D, and you can compute it for each of the 3 dimensions in view space, and combine those results for a pretty good result in 3D (i.e. an overlap in X and Y and Z means an overlap in 3D). This approach overestimates, so you will render more than you can see, but for a sufficiently large scene it will still be a marked improvement. You also need to compute an axis aligned bounding box in view space for every object every frame, which may be too computationally expensive. You could make this faster by computing an axis aligned bounding box in model space as you load each object, translating that by the model matrix each frame, translating that into view space, and calculating an axis aligned bounding box from that instead. This will mean even more overestimation, but will be faster since you’re only operating on 8 points instead of N many points
@OGLDEV
@OGLDEV Жыл бұрын
Thanks, I will definitely continue exploring this topic.
@chrispizz1327
@chrispizz1327 Жыл бұрын
Thx OGLDEV , great demonstration , good job , I already use it or something near of that For the small bug of the patch partially in/out of the frustum , I have enlarge the frustum a little bit with focal camera a little more far than the real position
@OGLDEV
@OGLDEV Жыл бұрын
Cool, thanks
@SuperGrimmy
@SuperGrimmy 10 ай бұрын
I did the same misake by just checking the corners of the bounding box. You get the same issue with with 3D object as shown in the video since you can view parts of of the mesh even when all corners are outside of the frustum. It can of course work in special cases. I ended up just doing line / plane intersection using a transform feedback or compute shader since that also builds the indirect draw buffer I need for the scene.
@OGLDEV
@OGLDEV 9 ай бұрын
Interesting, I also plan to do plane intersection but probably without transform feedback/compute shader.
@nerijusvilcinskas7851
@nerijusvilcinskas7851 Жыл бұрын
Thanks for another great video! I have tried both approaches and found the first one to work much better using clip space culling, using world space too many patches were culled then they should have been visible so maybe I left a bug there, but I do have to ask: if I want my terrain to support model/world transform, can i still use clip space culling then?
@OGLDEV
@OGLDEV Жыл бұрын
You're welcome :-) Other than minor differences due to numerical accuracy the two methods should be about the same so there might be a bug lurking there. In the past couple of days I've been experimenting with few workarounds for the these problems: 1. Always render the patch that the camera is located in. 2. Always render the patches whose center is within a distance of twice the size of a patch from the camera (kind of includes #1 but I still use #1 to print the location of the camera). I hope to check in these changes over the weekend. I'm also thinking that we may want to skip checking the top and bottom planes because in the real world you usually look forward (walking around with your head pointing to the sky so that you can't see the ground is not recommended...). You can do the model/world transform. You just need to include this matrix same as view/clip.
@nerijusvilcinskas7851
@nerijusvilcinskas7851 Жыл бұрын
@@OGLDEV Thanks for reply! I did find a bug in my code, because I am using GLM instead of my own math classes, so I just had to fix clip plane calculation and both methods now work flawlessly! Looking forward to the next video!
@Fxiques
@Fxiques Жыл бұрын
Cool, thanks
@OGLDEV
@OGLDEV Жыл бұрын
You're welcome :-)
@AlbertRyanstein
@AlbertRyanstein 8 ай бұрын
Great
@OGLDEV
@OGLDEV 8 ай бұрын
Thanks!
@marioxdangelo
@marioxdangelo Жыл бұрын
My Grandpa used to say the same thing. #100
@OGLDEV
@OGLDEV Жыл бұрын
;-)
@icaroamorim3123
@icaroamorim3123 Жыл бұрын
Your grandfather was a graphics programmer?
@OGLDEV
@OGLDEV Жыл бұрын
You need to watch until the end of the video. He was Pete Mitchell's commander ;-)
$10,000 Every Day You Survive In The Wilderness
26:44
MrBeast
Рет қаралды 126 МЛН
Шокирующая Речь Выпускника 😳📽️@CarrolltonTexas
00:43
Глеб Рандалайнен
Рет қаралды 11 МЛН
ELE QUEBROU A TAÇA DE FUTEBOL
00:45
Matheus Kriwat
Рет қаралды 36 МЛН
TRY NOT TO LAUGH 😂
00:56
Feinxy
Рет қаралды 9 МЛН
Heightmaps // Terrain Rendering episode #1
20:20
OGLDEV
Рет қаралды 12 М.
Rotations in 3D Graphics With Quaternions
8:23
Manifolds in Maryland
Рет қаралды 6 М.
How Games Have Worked for 30 Years to Do Less Work
23:40
SimonDev
Рет қаралды 1,2 МЛН
The OpenGL Software Ecosystem
13:51
OGLDEV
Рет қаралды 2,4 М.
How to Create 3D Terrain with Google Maps and Blender!
12:17
CG Geek
Рет қаралды 1,9 МЛН
How Big Budget AAA Games Render Bloom
13:23
SimonDev
Рет қаралды 105 М.
The Traveling Salesman Problem: When Good Enough Beats Perfect
30:27
I made a better Ray-Tracing engine
17:38
NamePointer
Рет қаралды 244 М.
When Your Game Is Bad But Your Optimisation Is Genius
8:52
Vercidium
Рет қаралды 1,3 МЛН
$10,000 Every Day You Survive In The Wilderness
26:44
MrBeast
Рет қаралды 126 МЛН