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

Fix background render error when render to RT #2414

Merged
merged 2 commits into from
Oct 31, 2024

Conversation

zhuxudong
Copy link
Member

@zhuxudong zhuxudong commented Oct 31, 2024

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

    • Enhanced background rendering by integrating camera-specific shader data.
    • Introduced a new uniform variable for improved vertical positioning in shaders.
  • Bug Fixes

    • Refined handling of internal color targets based on camera viewport dimensions.
  • Documentation

    • Updated method signatures to reflect new parameters and functionality.

@zhuxudong zhuxudong added the Bug Something isn't working label Oct 31, 2024
@zhuxudong zhuxudong requested a review from GuoLei1990 October 31, 2024 05:49
@zhuxudong zhuxudong changed the title Fix background texture yAxis erro when render to RT Fix background texture yAxis error when render to RT Oct 31, 2024
Copy link

coderabbitai bot commented Oct 31, 2024

Walkthrough

The changes in this pull request involve modifications to the BasicRenderPipeline class and associated GLSL shader code. The _drawBackgroundTexture method's signature is updated to include a new camera parameter for uploading camera-specific shader data. The render method is also adjusted to pass this parameter. Additionally, a new uniform variable camera_ProjectionParams is introduced in the GLSL shader, affecting the vertical positioning of rendered geometry. These updates enhance the integration of camera data into the rendering process.

Changes

File Path Change Summary
packages/core/src/RenderPipeline/BasicRenderPipeline.ts Updated _drawBackgroundTexture method to include camera: Camera parameter; modified render method to pass camera.
packages/core/src/shaderlib/extra/background-texture.vs.glsl Added uniform variable camera_ProjectionParams to modify the y component of gl_Position in the shader.

Possibly related PRs

  • Fix shader destroy memory residual #2410: The changes in this PR involve modifications to shader management, which may relate to the shader data handling introduced in the main PR's updates to the _drawBackgroundTexture method, particularly in how shader parameters are managed and utilized.

Suggested labels

shader

Poem

In the pipeline where colors blend,
A camera's gaze we now extend.
With shaders bright and textures fine,
Our rendering's dance is now divine!
Hopping through code, we cheer and play,
For every frame, a brighter day! 🐇✨


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>, 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 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

codecov bot commented Oct 31, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 69.46%. Comparing base (212130a) to head (bc4f29d).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ges/core/src/RenderPipeline/BasicRenderPipeline.ts 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2414      +/-   ##
==========================================
- Coverage   69.48%   69.46%   -0.03%     
==========================================
  Files         522      522              
  Lines       27363    27365       +2     
  Branches     4097     4097              
==========================================
- Hits        19013    19008       -5     
- Misses       6849     6853       +4     
- Partials     1501     1504       +3     
Flag Coverage Δ
unittests 69.46% <25.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

🧹 Outside diff range and nitpick comments (1)
packages/core/src/RenderPipeline/BasicRenderPipeline.ts (1)

320-320: LGTM! Consider documenting the camera shader data dependency.

The addition of camera shader data upload is crucial for correct y-axis orientation in render targets. Consider adding a code comment explaining this dependency.

    program.uploadAll(program.materialUniformBlock, material.shaderData);
+   // Upload camera shader data for correct y-axis orientation in render targets
    program.uploadAll(program.cameraUniformBlock, camera.shaderData);
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 320-320: packages/core/src/RenderPipeline/BasicRenderPipeline.ts#L320
Added line #L320 was not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 212130a and 0b51a5c.

📒 Files selected for processing (2)
  • packages/core/src/RenderPipeline/BasicRenderPipeline.ts (3 hunks)
  • packages/core/src/shaderlib/extra/background-texture.vs.glsl (1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
packages/core/src/RenderPipeline/BasicRenderPipeline.ts

[warning] 178-178: packages/core/src/RenderPipeline/BasicRenderPipeline.ts#L178
Added line #L178 was not covered by tests


[warning] 320-320: packages/core/src/RenderPipeline/BasicRenderPipeline.ts#L320
Added line #L320 was not covered by tests

🔇 Additional comments (3)
packages/core/src/shaderlib/extra/background-texture.vs.glsl (2)

4-4: LGTM! Well-chosen uniform for handling projection parameters.

The addition of camera_ProjectionParams follows standard practice for handling coordinate system differences between various render targets.


8-8: LGTM! Correct approach for Y-axis adjustment.

The multiplication of gl_Position.y with camera_ProjectionParams.x is the standard way to handle Y-axis flipping when rendering to different render targets.

Let's verify the camera parameter integration:

✅ Verification successful

Let me gather more information about how camera_ProjectionParams is set and used in the render context.


Let me check one final aspect - how the projection params are calculated and set.


Verified: Y-axis flipping implementation is correct and properly integrated

The verification confirms that:

  • The camera_ProjectionParams uniform is properly declared in shader files
  • The projection params are correctly set in RenderContext with the x component being -1 or 1 based on flipProjection flag
  • The shader correctly applies this to flip the Y coordinate when needed

This matches the standard approach for Y-axis flipping in render targets.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the camera parameter is properly set in the pipeline
# Expected: Find the corresponding uniform setup in the render pipeline

# Search for camera_ProjectionParams setup in the pipeline
rg -A 5 "camera_ProjectionParams" packages/core/src/

# Search for _drawBackgroundTexture to verify camera parameter usage
ast-grep --pattern $'_drawBackgroundTexture($$$, camera$$$)'

Length of output: 2495


Script:

#!/bin/bash
# Search for where camera_ProjectionParams is set in RenderContext
rg -A 10 "_cameraProjectionProperty" packages/core/src/RenderPipeline/RenderContext.ts

# Search for background texture rendering implementation
ast-grep --pattern 'drawBackgroundTexture($$$) {
  $$$
}'

Length of output: 815


Script:

#!/bin/bash
# Search for where projectionParams is set/calculated in RenderContext
rg -B 5 -A 10 "projectionParams" packages/core/src/RenderPipeline/RenderContext.ts

# Also check Camera class for any relevant projection param setup
rg -A 5 "ProjectionParams" packages/core/src/Camera.ts

Length of output: 1280

packages/core/src/RenderPipeline/BasicRenderPipeline.ts (1)

178-178: LGTM! Verify RT rendering behavior.

The addition of the camera parameter is correct and aligns with the need to handle projection parameters for render target output.

Let's verify the background texture rendering behavior with render targets:

✅ Verification successful

Based on the evidence gathered from the codebase:

  1. The background texture shader is properly initialized and used in the Background class
  2. The camera parameter addition in _drawBackgroundTexture aligns with render target handling
  3. The RenderContext shows evidence of Y-axis flipping matrices for render targets
  4. Multiple examples demonstrate proper render target and camera projection handling

✅ Camera parameter addition is correct for RT background rendering

The change to add the camera parameter to _drawBackgroundTexture is verified as the correct approach for handling background texture Y-axis rendering with render targets. The codebase shows consistent patterns of camera projection parameter handling for render targets, and the Background class properly initializes the shader that would consume these parameters.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other background texture render target usages
rg -g '!*.test.*' -g '!*.spec.*' "renderTarget.*background.*texture" -A 5

Length of output: 75


Script:

#!/bin/bash
# Let's try different search patterns to find render target and background texture usages
rg -g '!*.test.*' -g '!*.spec.*' "renderTarget.*background" -A 5

# Also search for background texture rendering methods
rg -g '!*.test.*' -g '!*.spec.*' "_drawBackgroundTexture" -A 5

# Look for render target setup with background
ast-grep --pattern 'renderTarget = $$$; background = $$$;'

# Search for background texture related tests
rg -g '*.test.*' -g '*.spec.*' "background.*texture.*renderTarget"

Length of output: 1315


Script:

#!/bin/bash
# Let's examine the background texture shader and material setup
ast-grep --pattern 'class Background {
  $$$
}'

# Look for camera projection related code in shaders
rg -g '*.shader.*' -g '*.vert.*' -g '*.frag.*' "camera_ProjectionParams" -A 5

# Check for render target related camera setup
ast-grep --pattern 'camera.renderTarget = $$$'

# Look for any background texture flipping or y-axis related code
rg -g '!*.test.*' -g '!*.spec.*' "flipY|yAxis|textureY" -A 3

Length of output: 39745


Script:

#!/bin/bash
# Let's examine the background texture shader code and camera projection handling
rg -g '*.ts' "background-texture" -B 2 -A 5

# Look for camera projection matrix handling in render context
ast-grep --pattern 'class RenderContext {
  $$$
  _updateShaderData($$$) {
    $$$
  }
  $$$
}'

# Check for render target specific camera handling
rg -g '*.ts' "renderTarget.*camera.*projection" -A 3

Length of output: 2359

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 178-178: packages/core/src/RenderPipeline/BasicRenderPipeline.ts#L178
Added line #L178 was not covered by tests

@@ -175,7 +175,7 @@
if (background.mode === BackgroundMode.Sky) {
background.sky._render(context);
} else if (background.mode === BackgroundMode.Texture && background.texture) {
this._drawBackgroundTexture(engine, background);
this._drawBackgroundTexture(engine, camera, background);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add tests for background texture RT rendering.

The changes fix a y-axis rendering issue but lack test coverage. Consider adding tests to:

  1. Verify background texture rendering with render targets
  2. Ensure correct y-axis orientation
  3. Prevent future regressions

Would you like help creating test cases for:

  • Background texture rendering with and without render targets
  • Y-axis orientation verification
  • Camera projection parameter integration

Also applies to: 320-320

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 178-178: packages/core/src/RenderPipeline/BasicRenderPipeline.ts#L178
Added line #L178 was not covered by tests

@GuoLei1990 GuoLei1990 added the rendering Rendering related functions label Oct 31, 2024
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

🧹 Outside diff range and nitpick comments (1)
packages/core/src/RenderPipeline/BasicRenderPipeline.ts (1)

Line range hint 303-321: Add documentation and validation for the y-axis fix.

While the implementation looks correct, consider these improvements:

  1. Add a comment explaining how the camera shader data fixes the y-axis issue when rendering to RT
  2. Add validation before uploading camera shader data

Example documentation:

 private _drawBackgroundTexture(camera: Camera, background: Background) {
+  // Upload camera projection parameters to fix y-axis orientation when rendering to RT
+  // This ensures correct vertical positioning of background texture in render target output
   const engine = camera.engine;

Example validation:

   program.uploadAll(program.materialUniformBlock, material.shaderData);
+  if (!camera.shaderData) {
+    console.warn('Camera shader data is required for correct background texture rendering');
+    return;
+  }
   program.uploadAll(program.cameraUniformBlock, camera.shaderData);
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 304-304: packages/core/src/RenderPipeline/BasicRenderPipeline.ts#L304
Added line #L304 was not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0b51a5c and bc4f29d.

📒 Files selected for processing (1)
  • packages/core/src/RenderPipeline/BasicRenderPipeline.ts (3 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
packages/core/src/RenderPipeline/BasicRenderPipeline.ts

[warning] 178-178: packages/core/src/RenderPipeline/BasicRenderPipeline.ts#L178
Added line #L178 was not covered by tests


[warning] 304-304: packages/core/src/RenderPipeline/BasicRenderPipeline.ts#L304
Added line #L304 was not covered by tests


[warning] 321-321: packages/core/src/RenderPipeline/BasicRenderPipeline.ts#L321
Added line #L321 was not covered by tests

🔇 Additional comments (1)
packages/core/src/RenderPipeline/BasicRenderPipeline.ts (1)

178-178: LGTM, but needs test coverage.

The parameter change from engine to camera is correct and aligns with the PR objective to fix y-axis rendering issues. However, this change lacks test coverage.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 178-178: packages/core/src/RenderPipeline/BasicRenderPipeline.ts#L178
Added line #L178 was not covered by tests

@GuoLei1990 GuoLei1990 merged commit 5d147ae into galacean:main Oct 31, 2024
7 of 9 checks passed
@GuoLei1990 GuoLei1990 changed the title Fix background texture yAxis error when render to RT Fix background render error when render to RT Oct 31, 2024
@coderabbitai coderabbitai bot mentioned this pull request Nov 5, 2024
3 tasks
@coderabbitai coderabbitai bot mentioned this pull request Dec 3, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working rendering Rendering related functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants