Tiled Forward Rendering #5

Merged
SeanOMik merged 15 commits from feature/tiled-forward-rendering into main 2024-03-23 14:38:43 +00:00
Owner

Tiled forward rendering is a very common rendering technique for rendering scenes with many many lights. In short, it uses a grid of tiles, that uses a compute shader to cull the lights in each tile. Then the fragment shader uses the results of the compute shader, and only calculates the lighting for each light in each tile instead of all lights.

Resources:

Note: All screenshots shown in this PR are taken from a window that is 800x600 unless labeled otherwise.

Tiled forward rendering is a very common rendering technique for rendering scenes with many many lights. In short, it uses a grid of tiles, that uses a compute shader to cull the lights in each tile. Then the fragment shader uses the results of the compute shader, and only calculates the lighting for each light in each tile instead of all lights. Resources: * https://www.3dgep.com/forward-plus * https://github.com/bcrusco/Forward-Plus-Renderer Note: All screenshots shown in this PR are taken from a window that is 800x600 unless labeled otherwise.
SeanOMik added 6 commits 2024-03-17 19:25:24 +00:00
Author
Owner

This has already been worked on before I made this PR. Here's a screenshot of the id of the tile as red and green in the fragment shader, with some lines:
image

This is the sponza scene with a blue point light rendered with forward+:
image
The top left tile appears to be the effects of the directional light in the scene. There is also a weird slightly darker square in the point light on the floor, it moves around with the camera.

This has already been worked on before I made this PR. Here's a screenshot of the id of the tile as red and green in the fragment shader, with some lines: ![image](/attachments/1d5df5f8-78e1-477c-b5ca-23cfc41a15ec) This is the sponza scene with a blue point light rendered with forward+: ![image](/attachments/e2cb16e1-1863-456a-8a14-3dfd3176c149) The top left tile appears to be the effects of the directional light in the scene. There is also a weird slightly darker square in the point light on the floor, it moves around with the camera.
SeanOMik added 1 commit 2024-03-17 20:07:48 +00:00
SeanOMik force-pushed feature/tiled-forward-rendering from a0b1e90bc6 to 834a864544 2024-03-20 01:18:48 +00:00 Compare
SeanOMik added 1 commit 2024-03-20 01:40:11 +00:00
SeanOMik added 2 commits 2024-03-20 15:42:01 +00:00
SeanOMik added 1 commit 2024-03-20 23:03:50 +00:00
Author
Owner

Tiled forward rendering is finally working!
image

I also added a triggerable debug view that shows the amount of lights in each tile (by pressing B). The brightness of each tile is number of lights in tile / total number of lights
image
Keep in mind that no optimizations have been made to the culling (i.e., AABB culling for point lights) so the culling isn't super accurate.

I did a bit of work to get spot lights working, but the light gets cutoff when moving closer to it:
image

A bug was also discovered that made it so the same mesh can't be shared between models which is why there aren't boxes at each light source in the above images.

Tiled forward rendering is finally working! ![image](/attachments/f5742c21-90af-4246-b747-8f109d8b37b1) I also added a triggerable debug view that shows the amount of lights in each tile (by pressing B). The brightness of each tile is `number of lights in tile / total number of lights` ![image](/attachments/d089f426-1448-48da-b529-eb43fdd2a1b4) Keep in mind that no optimizations have been made to the culling (i.e., AABB culling for point lights) so the culling isn't super accurate. I did a bit of work to get spot lights working, but the light gets cutoff when moving closer to it: ![image](/attachments/c90f6dca-fda2-4a0a-811d-b67f2aa64028) A bug was also discovered that made it so the same mesh can't be shared between models which is why there aren't boxes at each light source in the above images.
2.8 KiB
842 KiB
1015 KiB
SeanOMik added 1 commit 2024-03-22 14:46:55 +00:00
Author
Owner

Spot light culling was fixed, but in a non-optimal way. I couldn't figure out the issue with the math that checked if a cone was in the frustum, so I just treat the spotlight as a point light for culling. This is okay for now since optimizations for spotlight culling would replace the frustum culling.

Spot light culling was fixed, but in a non-optimal way. I couldn't figure out the issue with the math that checked if a cone was in the frustum, so I just treat the spotlight as a point light for culling. This is okay for now since optimizations for spotlight culling would replace the frustum culling.
SeanOMik added the
Kind/Feature
label 2024-03-23 02:24:29 +00:00
SeanOMik added 1 commit 2024-03-23 02:55:19 +00:00
SeanOMik changed title from WIP: Tiled Forward Rendering to Tiled Forward Rendering 2024-03-23 14:35:10 +00:00
Author
Owner

This can be considered complete. The performance is pretty poor, but for that I need to profile the engine to see what is taking up a lot of time. There can be future PRs for improving the performance of the renderer.

With 500 lights in the sponza scene I get ~180fps (release build, vsync disabled) when looking at the scene with the lights, or ~250fps when looking away.

This can be considered complete. The performance is pretty poor, but for that I need to profile the engine to see what is taking up a lot of time. There can be future PRs for improving the performance of the renderer. With 500 lights in the sponza scene I get ~180fps (release build, vsync disabled) when looking at the scene with the lights, or ~250fps when looking away.
SeanOMik merged commit 763d51ae36 into main 2024-03-23 14:38:43 +00:00
SeanOMik deleted branch feature/tiled-forward-rendering 2024-03-23 14:38:43 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: SeanOMik/lyra-engine#5
No description provided.