8000 Support FXAA and linear space color blend by hhhhkrx · Pull Request #2605 · galacean/engine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support FXAA and linear space color blend #2605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 59 commits into from
Apr 24, 2025
Merged

Conversation

hhhhkrx
Copy link
Contributor
@hhhhkrx hhhhkrx commented Apr 8, 2025

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Other information:

Summary by CodeRabbit

  • New Features

    • Added support for configurable anti-aliasing modes, including FXAA, for cameras.
    • Introduced a final post-processing pass with optional FXAA anti-aliasing and sRGB color space conversion.
    • Made the anti-aliasing configuration accessible via the public API.
    • Enhanced post-processing pipeline to conditionally apply final pass and manage output render targets.
    • Improved rendering pipeline to handle HDR and opaque texture formats more explicitly.
  • Tests

    • Added a new end-to-end test case demonstrating FXAA, bloom, and tonemapping effects.
    • Updated test configuration to include the new FXAA scenario.

Copy link
coderabbitai bot commented Apr 8, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • e2e/fixtures/originImage/Camera_camera-fxaa.jpg is excluded by !**/*.jpg

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This update introduces a new anti-aliasing feature to the rendering pipeline by adding an AntiAliasing enum and integrating a FinalPass post-processing class. The Camera class now has an antiAliasing property, allowing configuration of anti-aliasing modes, including FXAA. The FinalPass class is incorporated into the engine's post-process pipeline, applying sRGB conversion and optional FXAA based on camera settings. The BasicRenderPipeline and PostProcessManager are updated to support conditional final pass rendering and output render target management. The public API is expanded to export these new entities. Additionally, an end-to-end test case and its configuration for FXAA are added to validate the feature. Minor shader changes disable sRGB correction in some shaders to align with the new pipeline.

Changes

File(s) Change Summary
packages/core/src/enums/AntiAliasing.ts Introduced new AntiAliasing enum with None and FXAA options.
packages/core/src/Camera.ts Added public antiAliasing property to Camera class, defaulting to AntiAliasing.None. Added internal methods _needFinalPass(), _getTargetColorTextureFormat(), and _isTargetFormatHDR(). Updated independentCanvasEnabled getter logic.
packages/core/src/postProcess/FinalPass.ts Added new FinalPass class for final post-processing with sRGB and FXAA support, managing materials and render targets, including shader additions.
packages/core/src/postProcess/index.ts Exported FinalPass from the post-process module.
packages/core/src/index.ts Exported AntiAliasing enum from the core module's public API.
packages/core/src/Engine.ts Imported FinalPass class; no other functional changes.
packages/core/src/RenderPipeline/BasicRenderPipeline.ts Added private _finalPass member and instantiated it. Modified _drawRenderPass to conditionally render final pass, manage output render targets, and blit accordingly. Removed previous direct blit.
packages/core/src/postProcess/PostProcessManager.ts Added private _outputRenderTarget member and internal methods _releaseOutputRenderTarget() and _getOutputRenderTarget(camera) for managing output render target lifecycle.
e2e/case/camera-fxaa.ts Added new end-to-end test case for camera FXAA post-processing, configuring bloom and tonemapping effects.
e2e/config.ts Added new test configuration entry for FXAA under the Camera category.
e2e/case/camera-opaque-texture.ts Removed sRGB correction call in fragment shader of "RenderOpaqueTexture" shader.
e2e/case/material-shaderReplacement.ts Removed sRGB correction call in fragment shader of UV check shader.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant Camera
    participant Engine
    participant BasicRenderPipeline
    participant PostProcessManager
    participant FinalPass

    App->>Camera: Set antiAliasing = FXAA
    App->>Engine: Initialize Engine
    Engine->>BasicRenderPipeline: Instantiate with FinalPass
    BasicRenderPipeline->>PostProcessManager: Render post-process with output target
    BasicRenderPipeline->>Camera: Check _needFinalPass()
    alt _needFinalPass() == true
        BasicRenderPipeline->>FinalPass: Configure and render final pass
        FinalPass->>Camera: Check antiAliasing property
        alt antiAliasing == FXAA
            FinalPass->>FinalPass: Apply sRGB conversion
            FinalPass->>FinalPass: Apply FXAA shader
        else
            FinalPass->>FinalPass: Apply sRGB conversion only
        end
        FinalPass->>BasicRenderPipeline: Return processed frame
        BasicRenderPipeline->>Camera: Blit final output if needed
    else
        BasicRenderPipeline->>PostProcessManager: Render post-process directly to camera target
    end
Loading

Suggested labels

post processing, pipeline

Suggested reviewers

  • hhhhkrx

Poem

In the land of pixels, crisp and bright,
A FinalPass hops into sight.
With FXAA’s gentle, fuzzy touch,
Jagged lines don’t matter much!
Cameras now with choices gleam,
sRGB and bloom—what a dream!
A bunny cheers this rendering scene! 🐇✨


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
e2e/case/postProcess-fxaa.ts (1)

17-36: Eliminate unused dirtTexture or integrate it
Currently, dirtTexture is destructured from the resource array but never used. Consider removing it or applying it if intended:

-  const [_, __, dirtTexture] = resArray;
+  const [_, __] = resArray;
packages/core/src/postProcess/PostProcessFinalPass.ts (1)

33-44: Potential overhead from toggling FXAA macro each frame
Enabling and disabling shader macros in onRender can incur extra overhead from potential shader variant switches. If performance becomes a concern, consider caching or reducing toggles.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6bc9fcc and 3ae6eca.

⛔ Files ignored due to path filters (3)
  • packages/core/src/postProcess/shaders/FXAA/FXAA3_11.glsl is excluded by !**/*.glsl
  • packages/core/src/postProcess/shaders/FinalPost.glsl is excluded by !**/*.glsl
  • packages/core/src/postProcess/shaders/PostCommon.glsl is excluded by !**/*.glsl
📒 Files selected for processing (8)
  • e2e/case/postProcess-fxaa.ts (1 hunks)
  • packages/core/src/Camera.ts (2 hunks)
  • packages/core/src/Engine.ts (2 hunks)
  • packages/core/src/enums/AntiAliasing.ts (1 hunks)
  • packages/core/src/index.ts (1 hunks)
  • packages/core/src/postProcess/PostProcessFinalPass.ts (1 hunks)
  • packages/core/src/postProcess/PostProcessPass.ts (1 hunks)
  • packages/core/src/postProcess/index.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
packages/core/src/Engine.ts (2)
packages/core/src/postProcess/PostProcessFinalPass.ts (1)
  • PostProcessFinalPass (15-45)
packages/core/src/postProcess/index.ts (1)
  • PostProcessFinalPass (19-19)
packages/core/src/postProcess/PostProcessFinalPass.ts (5)
packages/core/src/postProcess/index.ts (3)
  • PostProcessFinalPass (19-19)
  • PostProcessPass (17-17)
  • PostProcessPassEvent (17-17)
packages/core/src/index.ts (3)
  • Engine (2-2)
  • Camera (16-16)
  • AntiAliasing (77-77)
packages/core/src/Engine.ts (1)
  • Engine (52-693)
packages/core/src/texture/Texture2D.ts (1)
  • Texture2D (12-185)
packages/core/src/texture/RenderTarget.ts (1)
  • RenderTarget (11-245)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e (22.x)
🔇 Additional comments (10)
packages/core/src/postProcess/index.ts (1)

19-19: Good addition of the PostProcessFinalPass export.

The export follows the existing pattern and makes the new post-processing class available for use throughout the application.

packages/core/src/enums/AntiAliasing.ts (1)

1-9: Well-structured anti-aliasing enum with proper documentation.

The enum provides clear options for anti-aliasing configuration with proper JSDoc comments explaining each option's purpose. This follows the project's established patterns for enum definitions.

packages/core/src/index.ts (1)

77-77: Appropriate export of the AntiAliasing enum.

The export makes the new AntiAliasing enum available throughout the module and is placed appropriately among other enum exports.

packages/core/src/Camera.ts (2)

20-20: Good import addition for AntiAliasing enum.

The import is correctly placed with related imports and follows the established pattern in the file.


98-104: Well-documented antiAliasing property added to Camera class.

The property extends the camera's functionality by allowing per-camera anti-aliasing configuration using the newly defined AntiAliasing enum. The property has proper JSDoc comments and a sensible default value.

packages/core/src/postProcess/PostProcessPass.ts (1)

14-17: Use of Number.MAX_SAFE_INTEGER for the final pass
Assigning Final to Number.MAX_SAFE_INTEGER effectively ensures this pass executes last. This approach appears consistent with the intended purpose.

packages/core/src/Engine.ts (2)

33-33: New import of PostProcessFinalPass
The import statement correctly references the new final pass class, no issues.


275-277: Final pass appended after the uber pass
Instantiating and adding PostProcessFinalPass ensures it runs at the end of the post-processing chain.

packages/core/src/postProcess/PostProcessFinalPass.ts (2)

15-19: New final pass class
This class correctly extends PostProcessPass and initializes a final material. Implementation looks solid.


47-52: Shader injection and creation
Appending PostCommon and FXAA3_11 to ShaderLib and invoking Shader.create for the final post shader follows a coherent design.

@hhhhkrx hhhhkrx self-assigned this Apr 9, 2025
@hhhhkrx hhhhkrx added the rendering Rendering related functions label Apr 9, 2025
Copy link
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/core/src/postProcess/PostProcessFinalPass.ts (2)

43-53: Optionally skip final pass when FXAA is not used.

If this pass is specifically for FXAA (and does not handle any other effects), you can skip it to save performance when FXAA is disabled:

override isValid(): boolean {
  if (!this.isActive) {
    return false;
  }
+ const camera = this._engine.sceneManager.activeCamera;
+ const enableFXAA = camera?.antiAliasing === AntiAliasing.FastApproximateAntiAliasing;
+ return enableFXAA;
}

57-63: Add test coverage for the final pass.

No tests were found for this newly added class. Consider adding a unit or integration test to ensure the final pass behavior is correct, especially under different anti-aliasing and HDR settings.

I can provide a sample test snippet if you’d like. Just let me know!

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ae6eca and c50ca30.

⛔ Files ignored due to path filters (3)
  • packages/core/src/postProcess/shaders/FXAA/FXAA3_11.glsl is excluded by !**/*.glsl
  • packages/core/src/postProcess/shaders/FinalPost.glsl is excluded by !**/*.glsl
  • packages/core/src/postProcess/shaders/PostCommon.glsl is excluded by !**/*.glsl
📒 Files selected for processing (3)
  • packages/core/src/Camera.ts (2 hunks)
  • packages/core/src/Engine.ts (2 hunks)
  • packages/core/src/postProcess/PostProcessFinalPass.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/core/src/Engine.ts
  • packages/core/src/Camera.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/src/postProcess/PostProcessFinalPass.ts (3)
packages/core/src/postProcess/index.ts (3)
  • PostProcessFinalPass (19-19)
  • PostProcessPass (17-17)
  • PostProcessPassEvent (17-17)
packages/core/src/Engine.ts (1)
  • Engine (52-701)
packages/core/src/index.ts (3)
  • Engine (2-2)
  • Camera (16-16)
  • AntiAliasing (77-77)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e (22.x)
🔇 Additional comments (1)
packages/core/src/postProcess/PostProcessFinalPass.ts (1)

26-28: Good job disabling depth test and write.

This addresses a previous concern about ensuring the final blit operation is not affected by depth testing.

Copy link
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
packages/core/src/postProcess/PostProcessFinalPass.ts (1)

33-38: Check camera anti-aliasing in isValid() to skip unnecessary overhead.

Currently, isValid() only checks isActive, but the pass will still be queued even if the camera is not using FXAA. As previously suggested, consider returning false from isValid() if camera.antiAliasing !== AntiAliasing.FastApproximateAntiAliasing. That way, the engine won’t include this pass at all when FXAA is disabled, improving performance.

🧹 Nitpick comments (1)
packages/core/src/postProcess/PostProcessFinalPass.ts (1)

57-61: Add tests to ensure correct shader setup.

Registering FXAA3_11 with ShaderLib and creating the final shader is a crucial step for FXAA. Consider adding automated tests to validate:

  1. Macros are properly enabled/disabled based on camera settings.
  2. The final blit is performed as intended.

Would you like help outlining unit or integration tests for this final pass?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1a7e046 and 24dd855.

📒 Files selected for processing (1)
  • packages/core/src/postProcess/PostProcessFinalPass.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/src/postProcess/PostProcessFinalPass.ts (3)
packages/core/src/postProcess/index.ts (3)
  • PostProcessFinalPass (19-19)
  • PostProcessPass (17-17)
  • PostProcessPassEvent (17-17)
packages/core/src/Engine.ts (1)
  • Engine (52-701)
packages/core/src/index.ts (3)
  • Engine (2-2)
  • Camera (16-16)
  • AntiAliasing (77-77)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e (22.x)
🔇 Additional comments (1)
packages/core/src/postProcess/PostProcessFinalPass.ts (1)

25-29: Good job disabling depth test and write.

By setting enabled = false and writeEnabled = false for the depth state, you’re effectively ensuring this final blit operation doesn’t interfere with depth. This aligns with the prior feedback to force the blit onto the camera’s render target without depth conflicts.

Copy link
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
packages/core/src/postProcess/PostProcessFinalPass.ts (2)

33-39: 🛠️ Refactor suggestion

Override isActive method to prevent undesired state modifications.

The isActive property from PostProcessPass can still be read and written by users, potentially causing undesired behavior. You should override the isActive method if you want this pass to always be valid.

+  /**
+   * @override
+   * @returns Always returns true since this pass should always be active
+   */
+  get isActive(): boolean {
+    return true;
+  }
+
+  /**
+   * @override
+   * @hidden
+   */
+  set isActive(value: boolean) {
+    // Do nothing to prevent disabling this pass
+  }

  /** @inheritdoc */
  override isValid(): boolean {
    if (!this.isActive) {
      return false;
    }
    return PostProcessFinalPass._camera?.antiAliasing === AntiAliasing.FastApproximateAntiAliasing;
  }

41-52: 🛠️ Refactor suggestion

Optimize render logic by removing redundant FXAA macro enabling.

The current implementation enables the FXAA macro in onRender() regardless of the camera's anti-aliasing settings, even though isValid() already checks for AntiAliasing.FastApproximateAntiAliasing. This is inefficient and could lead to unexpected behavior.

Additionally, the method doesn't capture the camera parameter to update the static _camera property, which is used in isValid().

  override onRender(camera: Camera, srcTexture: Texture2D, destTarget: RenderTarget): void {
+   // Update static camera reference
+   PostProcessFinalPass._camera = camera;
+   
    const material = this._finalMaterial;

-   material.shaderData.enableMacro(PostProcessFinalPass._fxaaEnabledMacro);
+   // Only enable FXAA if the camera has it enabled
+   if (camera.antiAliasing === AntiAliasing.FastApproximateAntiAliasing) {
+     material.shaderData.enableMacro(PostProcessFinalPass._fxaaEnabledMacro);
+   } else {
+     material.shaderData.disableMacro(PostProcessFinalPass._fxaaEnabledMacro);
+   }
+   
    if (camera.enableHDR) {
      material.shaderData.enableMacro(PostProcessFinalPass._hdrInputMacro);
    } else {
      material.shaderData.disableMacro(PostProcessFinalPass._hdrInputMacro);
    }

    Blitter.blitTexture(camera.engine, srcTexture, destTarget, 0, camera.viewport, material);
  }
🧹 Nitpick comments (1)
packages/core/src/postProcess/PostProcessFinalPass.ts (1)

55-59: Consider error handling for shader creation.

The static shader initialization at the end of the file has no error handling. If the shader creation fails, there would be no indication of the failure, which could make debugging difficult.

-Object.assign(ShaderLib, {
-  FXAA3_11
-});
+try {
+  Object.assign(ShaderLib, {
+    FXAA3_11
+  });
+  
+  Shader.create(PostProcessFinalPass.FINAL_SHADER_NAME, blitVs, FinalPost);
+} catch (error) {
+  console.error("Failed to initialize PostProcessFinalPass shaders:", error);
+}
-
-Shader.create(PostProcessFinalPass.FINAL_SHADER_NAME, blitVs, FinalPost);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24dd855 and b2e663c.

📒 Files selected for processing (1)
  • packages/core/src/postProcess/PostProcessFinalPass.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/src/postProcess/PostProcessFinalPass.ts (3)
packages/core/src/postProcess/index.ts (3)
  • PostProcessFinalPass (19-19)
  • PostProcessPass (17-17)
  • PostProcessPassEvent (17-17)
packages/core/src/index.ts (3)
  • Camera (16-16)
  • Engine (2-2)
  • AntiAliasing (77-77)
packages/core/src/Engine.ts (1)
  • Engine (52-701)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e (22.x)
🔇 Additional comments (1)
packages/core/src/postProcess/PostProcessFinalPass.ts (1)

26-29: Good job implementing the depth state settings.

The implementation correctly disables depth test and depth write, which forces blitting to the camera's render target.

Copy link
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/core/src/postProcess/PostProcessFinalPass.ts (1)

35-39: Unify FXAA checks in isValid with onRender to avoid redundancy.
Currently, isValid prevents the pass from running unless FXAA is enabled via the static _camera. Yet onRender again checks if _camera has FastApproximateAntiAliasing before setting shader macros. You can remove the second check or unify everything in isValid to streamline logic and avoid repeated conditions.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b2e663c and 506e237.

📒 Files selected for processing (1)
  • packages/core/src/postProcess/PostProcessFinalPass.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/src/postProcess/PostProcessFinalPass.ts (3)
packages/core/src/postProcess/index.ts (3)
  • PostProcessFinalPass (19-19)
  • PostProcessPass (17-17)
  • PostProcessPassEvent (17-17)
packages/core/src/index.ts (3)
  • Camera (16-16)
  • Engine (2-2)
  • AntiAliasing (77-77)
packages/core/src/Engine.ts (1)
  • Engine (52-701)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e (22.x)
🔇 Additional comments (1)
packages/core/src/postProcess/PostProcessFinalPass.ts (1)

61-65: Neat integration of shader code.
Registering FXAA3_11 into ShaderLib and creating the final shader is a clear and straightforward approach. This setup ensures the FXAA shader is properly recognized and available for the pass.

Copy link
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 506e237 and f2851b2.

📒 Files selected for processing (1)
  • packages/core/src/postProcess/PostProcessFinalPass.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/src/postProcess/PostProcessFinalPass.ts (3)
packages/core/src/postProcess/index.ts (3)
  • PostProcessFinalPass (19-19)
  • PostProcessPass (17-17)
  • PostProcessPassEvent (17-17)
packages/core/src/index.ts (3)
  • Camera (16-16)
  • Engine (2-2)
  • AntiAliasing (77-77)
packages/core/src/Engine.ts (1)
  • Engine (52-701)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e (22.x)
🔇 Additional comments (1)
packages/core/src/postProcess/PostProcessFinalPass.ts (1)

27-29: Depth testing correctly disabled.

Thank you for disabling depth testing and depth writing. This fully addresses the previous recommendation to ensure a clean blit operation without unintended depth interference.

Copy link
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
packages/core/src/postProcess/PostProcessFinalPass.ts (4)

15-17: Preserve clarity by adding doc comments for static macro properties.

These macros (_fxaaEnabledMacro and _hdrInputMacro) are central to the post-processing configuration. A short comment explaining their intended usage (e.g., enabling FXAA, toggling HDR input) can help future maintainers.


42-44: Avoid storing the camera reference unless needed across frames.

Assigning this._camera each time may cause unexpected behavior in multi-camera scenarios if the engine reuses the same pass instance. Confirm whether this pass is per-camera or shared. If shared, store camera data in local variables within onRender() to avoid accidental cross-camera usage.


47-57: Macrotoggling might be repeated across multiple frames.

Enabling and disabling macros each frame can be slightly inefficient if these toggles don’t change often. Consider caching the previous state of enableFXAA/enableHDR to skip toggling if the value remains the same.


67-67: Consider surfacing shader compile errors.

If Shader.create fails or logs warnings, it may silently break the final pass. Consider adding simple error-handling or debug logs to quickly identify issues in production.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f2851b2 and 5b2d7ac.

📒 Files selected for processing (1)
  • packages/core/src/postProcess/PostProcessFinalPass.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e (22.x)
🔇 Additional comments (3)
packages/core/src/postProcess/PostProcessFinalPass.ts (3)

21-31: Acknowledgment: Depth test & write disabled as requested.

Thanks for honoring the previous feedback to disable depth test and write in the final pass. This ensures the pass always properly overwrites the final render target without depth interference.


34-40: Potential confusion when isValid() is called before _camera assignment.

isValid() checks _camera?.antiAliasing but _camera is only assigned inside onRender(). If isValid() is called earlier in the pipeline (before onRender()), _camera will be undefined and the pass will always return false.
If that’s intentional, please confirm; otherwise, assign _camera sooner or reconsider how isValid() retrieves the active camera.


63-65: Ensure that newly added shaders are compatible with existing pipeline.

While extending ShaderLib is straightforward, confirm that FXAA3_11 doesn’t conflict with other passes. For instance, if PostCommon or UberPass is used in other parts of the pipeline, ensure they don’t inadvertently override or disable this new shader code.

@GuoLei1990 GuoLei1990 changed the title support fxaa Support fxaa Apr 16, 2025
@GuoLei1990 GuoLei1990 added the enhancement New feature or request label Apr 16, 2025
Copy link
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
packages/core/src/postProcess/PostProcessFinalPass.ts (1)

21-31: Constructor implementation is appropriate, but best to follow existing feedback.

The constructor properly sets up the post-processing pass with the correct event and material configuration. The depth state is disabled, which is good for a screen-space pass.

As mentioned in a previous review comment, you should make sure depth test and depth write are disabled to force blitting to the camera render target.

🧹 Nitpick comments (2)
packages/core/src/postProcess/PostProcessFinalPass.ts (2)

43-53: Consider optimizing shader macro management.

The code toggles shader macros during rendering, which is functional but could potentially be optimized. Consider setting macros only when the camera's anti-aliasing or HDR settings change, rather than on every render call.

- if (enableFXAA) {
-   material.shaderData.enableMacro(PostProcessFinalPass._fxaaEnabledMacro);
-   if (camera.enableHDR) {
-     material.shaderData.enableMacro(PostProcessFinalPass._hdrInputMacro);
-   } else {
-     material.shaderData.disableMacro(PostProcessFinalPass._hdrInputMacro);
-   }
- } else {
-   material.shaderData.disableMacro(PostProcessFinalPass._fxaaEnabledMacro);
-   material.shaderData.disableMacro(PostProcessFinalPass._hdrInputMacro);
- }
+ // Only update macros if settings have changed
+ if (this._lastFXAAEnabled !== enableFXAA || this._lastHDREnabled !== camera.enableHDR) {
+   if (enableFXAA) {
+     material.shaderData.enableMacro(PostProcessFinalPass._fxaaEnabledMacro);
+     if (camera.enableHDR) {
+       material.shaderData.enableMacro(PostProcessFinalPass._hdrInputMacro);
+     } else {
+       material.shaderData.disableMacro(PostProcessFinalPass._hdrInputMacro);
+     }
+   } else {
+     material.shaderData.disableMacro(PostProcessFinalPass._fxaaEnabledMacro);
+     material.shaderData.disableMacro(PostProcessFinalPass._hdrInputMacro);
+   }
+   this._lastFXAAEnabled = enableFXAA;
+   this._lastHDREnabled = camera.enableHDR;
+ }

To implement this optimization, you'd need to add two more private properties:

private _lastFXAAEnabled: boolean = false;
private _lastHDREnabled: boolean = false;

1-64: Consider adding overrideable methods for extensibility.

The current implementation is solid for FXAA, but you might want to make it more extensible for future post-processing effects by adding protected methods that subclasses could override.

For example, you could add:

protected configureMaterial(material: Material, camera: Camera): void {
  const enableFXAA = camera?.antiAliasing === AntiAliasing.FastApproximateAntiAliasing;
  
  if (enableFXAA) {
    material.shaderData.enableMacro(PostProcessFinalPass._fxaaEnabledMacro);
    if (camera.enableHDR) {
      material.shaderData.enableMacro(PostProcessFinalPass._hdrInputMacro);
    } else {
      material.shaderData.disableMacro(PostProcessFinalPass._hdrInputMacro);
    }
  } else {
    material.shaderData.disableMacro(PostProcessFinalPass._fxaaEnabledMacro);
    material.shaderData.disableMacro(PostProcessFinalPass._hdrInputMacro);
  }
}

Then update onRender to use it:

override onRender(camera: Camera, srcTexture: Texture2D, destTarget: RenderTarget): void {
  this._camera = camera;
  this.configureMaterial(this._finalMaterial, camera);
  Blitter.blitTexture(camera.engine, srcTexture, destTarget, 0, camera.viewport, this._finalMaterial);
}

This would make it easier for subclasses to extend the functionality without having to override the entire onRender method.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b48df4d and 300f703.

📒 Files selected for processing (2)
  • packages/core/src/Camera.ts (2 hunks)
  • packages/core/src/postProcess/PostProcessFinalPass.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/Camera.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build (22.x, windows-latest)
  • GitHub Check: e2e (22.x)
🔇 Additional comments (6)
packages/core/src/postProcess/PostProcessFinalPass.ts (6)

1-13: Imports look well-organized and complete.

The file imports all necessary dependencies for implementing a final post-processing pass with FXAA support. The modular approach to shader imports (separating FXAA3_11 and FinalPost) is good for maintainability.


14-20: Class properties are well-structured.

The static shader macros and private properties are properly defined. The _camera property is now correctly implemented as a private instance property instead of static, addressing previous review concerns.


33-36: The isValid method now correctly returns true.

This implementation ensures the pass is always active, which makes sense for a final post-processing pass. This addresses previous concerns about the method potentially not returning a value.


38-41: Good initialization of the camera property.

The camera is now correctly assigned at the beginning of the onRender method, ensuring it's properly set before being used.


55-57: The blitting operation looks correct.

Using Blitter.blitTexture is appropriate for copying the processed texture to the destination target. Including the camera viewport ensures proper rendering dimensions.


59-63: Shader registration looks good.

The FXAA shader is correctly registered in the ShaderLib, and the final shader is created with appropriate vertex and fragment shaders.

Copy link
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🔭 Outside diff range comments (1)
packages/core/src/RenderPipeline/BasicRenderPipeline.ts (1)

49-66: 🛠️ Refactor suggestion

Release _finalPass resources in destroy()

FinalPass allocates its own material, mesh and render target.
BasicRenderPipeline.destroy() currently forgets to free them, leading to
GPU leaks when cameras are recreated.

   destroy(): void {
     this._cullingResults.destroy();
+    this._finalPass?.release();
     this._camera = null;
   }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e41325c and 2b57173.

⛔ Files ignored due to path filters (20)
  • packages/core/src/postProcess/shaders/Bloom/BloomBlurH.glsl is excluded by !**/*.glsl
  • packages/core/src/postProcess/shaders/Bloom/BloomBlurV.glsl is excluded by !**/*.glsl
  • packages/core/src/postProcess/shaders/Bloom/BloomPrefilter.glsl is excluded by !**/*.glsl
  • packages/core/src/postProcess/shaders/Bloom/BloomUpsample.glsl is excluded by !**/*.glsl
  • packages/core/src/postProcess/shaders/FXAA/FXAA3_11.glsl is excluded by !**/*.glsl
  • packages/core/src/postProcess/shaders/FinalPost.glsl is excluded by !**/*.glsl
  • packages/core/src/postProcess/shaders/UberPost.glsl is excluded by !**/*.glsl
  • packages/core/src/shaderlib/extra/BlitScreen.fs.glsl is excluded by !**/*.glsl
  • packages/core/src/shaderlib/extra/SkyProcedural.fs.glsl is excluded by !**/*.glsl
  • packages/core/src/shaderlib/extra/background-texture.fs.glsl is excluded by !**/*.glsl
  • packages/core/src/shaderlib/extra/blinn-phong.fs.glsl is excluded by !**/*.glsl
  • packages/core/src/shaderlib/extra/particle.fs.glsl is excluded by !**/*.glsl
  • packages/core/src/shaderlib/extra/pbr-specular.fs.glsl is excluded by !**/*.glsl
  • packages/core/src/shaderlib/extra/pbr.fs.glsl is excluded by !**/*.glsl
  • packages/core/src/shaderlib/extra/skybox.fs.glsl is excluded by !**/*.glsl
  • packages/core/src/shaderlib/extra/sprite.fs.glsl is excluded by !**/*.glsl
  • packages/core/src/shaderlib/extra/text.fs.glsl is excluded by !**/*.glsl
  • packages/core/src/shaderlib/extra/unlit.fs.glsl is excluded by !**/*.glsl
  • packages/shader-shaderlab/src/shaders/shadingPBR/ForwardPassPBR.glsl is excluded by !**/*.glsl
  • packages/ui/src/shader/uiDefault.fs.glsl is excluded by !**/*.glsl
📒 Files selected for processing (7)
  • e2e/case/camera-opaque-texture.ts (0 hunks)
  • e2e/case/material-shaderReplacement.ts (1 hunks)
  • packages/core/src/Camera.ts (4 hunks)
  • packages/core/src/Engine.ts (1 hunks)
  • packages/core/src/RenderPipeline/BasicRenderPipeline.ts (5 hunks)
  • packages/core/src/postProcess/FinalPass.ts (1 hunks)
  • packages/core/src/postProcess/PostProcessManager.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • e2e/case/camera-opaque-texture.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/core/src/Engine.ts
  • packages/core/src/Camera.ts
  • packages/core/src/postProcess/FinalPass.ts
🧰 Additional context used
🪛 ESLint
packages/core/src/postProcess/PostProcessManager.ts

[error] 204-204: Delete ·

(prettier/prettier)


[error] 207-207: Delete ·

(prettier/prettier)


[error] 214-215: Delete

(prettier/prettier)

🪛 GitHub Check: lint
packages/core/src/postProcess/PostProcessManager.ts

[failure] 214-214:
Delete


[failure] 207-207:
Delete ·


[failure] 204-204:
Delete ·

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: e2e (22.x)
  • GitHub Check: build (22.x, windows-latest)
  • GitHub Check: codecov
🔇 Additional comments (2)
e2e/case/material-shaderReplacement.ts (1)

151-154: Ensure color-space correctness after removing outputSRGBCorrection

The shader now writes the sampled texel directly to gl_FragColor.
That is correct if (and only if) the new FinalPass is always invoked whenever this shader is rendered, because the sRGB conversion has been moved there.
If the camera is configured so that _needFinalPass() returns false, the rendered colors will stay in linear space and appear darker.

Please double-check with a quick render test (FXAA off + LDR render-target) or search for usages of setReplacementShader("UVCheckShader") to confirm that every path still schedules a final pass. If you find cases where the final pass is skipped, re-introduce the correction locally or force the camera to enable the final pass.

packages/core/src/postProcess/PostProcessManager.ts (1)

221-237: Validate MSAA sample count & color-space flags

_getOutputRenderTarget() hard-codes msaaSamples = 1.
If the camera itself is multisampled, this down-sampling may introduce
visible edge aliasing before FXAA is applied, and wastes the original
hardware-MSAA resolve. Please verify whether:

  1. We intentionally want a single-sample texture as FXAA input, or
  2. We should pass camera.msaaSamples instead.

Likewise, the isSRGBColorSpace flag is derived via !camera._isTargetFormatHDR().
Ensure this matches the engine’s SRGB/HDR semantics for all targets.

Copy link
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/src/core/Camera.test.ts (1)

119-119: Add space before the inline comment.

The test case updates correctly reflect the new behavior where independentCanvasEnabled is now true initially due to the sRGB pass introduced as part of the FXAA support. However, there's a minor formatting issue - you need to add a space between true); and the comment.

-    expect(camera.independentCanvasEnabled).to.eq(true);// Because sRGB pass
+    expect(camera.independentCanvasEnabled).to.eq(true); // Because sRGB pass
🧰 Tools
🪛 ESLint

[error] 119-119: Insert ·

(prettier/prettier)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f340bd2 and 5134a07.

📒 Files selected for processing (1)
  • tests/src/core/Camera.test.ts (1 hunks)
🧰 Additional context used
🪛 ESLint
tests/src/core/Camera.test.ts

[error] 119-119: Insert ·

(prettier/prettier)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: codecov
  • GitHub Check: e2e (22.x)
  • GitHub Check: build (22.x, windows-latest)

@GuoLei1990 GuoLei1990 merged commit d15d085 into galacean:dev/1.5 Apr 24, 2025
9 checks passed
@GuoLei1990 GuoLei1990 changed the title Support fxaa Support fxaa and linear space color blend Apr 24, 2025
@GuoLei1990 GuoLei1990 changed the title Support fxaa and linear space color blend Support FXAA and linear space color blend Apr 24, 2025
@coderabbitai coderabbitai bot mentioned this pull request Apr 25, 2025
3 tasks
This was referenced May 22, 2025
@hhhhkrx hhhhkrx deleted the FXAA branch June 4, 2025 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request rendering Rendering related functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Color blending should be linear color space 【RFC】 Anti-Aliasing(FXAA/TAA)
3 participants
0