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 scene/camera shaderData in blitter #2558

Merged
merged 1 commit into from
Feb 13, 2025

Conversation

zhuxudong
Copy link
Member

@zhuxudong zhuxudong commented Feb 13, 2025

Users should be allowed to use the shader data of scene and camera in blitter shader, such as camera_DepthTexture.

Summary by CodeRabbit

  • Refactor
    • Improved the rendering pipeline to ensure camera settings are applied accurately. This update contributes to smoother and more consistent visual outputs during scene rendering, enhancing the overall display quality without altering the core functionality.

@zhuxudong zhuxudong added the bug Something isn't working label Feb 13, 2025
@zhuxudong zhuxudong requested a review from GuoLei1990 February 13, 2025 09:30
@zhuxudong zhuxudong self-assigned this Feb 13, 2025
Copy link

coderabbitai bot commented Feb 13, 2025

Walkthrough

The changes introduce a local camera variable in the Blitter class of the rendering pipeline. This variable is initialized from the context object and is used in the blitTexture method to replace direct references to context.camera. Additionally, the camera's shader data is uploaded to both the sceneUniformBlock and the cameraUniformBlock during the blitting process. These modifications improve code clarity without changing the overall control flow or core logic.

Changes

File(s) Change Summary
packages/core/src/RenderPipeline/Blitter.ts Introduced a local camera variable; replaced direct context.camera references; added calls to upload camera shader data to sceneUniformBlock and cameraUniformBlock in blitTexture.

Sequence Diagram(s)

sequenceDiagram
    participant BP as Blitter
    participant C as Context
    participant SP as Shader Program

    BP->>C: Retrieve camera
    C-->>BP: Returns camera
    BP->>SP: Upload sceneUniformBlock with camera data
    BP->>SP: Upload cameraUniformBlock with camera data
Loading

Possibly related PRs

Suggested labels

enhancement, shader, Rendering

Suggested reviewers

  • GuoLei1990

Poem

Hop, hop, the code now gleams,
A fresh camera joins our dreams.
Uniform blocks catch its light,
Shader data set just right.
I'm the bunny, coding all night! 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 813242e and 53814fe.

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

51-51: LGTM! Good optimization.

Storing the frequently accessed camera object in a local variable improves code readability and potentially performance by reducing property access.


78-79: LGTM! Successfully implements shader data access.

The added shader data uploads correctly implement the PR objective of enabling access to scene and camera shader data in the blitter. The implementation follows a logical order and maintains consistency with the existing pattern.

Note: This change enables access to shader data elements like camera_DepthTexture as mentioned in the PR objectives.

Comment on lines 69 to 73
ShaderMacroCollection.unionCollection(
context.camera._globalShaderMacro,
camera._globalShaderMacro,
blitMaterial.shaderData._macroCollection,
compileMacros
);
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Consider using a public accessor for the shader macro.

The direct access to _globalShaderMacro (with underscore prefix) suggests it's a private property. Consider using a public accessor method if available to make the code more maintainable and resilient to internal implementation changes.

Let's check if a public accessor exists:


🏁 Script executed:

#!/bin/bash
# Search for potential public accessors for globalShaderMacro
rg -A 5 "globalShaderMacro" --type ts

Length of output: 5226


Action Required: Introduce a Public Accessor for Shader Macro

Our investigation confirms that no public accessor exists for the shader macro—the codebase consistently accesses the internal _globalShaderMacro property (e.g., in Camera, Renderer, Scene, etc.). Direct use of this internal property could make the code susceptible to breaking changes if its implementation evolves.

  • Recommendation: Consider adding a public getter (e.g., getGlobalShaderMacro()) in the relevant class (such as Camera or Renderer) to encapsulate the shader macro collection.
  • Next Step: Update the call in packages/core/src/RenderPipeline/Blitter.ts to use this new accessor once implemented, or document the rationale for direct access if it’s intended for internal usage.

Copy link

codecov bot commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.92%. Comparing base (78f7415) to head (53814fe).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2558      +/-   ##
==========================================
+ Coverage   68.90%   68.92%   +0.01%     
==========================================
  Files         961      961              
  Lines      100266   100269       +3     
  Branches     8679     8682       +3     
==========================================
+ Hits        69092    69108      +16     
+ Misses      30914    30901      -13     
  Partials      260      260              
Flag Coverage Δ
unittests 68.92% <100.00%> (+0.01%) ⬆️

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.

@GuoLei1990 GuoLei1990 merged commit 4f833fb into galacean:main Feb 13, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants