Today I fixed a problem with frustum culling. The perspective divide was not accounting for negative w, and that was causing some incorrect culling in certain situations.
I also offloaded some calculations (batches constructions) to another thread, in order to improve CPU performance.
mercoledì 10 gennaio 2018
martedì 9 gennaio 2018
Day 218: Frustum Culling
Today I implemented something that I was supposed to do a long time ago, frustum culling.
When I first started developing the engine I had a limited knowledge in 3D geometry, so I never implemented it because I didn't want to blindly copy an implementation.
Now that I improved on that side, I decided to tackle the problem, and it was pretty easy to get it to work.
First thing, I added to each mesh an AABB that gets created once at load time.
Then I proceeded to add a frustum test that, if failed, disables the geometry rendering (not the shadows though, because their contribute needs to be there even if the caster object isn't).
The implementation of the AABB - frustum intersection test uses NDC space. I realized that its much cleaner to convert the AABB to NDC and test the vertices against simple boundaries (-1 and 1 along the three axes), rather than doing more complex plane intersections in world space. I didn't look for it online, but I bet this is the way it is done.
In the picture you can see a part of the Sponza scene rendered with 67 draw calls, instead of the usual ~390.
When I first started developing the engine I had a limited knowledge in 3D geometry, so I never implemented it because I didn't want to blindly copy an implementation.
Now that I improved on that side, I decided to tackle the problem, and it was pretty easy to get it to work.
First thing, I added to each mesh an AABB that gets created once at load time.
Then I proceeded to add a frustum test that, if failed, disables the geometry rendering (not the shadows though, because their contribute needs to be there even if the caster object isn't).
The implementation of the AABB - frustum intersection test uses NDC space. I realized that its much cleaner to convert the AABB to NDC and test the vertices against simple boundaries (-1 and 1 along the three axes), rather than doing more complex plane intersections in world space. I didn't look for it online, but I bet this is the way it is done.
In the picture you can see a part of the Sponza scene rendered with 67 draw calls, instead of the usual ~390.
Iscriviti a:
Post (Atom)
