Skip to content
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

Support post process #2129

Merged
merged 49 commits into from
Jul 11, 2024
Merged

Support post process #2129

merged 49 commits into from
Jul 11, 2024

Conversation

zhuxudong
Copy link
Member

@zhuxudong zhuxudong commented Jun 20, 2024

RFC: https://yuque.antfin-inc.com/shensi.zxd/ftoum6/gheugo4e7e1c1oil

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)
image

Summary by CodeRabbit

  • New Features

    • Introduced comprehensive post-processing capabilities, including Bloom, HDR, and Tonemapping effects.
    • Added support for post-process effect management via a new PostProcessManager class.
  • Enhancements

    • Improved bloom rendering with customizable parameters.
    • HDR and LDR post-processing effects with different tonemapping modes.
  • Bug Fixes

    • Corrected AARoughnessFactor calculation for better visual fidelity.
  • Configuration

    • Included new e2e test cases for post-processing effects.
    • Updated e2e configuration to support new post-processing test cases.

@zhuxudong zhuxudong added Rendering Rendering related functions post processing Post processing labels Jun 20, 2024
@zhuxudong zhuxudong added this to the 1.3 milestone Jun 20, 2024
@zhuxudong zhuxudong requested review from GuoLei1990 and hhhhkrx June 20, 2024 10:43
@zhuxudong zhuxudong self-assigned this Jun 20, 2024
@zhuxudong zhuxudong linked an issue Jun 20, 2024 that may be closed by this pull request
Copy link

coderabbitai bot commented Jun 28, 2024

Walkthrough

This update introduces significant enhancements to the post-processing capabilities in the rendering engine. The PostProcessManager class has been expanded to manage multiple post-processing effects, including bloom and tonemapping. New post-processing effects like BloomEffect have been added, alongside changes to utilities and shaders to support these effects. Additionally, new end-to-end tests were introduced to validate the HDR and LDR post-processing effects.

Changes

File(s) Change Summary
.../PostProcessManager.ts Enhanced PostProcessManager to manage multiple post-processing effects and render targets.
.../BloomEffect.ts Introduced BloomEffect with controls for bloom rendering parameters.
.../shaderlib/.../pbr_helper.glsl Adjusted AARoughnessFactor calculation by clamping it to a maximum value of 1.0.
.../PipelineUtils.ts Enhanced texture and render target recreation logic with new parameters for wrap mode and filter mode.
e2e/case/... Added new end-to-end tests for HDR and LDR post-processing effects, including HDR Bloom with ACES and Neutral tonemapping.
e2e/config.ts Updated configuration to include new post-processing tests.
.../Camera.ts Added HDR and post-process enabling properties and methods.
.../Scene.ts Integrated PostProcessManager into scene management.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Scene
    participant Camera
    participant PostProcessManager
    participant BloomEffect
    
    User->>Scene: Initialize scene
    Scene->>PostProcessManager: Initialize post-process manager
    PostProcessManager->>BloomEffect: Add bloom effect
    PostProcessManager->>Camera: Attach to camera
    Camera-->>Scene: Render scene
    Scene->>PostProcessManager: Apply post-processing
    PostProcessManager->>BloomEffect: Render bloom effect
    BloomEffect->>Camera: Output final image
    Camera-->>User: Display processed image
Loading

Poem

In the world of code, effects do bloom,
With shaders bright, dispelling gloom.
HDR and tonemapping play,
In scenes where colors dance and sway.
Post-processing now refined,
Brings to life what’s in the mind.
Render on, through night and day,
In pixels, magic finds its way.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between edc047b and 75c7013.

Files selected for processing (3)
  • packages/core/src/Camera.ts (10 hunks)
  • packages/core/src/postProcess/PostProcessManager.ts (1 hunks)
  • packages/core/src/postProcess/shaders/Tonemapping/ACES/RRT.glsl (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • packages/core/src/Camera.ts
  • packages/core/src/postProcess/PostProcessManager.ts
  • packages/core/src/postProcess/shaders/Tonemapping/ACES/RRT.glsl

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 75c7013 and c3c499b.

Files selected for processing (1)
  • packages/core/src/postProcess/effects/BloomEffect.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/postProcess/effects/BloomEffect.ts

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c3c499b and c86a9d4.

Files selected for processing (2)
  • packages/core/src/RenderPipeline/BasicRenderPipeline.ts (5 hunks)
  • packages/core/src/postProcess/PostProcessManager.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/postProcess/PostProcessManager.ts
Additional comments not posted (5)
packages/core/src/RenderPipeline/BasicRenderPipeline.ts (5)

15-22: Imports look good.

The added import statements are necessary for the new functionality related to texture handling and post-processing effects.


Line range hint 34-34: Initialization of _internalColorTarget looks good.

Initializing _internalColorTarget to null is standard practice.


198-222: Post-process rendering section looks good.

The modifications ensure that post-process effects are applied correctly when enabled.

However, verify the function's behavior with various post-process effects to ensure correctness.

Verification successful

Post-process rendering section looks good.

The modifications ensure that post-process effects are applied correctly when enabled. The end-to-end tests confirm the functionality with specific post-process effects like bloom and tonemapping.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify behavior of post-process rendering section with various post-process effects.

# Test: Search for the post-process rendering section usage. Expect: Correct application of post-process effects.
rg --type typescript -A 5 $'postProcessManager._render'

Length of output: 89


Script:

#!/bin/bash
# Description: Verify behavior of post-process rendering section with various post-process effects.

# Test: Search for the post-process rendering section usage. Expect: Correct application of post-process effects.
rg --type ts -A 5 $'postProcessManager._render'

Length of output: 599


Script:

#!/bin/bash
# Description: Verify behavior of post-process rendering section with various post-process effects.

# Test: Search for other usages of `postProcessManager` in the codebase.
rg --type ts 'postProcessManager'

Length of output: 904


Script:

#!/bin/bash
# Extract relevant test cases from the end-to-end test file for post-process effects.

rg --type ts -A 10 'postProcessManager' e2e/case/postProcess-bloom-tonemap.ts

Length of output: 462


Line range hint 153-222: Changes to _drawRenderPass method look good.

The modifications introduce post-process rendering and blitting operations, enhancing the rendering pipeline's flexibility.

However, verify the function's behavior with various post-process effects to ensure correctness.


118-124: Changes to the render method look good.

The modifications ensure the internal color texture is created and configured correctly based on the camera properties.

However, verify the function's behavior with various camera configurations to ensure correctness.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c86a9d4 and 5458d9c.

Files selected for processing (3)
  • packages/core/src/Camera.ts (10 hunks)
  • packages/core/src/RenderPipeline/BasicRenderPipeline.ts (5 hunks)
  • packages/core/src/postProcess/PostProcessManager.ts (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • packages/core/src/Camera.ts
  • packages/core/src/RenderPipeline/BasicRenderPipeline.ts
  • packages/core/src/postProcess/PostProcessManager.ts

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5458d9c and 3120f58.

Files selected for processing (2)
  • packages/core/src/postProcess/PostProcessManager.ts (1 hunks)
  • packages/core/src/postProcess/effects/BloomEffect.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • packages/core/src/postProcess/PostProcessManager.ts
  • packages/core/src/postProcess/effects/BloomEffect.ts

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

Outside diff range, codebase verification and nitpick comments (2)
e2e/case/postProcess-HDR-bloom-neutral.ts (1)

1-4: Add a description for the test case.

Consider adding a brief description of the test case's purpose for better understanding.

/**
+ * This test case sets up a post-processing environment with HDR, Bloom effect, and Neutral Tonemapping.
 * @title Bloom + HDR + Neutral Tonemapping
 * @category PostProcess
 */
e2e/case/postProcess-LDR-bloom-neutral.ts (1)

1-4: Add a description for the test case.

Consider adding a brief description of the test case's purpose for better understanding.

/**
+ * This test case sets up a post-processing environment with LDR, Bloom effect, and Neutral Tonemapping.
 * @title Bloom + LDR + Neutral Tonemapping
 * @category PostProcess
 */
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3120f58 and 24d5a31.

Files ignored due to path filters (3)
  • e2e/fixtures/originImage/PostProcess_postProcess-HDR-bloom-ACES.jpg is excluded by !**/*.jpg
  • e2e/fixtures/originImage/PostProcess_postProcess-HDR-bloom-neutral.jpg is excluded by !**/*.jpg
  • e2e/fixtures/originImage/PostProcess_postProcess-LDR-bloom-neutral.jpg is excluded by !**/*.jpg
Files selected for processing (7)
  • e2e/case/.initPostProcessEnv.ts (1 hunks)
  • e2e/case/postProcess-HDR-bloom-ACES.ts (1 hunks)
  • e2e/case/postProcess-HDR-bloom-neutral.ts (1 hunks)
  • e2e/case/postProcess-LDR-bloom-neutral.ts (1 hunks)
  • e2e/config.ts (1 hunks)
  • packages/core/src/Camera.ts (10 hunks)
  • packages/core/src/RenderPipeline/BasicRenderPipeline.ts (5 hunks)
Files skipped from review due to trivial changes (1)
  • e2e/case/postProcess-HDR-bloom-ACES.ts
Files skipped from review as they are similar to previous changes (3)
  • e2e/config.ts
  • packages/core/src/Camera.ts
  • packages/core/src/RenderPipeline/BasicRenderPipeline.ts
Additional comments not posted (18)
e2e/case/postProcess-HDR-bloom-neutral.ts (4)

5-6: Ensure the initPostProcessEnv function handles errors.

The initPostProcessEnv function should handle potential errors during initialization.

import { Camera, TonemappingMode } from "@galacean/engine";
import { initPostProcessEnv } from "./.initPostProcessEnv";

8-10: Consider adding error handling for the callback function.

Ensure that the callback function handles any errors that may occur during execution.

initPostProcessEnv((camera: Camera, resArray) => {
  const [_, __, dirtTexture] = resArray;
  const scene = camera.scene;
  // Add error handling logic here if necessary

12-13: Enable post-processing and HDR correctly.

Ensure that enabling post-processing and HDR is done correctly. No changes needed.

camera.enablePostProcess = true;
camera.enableHDR = true;

19-24: Configure Bloom and Tonemapping effects correctly.

Ensure that the Bloom and Tonemapping effects are configured correctly. No changes needed.

bloomEffect.enabled = true;
tonemappingEffect.enabled = true;

bloomEffect.threshold = 0.5;
bloomEffect.dirtTexture = dirtTexture;
tonemappingEffect.mode = TonemappingMode.Neutral;
e2e/case/postProcess-LDR-bloom-neutral.ts (4)

5-6: Ensure the initPostProcessEnv function handles errors.

The initPostProcessEnv function should handle potential errors during initialization.

import { Camera, TonemappingMode } from "@galacean/engine";
import { initPostProcessEnv } from "./.initPostProcessEnv";

8-10: Consider adding error handling for the callback function.

Ensure that the callback function handles any errors that may occur during execution.

initPostProcessEnv((camera: Camera, resArray) => {
  const [_, __, dirtTexture] = resArray;
  const scene = camera.scene;
  // Add error handling logic here if necessary

12-13: Enable post-processing and LDR correctly.

Ensure that enabling post-processing and LDR is done correctly. No changes needed.

camera.enablePostProcess = true;
camera.enableHDR = false;

19-24: Configure Bloom and Tonemapping effects correctly.

Ensure that the Bloom and Tonemapping effects are configured correctly. No changes needed.

bloomEffect.enabled = true;
tonemappingEffect.enabled = true;

bloomEffect.threshold = 0.5;
bloomEffect.dirtTexture = dirtTexture;
tonemappingEffect.mode = TonemappingMode.Neutral;
e2e/case/.initPostProcessEnv.ts (10)

1-12: Ensure all imports are necessary.

Verify that all imported modules are necessary for the function.

import {
  AmbientLight,
  AssetType,
  BackgroundMode,
  Camera,
  GLTFResource,
  PrimitiveMesh,
  SkyBoxMaterial,
  Texture2D,
  Vector3,
  WebGLEngine
} from "@galacean/engine";
import { initScreenshot, updateForE2E } from "./.mockForE2E";

15-17: Add error handling for the callback function.

Ensure that the callback function handles any errors that may occur during execution.

export async function initPostProcessEnv(
  callback: (camera: Camera, resArray: [GLTFResource, AmbientLight, Texture2D]) => void
) {

18-19: Handle potential errors from WebGLEngine.create.

Ensure that potential errors from WebGLEngine.create are handled properly.

  WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
    engine.canvas.resizeByClientSize();

21-22: Check for errors during scene creation.

Ensure that errors during scene creation are handled.

    const scene = engine.sceneManager.activeScene;
    const rootEntity = scene.createRootEntity();

24-28: Ensure camera setup is correct.

Verify the correctness of the camera setup.

    //Create camera
    const cameraNode = rootEntity.createChild("camera_node");
    cameraNode.transform.position.set(4, 0, 6);
    cameraNode.transform.lookAt(new Vector3(1, 0, 0));
    const camera = cameraNode.addComponent(Camera);

30-37: Handle potential errors during asset loading.

Ensure that potential errors during asset loading are handled.

    Promise.all([
      engine.resourceManager
        .load<GLTFResource>("https://gw.alipayobjects.com/os/bmw-prod/a1da72a4-023e-4bb1-9629-0f4b0f6b6fc4.glb")
        .then((glTF) => {
          const defaultSceneRoot = glTF.instantiateSceneRoot();
          rootEntity.addChild(defaultSceneRoot);
          return glTF;
        }),

38-54: Ensure ambient light and skybox setup is correct.

Verify the correctness of the ambient light and skybox setup.

      engine.resourceManager
        .load<AmbientLight>({
          type: AssetType.Env,
          url: "https://gw.alipayobjects.com/os/bmw-prod/89c54544-1184-45a1-b0f5-c0b17e5c3e68.bin"
        })
        .then((ambientLight) => {
          scene.ambientLight = ambientLight;
          const sky = scene.background.sky;
          const skyMaterial = new SkyBoxMaterial(engine);
          scene.background.mode = BackgroundMode.Sky;

          sky.material = skyMaterial;
          sky.mesh = PrimitiveMesh.createCuboid(engine, 1, 1, 1);
          skyMaterial.texture = ambientLight.specularTexture;
          skyMaterial.textureDecodeRGBM = true;
          return ambientLight;
        }),

55-58: Handle potential errors during texture loading.

Ensure that potential errors during texture loading are handled.

      engine.resourceManager.load<Texture2D>({
        type: AssetType.Texture2D,
        url: "https://mdn.alipayobjects.com/huamei_dmxymu/afts/img/A*tMeTQ4Mx60oAAAAAAAAAAAAADuuHAQ/original"
      })

59-65: Ensure callback and E2E update are correct.

Verify the correctness of the callback invocation and E2E update.

    ]).then((resArray) => {
      callback(camera, resArray);

      updateForE2E(engine);

      initScreenshot(engine, camera);
    });

66-67: Handle potential errors from Promise.all.

Ensure that potential errors from Promise.all are handled properly.

  });
}

Comment on lines +14 to +17
// @ts-ignore
const bloomEffect = scene._postProcessManager._bloomEffect;
// @ts-ignore
const tonemappingEffect = scene._postProcessManager._tonemappingEffect;
Copy link

Choose a reason for hiding this comment

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

Avoid using private properties directly.

Using private properties like _postProcessManager directly is discouraged. Consider adding public methods to access these properties.

// @ts-ignore
const bloomEffect = scene._postProcessManager._bloomEffect;
// @ts-ignore
const tonemappingEffect = scene._postProcessManager._tonemappingEffect;

// Consider refactoring to use public methods if available

Committable suggestion was skipped due to low confidence.

Comment on lines +14 to +17
// @ts-ignore
const bloomEffect = scene._postProcessManager._bloomEffect;
// @ts-ignore
const tonemappingEffect = scene._postProcessManager._tonemappingEffect;
Copy link

Choose a reason for hiding this comment

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

Avoid using private properties directly.

Using private properties like _postProcessManager directly is discouraged. Consider adding public methods to access these properties.

// @ts-ignore
const bloomEffect = scene._postProcessManager._bloomEffect;
// @ts-ignore
const tonemappingEffect = scene._postProcessManager._tonemappingEffect;

// Consider refactoring to use public methods if available

Committable suggestion was skipped due to low confidence.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 24d5a31 and 17cf57e.

Files selected for processing (1)
  • packages/core/src/shaderlib/pbr/pbr_helper.glsl (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/shaderlib/pbr/pbr_helper.glsl

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 17cf57e and 5bf3965.

Files selected for processing (5)
  • packages/core/src/RenderPipeline/PipelineUtils.ts (9 hunks)
  • packages/core/src/Scene.ts (2 hunks)
  • packages/core/src/postProcess/PostProcessManager.ts (1 hunks)
  • packages/core/src/postProcess/effects/BloomEffect.ts (1 hunks)
  • packages/core/src/postProcess/index.ts (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • packages/core/src/RenderPipeline/PipelineUtils.ts
  • packages/core/src/Scene.ts
  • packages/core/src/postProcess/PostProcessManager.ts
  • packages/core/src/postProcess/effects/BloomEffect.ts
  • packages/core/src/postProcess/index.ts

@GuoLei1990 GuoLei1990 merged commit a69eb60 into galacean:dev/1.3 Jul 11, 2024
6 checks passed
@GuoLei1990 GuoLei1990 added the enhancement New feature or request label Jul 12, 2024
This was referenced Sep 9, 2024
@coderabbitai coderabbitai bot mentioned this pull request Jan 15, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pipeline post processing Post processing Rendering Rendering related functions
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Support Post Process Pipeline
2 participants