Skip to content

Commit 156be23

Browse files
committed
feat(vulkan): implement post-processing effects and enhance particle system
- Added support for post-processing effects in Vulkan, including SSAO, SSR, Bloom, DoF, Motion Blur, Color Grading, and Heat Distortion. - Enhanced the particle system with GPU buffer management for particles, allowing for efficient rendering and memory handling. - Updated the particle upload function to convert CPU particles to GPU format and manage indirect draw commands. - Improved weather effect rendering by integrating particle spawning based on weather conditions (rain, snow, dust). - Enhanced documentation and comments throughout the codebase to clarify new features and future implementation paths. This commit significantly advances the Vulkan renderer's capabilities in post-processing and particle effects, improving visual fidelity and performance.
1 parent f07b668 commit 156be23

8 files changed

Lines changed: 644 additions & 55 deletions

File tree

src/renderers/vulkan/tr_cmds.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2424
extern refimport_t ri;
2525
#include "../renderercommon/tr_frame_graph.h"
2626
#include "vk_utils.h" // For memory validation functions
27+
#ifdef USE_VULKAN
28+
#include "vk_post_process.h" // For post-processing types and functions
29+
#endif
2730

2831
/*
2932
=====================
@@ -198,9 +201,34 @@ static void RG_ExecuteLightClusters( void *user ) {
198201
R_BuildLightClusters();
199202
}
200203

201-
// Placeholder post pass (currently no-op). Extend later for post effects.
204+
// Post-processing pass - executes post-processing effects if enabled
202205
static void RG_ExecutePostPass( void *user ) {
203206
(void)user;
207+
208+
#ifdef USE_VULKAN
209+
// Check if post-processing is available and enabled
210+
extern qboolean vk_has_post_processing(void);
211+
extern void vk_execute_post_processing(const postProcessConfig_t *config);
212+
extern cvar_t *r_pp_ssao;
213+
extern cvar_t *r_pp_ssr;
214+
extern cvar_t *r_pp_bloom;
215+
extern cvar_t *r_pp_dof;
216+
extern cvar_t *r_pp_motion_blur;
217+
extern cvar_t *r_pp_color_grading;
218+
extern cvar_t *r_pp_heat_distortion;
219+
220+
if (vk_has_post_processing()) {
221+
// Build post-processing configuration from CVARs
222+
postProcessConfig_t config;
223+
extern void vk_update_post_process_config(postProcessConfig_t *config);
224+
vk_update_post_process_config(&config);
225+
226+
// Execute post-processing if any effects are enabled
227+
if (config.enabledEffects != 0) {
228+
vk_execute_post_processing(&config);
229+
}
230+
}
231+
#endif
204232
}
205233

206234

src/renderers/vulkan/tr_renderer_vulkan.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Vulkan implementation of the unified renderer interface.
1111
#include "tr_local.h"
1212
#include "vk.h"
1313

14+
// Forward declarations for scene functions
15+
extern void RE_AddLightToScene(const vec3_t org, float intensity, float r, float g, float b);
16+
extern void RE_AddAdditiveLightToScene(const vec3_t org, float intensity, float r, float g, float b);
17+
1418
// Forward declarations for Vulkan-specific functions
1519
extern qboolean vk_initialize(void);
1620
extern void vk_shutdown(void);
@@ -66,12 +70,26 @@ static void Vulkan_AddPolygon(qhandle_t shader, int numVerts, const polyVert_t*
6670
}
6771

6872
static void Vulkan_AddLight(const dlight_t* light) {
69-
// Vulkan lighting integration
70-
// This would need to be implemented based on Vulkan lighting system
73+
// Vulkan lighting integration - delegate to RE_AddLightToScene
74+
if (!light) {
75+
return;
76+
}
77+
78+
// Use additive mode if light->additive is set, otherwise use normal mode
79+
if (light->additive) {
80+
RE_AddAdditiveLightToScene(light->origin, light->radius,
81+
light->color[0], light->color[1], light->color[2]);
82+
} else {
83+
RE_AddLightToScene(light->origin, light->radius,
84+
light->color[0], light->color[1], light->color[2]);
85+
}
7186
}
7287

7388
static void Vulkan_SetupLighting(void) {
7489
// Setup Vulkan lighting state
90+
// Lighting setup is handled automatically during scene rendering
91+
// This function provides a hook for any pre-render lighting configuration
92+
// Currently no-op as lighting is set up per-frame in vk_render_scene
7593
}
7694

7795
static qhandle_t Vulkan_RegisterShader(const char* name) {
@@ -127,10 +145,14 @@ static void Vulkan_RenderSurfaces(void) {
127145

128146
static void Vulkan_BeginPostProcess(void) {
129147
// Vulkan post-processing begin
148+
// Post-processing setup is handled automatically in vk_end_frame
149+
// This function provides a hook for any pre-post-process configuration
130150
}
131151

132152
static void Vulkan_EndPostProcess(void) {
133153
// Vulkan post-processing end
154+
// Post-processing finalization is handled automatically in vk_end_frame
155+
// This function provides a hook for any post-post-process cleanup
134156
}
135157

136158
static void Vulkan_DebugDrawAxis(void) {
Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
1-
// Direct Vulkan helper bindings (Plan D baseline, minimal no-ops)
1+
/*
2+
=============================================================================
3+
Direct Vulkan Helper Bindings (Plan D baseline)
4+
=============================================================================
5+
Minimal stub implementations for direct Vulkan API access.
6+
These are weak symbols that can be overridden by real implementations
7+
in vk_command_buffers.cpp and vk_swapchain.cpp.
8+
9+
Note: Real implementations are provided in:
10+
- vk_command_buffers.cpp: vk_begin_command_buffer, vk_end_command_buffer
11+
- vk_swapchain.cpp: vk_destroy_swapchain
12+
=============================================================================
13+
*/
14+
215
#include <stdint.h>
316
#include <vulkan/vulkan.h>
417

518
#ifdef __cplusplus
619
extern "C" {
720
#endif
8-
VkCommandBuffer vk_begin_command_buffer(void) { return VK_NULL_HANDLE; }
9-
void vk_end_command_buffer(VkCommandBuffer cb, const char* location) { (void)cb; (void)location; }
10-
void vk_destroy_swapchain(void) { }
11-
#ifdef __cplusplus
21+
22+
// Stub implementations - real versions are in vk_command_buffers.cpp
23+
VkCommandBuffer vk_begin_command_buffer(void) {
24+
// Real implementation in vk_command_buffers.cpp allocates and begins recording
25+
return VK_NULL_HANDLE;
1226
}
13-
#endif
1427

15-
#ifdef __GNUC__
16-
#define WEAK __attribute__((weak))
17-
#else
18-
#define WEAK
19-
#endif
20-
WEAK VkSurfaceFormatKHR vk_present_format = {};
28+
void vk_end_command_buffer(VkCommandBuffer cb, const char* location) {
29+
// Real implementation in vk_command_buffers.cpp ends recording and submits
30+
(void)cb;
31+
(void)location;
32+
}
2133

22-
// Direct Vulkan helper bindings (Plan D baseline, minimal no-ops)
23-
#include <stdint.h>
24-
#include <vulkan/vulkan.h>
34+
// Stub implementation - real version is in vk_swapchain.cpp
35+
void vk_destroy_swapchain(void) {
36+
// Real implementation in vk_swapchain.cpp destroys swapchain and related resources
37+
}
2538

26-
#ifdef __cplusplus
27-
extern "C" {
28-
#endif
29-
VkCommandBuffer vk_begin_command_buffer(void) { return VK_NULL_HANDLE; }
30-
void vk_end_command_buffer(VkCommandBuffer cb, const char* location) { (void)cb; (void)location; }
31-
void vk_destroy_swapchain(void) { }
3239
#ifdef __cplusplus
3340
}
3441
#endif
@@ -38,5 +45,7 @@ void vk_destroy_swapchain(void) { }
3845
#else
3946
#define WEAK
4047
#endif
48+
49+
// Weak symbol for present format - can be overridden by real implementation
4150
WEAK VkSurfaceFormatKHR vk_present_format = {};
4251

0 commit comments

Comments
 (0)