Skip to content

feat(graphic): add deferred pass#434

Merged
Miou-zora merged 10 commits into
mainfrom
add-deferred-pass
Jan 24, 2026
Merged

feat(graphic): add deferred pass#434
Miou-zora merged 10 commits into
mainfrom
add-deferred-pass

Conversation

@Miou-zora

@Miou-zora Miou-zora commented Jan 24, 2026

Copy link
Copy Markdown
Contributor

This pull request introduces a new Deferred render pass and refactors the camera GPU buffer to support more advanced rendering features, specifically for deferred shading. It also removes legacy/default render pipeline code and updates the GBuffer pass to use the enhanced camera data structure. The main focus is on enabling deferred rendering with physically plausible point light attenuation and better camera data handling.

Deferred Rendering Pipeline Enhancements:

  • Added a new Deferred render pass (Deferred.hpp) that implements a deferred shading pipeline, including a WGSL shader for physically plausible point light attenuation and improved lighting calculations.
  • Updated the GBuffer pass (GBuffer.hpp) to output additional camera data (inverse view-projection matrix and camera position) required for deferred shading, and to use the new camera buffer structure. [1] [2]

Camera Buffer Improvements:

  • Refactored CameraGPUBuffer to include the camera's inverse view-projection matrix and position, and updated its interface and buffer layout to match the requirements of deferred rendering. [1] [2] [3] [4]
  • Updated all usages of the camera buffer to use the new structure, including buffer creation and updates in the render pipeline and system code. [1] [2] [3] [4]

Code Cleanup and Legacy Removal:

  • Removed references and registration of the old default render pipeline, including CreateDefaultRenderPipeline and related utilities, to streamline the initialization and reduce confusion. [1] [2] [3] [4] [5]

General Integration:

  • Integrated the new Deferred and updated GBuffer passes into the pipeline, ensuring correct bind group and buffer usage for both camera and lighting data. [1] [2] [3] [4] [5] [6]

These changes lay the groundwork for a modern deferred rendering pipeline, supporting more complex lighting and shading effects while simplifying and modernizing the codebase.

Summary by CodeRabbit

  • New Features

    • Added a deferred render pass with G‑buffer lighting (ambient + point lights).
    • Camera buffer now includes additional transform data for improved rendering.
    • Test output now saves the deferred-pass image.
  • Refactors

    • Rendering pipeline converted from single-pass to multi-pass (G‑buffer → Deferred).
    • Bind groups and shader usage made explicit with names/IDs for clearer resource mapping.
  • Removals

    • Legacy default render pass and its automatic pipeline creation removed.

✏️ Tip: You can customize this high-level summary in your review settings.

@Miou-zora Miou-zora requested a review from a team January 24, 2026 13:56
@Miou-zora Miou-zora self-assigned this Jan 24, 2026
@coderabbitai

coderabbitai Bot commented Jan 24, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@Miou-zora has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 28 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

Replaces the legacy DefaultRenderPass and its creation with a G-buffer + Deferred render pass pipeline, updates BindGroup API to accept a name label, extends camera GPU buffer with CameraTransfer, and wires deferred textures, shader IDs, and bind-groups across initialization and GPU component setup.

Changes

Cohort / File(s) Summary
Deferred render pass
src/plugin/default-pipeline/src/resource/pass/Deferred.hpp
New Deferred render-pass class, WGSL deferred shader, shader creation, bind-group layouts (camera, G-buffer textures, lights), and full-screen render callback.
Render graph & initialization
src/plugin/default-pipeline/src/system/initialization/Create3DGraph.cpp, .../Create3DGraph.hpp
Adds deferred output texture descriptors and binding group, inserts DEFERRED pass with dependency GBUFFER → DEFERRED, and recreates deferred resources on resize.
Removed legacy default pass
src/plugin/default-pipeline/src/utils/DefaultRenderPass.hpp, src/plugin/default-pipeline/src/system/initialization/CreateDefaultRenderPipeline.*
Removes DefaultRenderPass implementation and CreateDefaultRenderPipeline API/implementation.
BindGroup API & labeling
src/plugin/graphic/src/resource/BindGroup.hpp, src/plugin/graphic/tests/BindGroupTest.cpp, src/plugin/graphic/tests/RenderPassTest.cpp
BindGroup constructor now accepts a name (std::string_view) stored as _name and used as GPU label; call sites/tests updated to supply the name argument.
BindGroup usage updates
src/plugin/default-pipeline/src/system/GPUComponentManagement/OnCameraCreation.cpp, OnMaterialCreation.cpp, OnTransformCreation.cpp, .../CreateDefaultMaterial.cpp, CreatePointLights.cpp
Updated BindGroup construction calls to pass bind-group name and explicit shader IDs (GBUFFER/DEFERRED); lights bind-group binding counts/names adjusted.
Camera buffer & GBuffer changes
src/plugin/default-pipeline/src/resource/buffer/CameraGPUBuffer.hpp, src/plugin/default-pipeline/src/resource/pass/GBuffer.hpp
Introduces CameraTransfer (viewProjection, invViewProjection, position), sizes camera bind accordingly, updates shader camera layout and visibility, and disables culling for GBuffer.
Ambient/Point lights wiring
src/plugin/default-pipeline/src/resource/AmbientLight.cpp, src/plugin/default-pipeline/src/system/initialization/CreatePointLights.cpp
Removes legacy include; rewire lights bind-group to use DEFERRED shader ID and updated two-entry binding (ambient + point-lights).
Tests
src/plugin/default-pipeline/tests/shader/GBufferTest.cpp
Adds ambient and point-light entities; extracts/writes deferred output image; removes manual GBuffer execution hook.
Shader labeling
src/plugin/graphic/src/resource/Shader.hpp
Adjusts bind-group layout label formatting to "{}::{}".

Sequence Diagram

sequenceDiagram
    participant Engine as Engine::Core
    participant RG as RenderGraph
    participant GBUF as GBuffer Pass
    participant GBTEX as G-Buffer Textures
    participant DEFER as Deferred Pass
    participant LIGHTS as Lights Buffers
    participant OUT as Frame Output

    Engine->>RG: Build render graph (GBUFFER, DEFERRED)
    RG->>GBUF: Execute GBuffer pass
    GBUF->>GBTEX: Write albedo/normal/position/depth
    RG->>DEFER: Execute Deferred pass (depends on GBuffer)
    DEFER->>GBTEX: Read G-Buffer textures
    DEFER->>LIGHTS: Read ambient & point-light buffers
    DEFER->>OUT: Shade fragments and write final color
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • Divengerss
  • ripel2

Poem

🐇 I hop through G-buffers, eager and spry,

Albedo, normal, and depth pass by,
Two-stage lights bloom where one used to be,
Named bind-groups make tracing joyfully free,
Deferred sunsets rendered — hip-hop-hooray!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 19.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat(graphic): add deferred pass' directly and concisely describes the main change—introducing a new Deferred render pass. It is clear, specific, and properly conveys the primary contribution of the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Miou-zora

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jan 24, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Miou-zora Miou-zora removed the request for review from a team January 24, 2026 14:36
@Miou-zora

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jan 24, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/plugin/default-pipeline/src/plugin/PluginDefaultPipeline.cpp (1)

23-25: Outdated documentation: docstring references removed system.

The docstring mentions CreateDefaultRenderPipeline which has been removed from the setup systems. Update the documentation to reflect the current registration.

📝 Suggested fix
- * The setup systems registered include: CreateDefaultRenderPipeline, Create3DGraph,
- * CreateDefaultMaterial, CreateAmbientLight, and CreatePointLights.
+ * The setup systems registered include: Create3DGraph, CreateDefaultMaterial,
+ * CreateAmbientLight, and CreatePointLights.
src/plugin/default-pipeline/src/system/GPUComponentManagement/OnMaterialCreation.cpp (1)

58-66: Use Resource::GBUFFER_SHADER_ID instead of hardcoded "DEFAULT_RENDER_PASS_SHADER" string.

The material bind group structure (buffer, texture, sampler) matches the GBuffer shader's material layout (group 2, bindings 0–2). Using the string literal "DEFAULT_RENDER_PASS_SHADER" will fail to resolve at runtime since the default render pass was removed. Replace with Resource::GBUFFER_SHADER_ID and add the required include:

🐛 Proposed fix
+#include "resource/pass/GBuffer.hpp"
-    Graphic::Resource::BindGroup bindGroup(core, bindGroupName, "DEFAULT_RENDER_PASS_SHADER", 2,
+    Graphic::Resource::BindGroup bindGroup(core, bindGroupName, Resource::GBUFFER_SHADER_ID, 2,
🤖 Fix all issues with AI agents
In `@src/plugin/default-pipeline/src/resource/buffer/CameraGPUBuffer.hpp`:
- Around line 15-28: Change the CameraTransfer layout to use glm::vec4 for
position, remove the manual "+ sizeof(float)" in GPUSize(), and add a
static_assert to guarantee CPU and GPU sizes match; specifically modify the
CameraTransfer struct (field position -> glm::vec4), update
CameraTransfer::GPUSize() to return sizeof(CameraTransfer) only, and add a
static_assert(sizeof(CameraTransfer) == CameraTransfer::GPUSize()) (or
equivalent) to document and enforce the expected alignment/size invariants so
CPUSize() and GPUSize() are identical.
🧹 Nitpick comments (2)
src/plugin/default-pipeline/src/resource/pass/Deferred.hpp (1)

31-33: Use a distinct name/ID for the deferred textures bind group.
Right now it reuses the shader name/ID, which is confusing and risks key collisions in BindGroupManager. Consider giving it its own label.

♻️ Suggested rename
-static inline constexpr std::string_view DEFERRED_BINDGROUP_TEXTURES_NAME = "DEFERRED_SHADER";
-static inline const entt::hashed_string DEFERRED_BINDGROUP_TEXTURES_ID =
-    entt::hashed_string{DEFERRED_SHADER_NAME.data(), DEFERRED_SHADER_NAME.size()};
+static inline constexpr std::string_view DEFERRED_BINDGROUP_TEXTURES_NAME = "DEFERRED_BINDGROUP_TEXTURES";
+static inline const entt::hashed_string DEFERRED_BINDGROUP_TEXTURES_ID{
+    DEFERRED_BINDGROUP_TEXTURES_NAME.data(), DEFERRED_BINDGROUP_TEXTURES_NAME.size()};
src/plugin/default-pipeline/src/system/initialization/Create3DGraph.cpp (1)

141-166: Remove unused DEFERRED_PASS_OUTPUT_ID texture creation.

The deferred pass renders to END_RENDER_TEXTURE_ID (line 262), not DEFERRED_PASS_OUTPUT_ID. The latter is created with a resize callback but never consumed in production code—only in the test file GBufferTest.cpp. This incurs unnecessary GPU allocation and resize overhead that can be eliminated.

Comment thread src/plugin/default-pipeline/src/resource/buffer/CameraGPUBuffer.hpp
@Miou-zora Miou-zora marked this pull request as ready for review January 24, 2026 16:07

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/plugin/default-pipeline/src/system/initialization/Create3DGraph.cpp`:
- Around line 71-81: Remove the unused helper
CreateDeferredPassOutputTextureDescriptor: locate the function
CreateDeferredPassOutputTextureDescriptor in Create3DGraph.cpp and delete it
along with any related unused includes or forward declarations; ensure no
remaining references to this function exist (the deferred pass already outputs
to END_RENDER_TEXTURE_ID at the deferred pass creation), and run a build to
confirm no symbols remain referencing the removed function.
🧹 Nitpick comments (3)
src/plugin/default-pipeline/src/resource/pass/GBuffer.hpp (1)

242-242: Consider if disabling backface culling is intentional.

CullMode::None disables backface culling, which renders both front and back faces. While this can be useful for specific effects (e.g., two-sided foliage), it may impact performance for typical opaque geometry. If this is intentional, a comment explaining the rationale would be helpful.

src/plugin/default-pipeline/src/system/initialization/Create3DGraph.cpp (1)

143-144: Remove unused variable.

shaderContainer is obtained but never used in CreateDeferredTexturesBindingGroup.

🔧 Proposed fix
 static void CreateDeferredTexturesBindingGroup(Engine::Core &core)
 {
     const auto &context = core.GetResource<Graphic::Resource::Context>();
-    auto &shaderContainer = core.GetResource<Graphic::Resource::ShaderContainer>();
src/plugin/default-pipeline/src/resource/pass/Deferred.hpp (1)

159-161: Unused variable V - remove or implement specular lighting.

The view direction V is computed but never used. If specular lighting is planned, consider implementing it; otherwise, remove this dead code.

🔧 Proposed fix (remove unused variable)
     let N = normalize(normal);
-    let V = normalize(camera.position - position);

     var lighting = ambientLight.color;

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
8.4% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@Miou-zora Miou-zora merged commit c089b19 into main Jan 24, 2026
14 of 15 checks passed
@Miou-zora Miou-zora deleted the add-deferred-pass branch January 24, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants