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

Update shaderlab doc #2505

Merged
merged 6 commits into from
Jan 23, 2025
Merged

Update shaderlab doc #2505

merged 6 commits into from
Jan 23, 2025

Conversation

Sway007
Copy link
Member

@Sway007 Sway007 commented Jan 14, 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

  • Documentation

    • Updated ShaderLab documentation with new sections on:
      • Multi-Render Target (MRT) support
      • Material property customization using Editor directive
      • Enhanced explanations of global variable declarations
    • Added comprehensive documentation for ShaderLab Editor functionality
    • Improved metadata for shader-related files
  • New Features

    • Introduced ShaderUIScript class for material property and macro change callbacks
    • Added support for customizing material Inspector property panel

@Sway007 Sway007 added documentation Improvements or additions to documentation shader Shader related functions medium priority Medium priority issue labels Jan 14, 2025
@Sway007 Sway007 self-assigned this Jan 14, 2025
Copy link

coderabbitai bot commented Jan 14, 2025

Walkthrough

This pull request introduces comprehensive documentation updates for ShaderLab, focusing on shader syntax, editor properties, and Multi-Render Target (MRT) support. The changes include adding an Editor block to shader definitions, expanding documentation on shader property customization, introducing a new ShaderUIScript class for material property interactions, and detailing MRT rendering techniques. The modifications aim to provide developers with more detailed guidance on shader configuration and inspector property management.

Changes

File Change Summary
docs/zh/graphics/shader/shaderLab/syntax/_meta.json Added "editor": "Editor" key-value pair
docs/zh/graphics/shader/shaderLab/syntax/editor.mdx New documentation for ShaderLab Editor, introducing ShaderUIScript class with methods for material property and macro change callbacks
docs/zh/graphics/shader/shaderLab/syntax/intro.mdx Updated image source, added Editor { ... } block in GLSL syntax
docs/zh/graphics/shader/shaderLab/syntax/pass.mdx Added Multi-Render Target (MRT) section with two MRT specification methods
docs/zh/graphics/shader/shaderLab/syntax/shader.mdx Removed detailed EditorProperties example, added new Editor directive explanation
docs/en/graphics/shader/shaderLab/syntax/_meta.json Added "editor": "Editor" key-value pair
docs/en/graphics/shader/shaderLab/syntax/editor.mdx New documentation for ShaderLab Editor, introducing ShaderUIScript class with methods for material property and macro change callbacks
docs/en/graphics/shader/shaderLab/syntax/intro.mdx Updated image source, added Editor { ... } block in GLSL syntax
docs/en/graphics/shader/shaderLab/syntax/pass.mdx Added Multi-Render Target (MRT) section with two MRT specification methods
docs/en/graphics/shader/shaderLab/syntax/shader.mdx Removed detailed EditorProperties example, added new Editor directive explanation

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • zhuxudong
  • GuoLei1990

Poem

🐰 Shader magic unfolds today,
With Editor's touch, we pave the way!
MRT dancing, properties bright,
Code leaps forward with rabbit's might!
ShaderLab sings its syntax song 🎨


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: 0

🧹 Nitpick comments (5)
docs/zh/graphics/shader/shaderLab/syntax/intro.mdx (1)

22-25: Consider adding a brief comment about the Editor block's purpose.

While the placement is correct, adding a brief inline comment about the Editor block's purpose would help readers understand its role in the shader structure.

 Editor {
+    // Customize material properties and Inspector UI
     ...
   }
docs/zh/graphics/shader/shaderLab/syntax/pass.mdx (2)

106-112: Consider adding a note about gl_FragData limitations.

While the example is correct, it would be helpful to mention that gl_FragData has a maximum array size limitation that varies by hardware.


116-127: Add performance considerations for MRT usage.

The GLSL 300 example with structure is well-documented, but consider adding a note about performance implications of using multiple render targets.

docs/zh/graphics/shader/shaderLab/syntax/editor.mdx (2)

211-253: Add error handling in the UIScript example.

The example would benefit from proper error handling for potential null values and type checking.

 this.onPropertyChanged("material_NormalTexture", (material: Material, value) => {
+  if (!material?.shaderData) {
+    console.warn("Invalid material or shader data");
+    return;
+  }
   const shaderData = material.shaderData;
   if (value) {
     shaderData.enableMacro("MATERIAL_HAS_NORMALTEXTURE");
   } else {
     shaderData.disableMacro("MATERIAL_HAS_NORMALTEXTURE");
   }
 })

257-260: Consider adding a code example for global variable declaration.

The warning about global variables is important, but it would be more helpful with a concrete example showing how to properly declare the variables.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3575cb9 and 119ab0b.

📒 Files selected for processing (5)
  • docs/zh/graphics/shader/shaderLab/syntax/_meta.json (1 hunks)
  • docs/zh/graphics/shader/shaderLab/syntax/editor.mdx (1 hunks)
  • docs/zh/graphics/shader/shaderLab/syntax/intro.mdx (1 hunks)
  • docs/zh/graphics/shader/shaderLab/syntax/pass.mdx (1 hunks)
  • docs/zh/graphics/shader/shaderLab/syntax/shader.mdx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build (22.x, windows-latest)
  • GitHub Check: e2e (22.x)
  • GitHub Check: codecov
🔇 Additional comments (5)
docs/zh/graphics/shader/shaderLab/syntax/_meta.json (1)

4-4: LGTM!

The addition of the "editor" entry properly maps to the new Editor documentation section.

docs/zh/graphics/shader/shaderLab/syntax/intro.mdx (1)

11-14: LGTM!

The image source has been updated to use the WebP format, which provides better compression and faster loading times.

docs/zh/graphics/shader/shaderLab/syntax/pass.mdx (1)

101-104: LGTM! Clear introduction to MRT support.

The introduction clearly states compatibility with both GLSL 100 and GLSL 300 syntax.

docs/zh/graphics/shader/shaderLab/syntax/shader.mdx (1)

21-21: LGTM! Clear reference to Editor documentation.

The reference to the Editor directive is clear and properly links to the detailed documentation.

docs/zh/graphics/shader/shaderLab/syntax/editor.mdx (1)

7-37: LGTM! Well-structured Editor block example.

The example clearly demonstrates the structure of Properties, Macros, and UIScript sections.

Copy link

codecov bot commented Jan 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.04%. Comparing base (e8f8359) to head (13fde20).
Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2505      +/-   ##
==========================================
+ Coverage   69.01%   69.04%   +0.02%     
==========================================
  Files         957      957              
  Lines      100078   100078              
  Branches     8560     8564       +4     
==========================================
+ Hits        69070    69100      +30     
+ Misses      30752    30722      -30     
  Partials      256      256              
Flag Coverage Δ
unittests 69.04% <ø> (+0.02%) ⬆️

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.

@Sway007 Sway007 changed the base branch from dev/1.4 to main January 23, 2025 02:57
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: 5

🧹 Nitpick comments (5)
docs/zh/graphics/shader/shaderLab/syntax/pass.mdx (1)

102-127: LGTM! Comprehensive MRT documentation

The MRT documentation clearly explains both GLSL 100 and 300 syntax methods with proper examples.

Consider adding version-specific notes

It would be helpful to explicitly mention which GLSL version is recommended for different scenarios.

docs/en/graphics/shader/shaderLab/syntax/shader.mdx (2)

21-21: Add a direct link to Editor documentation

Consider adding a direct link to the Editor documentation section for better navigation.


128-130: Add precision qualifier examples

Consider adding examples demonstrating when to use different precision qualifiers (lowp/mediump/highp).

docs/zh/graphics/shader/shaderLab/syntax/editor.mdx (2)

242-250: Improve readability and maintainability of angle calculations.

The angle calculations use magic numbers and could be simplified. Consider extracting constants and using more descriptive variable names.

-      const PI2 = Math.PI * 2;
-      const rotationRad = (Math.atan2(anisotropyInfo.y, anisotropyInfo.x) + PI2 ) % PI2;
-      shaderData.setFloat("anisotropyRotation", rotationRad * (180 / Math.PI))
+      const TWO_PI = Math.PI * 2;
+      const RADIANS_TO_DEGREES = 180 / Math.PI;
+      const rotationRad = (Math.atan2(anisotropyInfo.y, anisotropyInfo.x) + TWO_PI) % TWO_PI;
+      const rotationDeg = rotationRad * RADIANS_TO_DEGREES;
+      shaderData.setFloat("anisotropyRotation", rotationDeg);

257-260: Consider adding a code example for global variable declaration.

The warning about manual global variable declaration is important but could be more helpful with a concrete example.

Consider adding a code example showing how to properly declare global variables in the ShaderPass, like:

// In ShaderPass
uniform vec4 material_BaseColor;
uniform vec4 material_EmissiveColor;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 119ab0b and 13fde20.

📒 Files selected for processing (7)
  • docs/en/graphics/shader/shaderLab/syntax/_meta.json (1 hunks)
  • docs/en/graphics/shader/shaderLab/syntax/editor.mdx (1 hunks)
  • docs/en/graphics/shader/shaderLab/syntax/intro.mdx (2 hunks)
  • docs/en/graphics/shader/shaderLab/syntax/pass.mdx (1 hunks)
  • docs/en/graphics/shader/shaderLab/syntax/shader.mdx (1 hunks)
  • docs/zh/graphics/shader/shaderLab/syntax/editor.mdx (1 hunks)
  • docs/zh/graphics/shader/shaderLab/syntax/pass.mdx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e (22.x)
🔇 Additional comments (7)
docs/en/graphics/shader/shaderLab/syntax/_meta.json (1)

4-4: LGTM! Addition of Editor entry

The new entry follows the existing naming pattern and properly integrates with the documentation structure.

docs/en/graphics/shader/shaderLab/syntax/intro.mdx (1)

11-14: LGTM! Image format optimization

The switch to WEBP format is a good optimization for web delivery.

docs/en/graphics/shader/shaderLab/syntax/pass.mdx (1)

102-129: LGTM! Consistent MRT documentation

The English documentation accurately mirrors the Chinese version with proper technical terminology.

docs/en/graphics/shader/shaderLab/syntax/shader.mdx (4)

33-46: LGTM! Comprehensive BlendState documentation

The BlendState properties are well-documented with clear parameter descriptions.


52-58: LGTM! Clear DepthState documentation

The DepthState properties are accurately documented with proper types.


64-79: LGTM! Detailed StencilState documentation

The StencilState documentation comprehensively covers all properties with proper types.


97-115: LGTM! Clear example with both assignment types

The example effectively demonstrates both constant and variable assignments for BlendState.

Comment on lines +23 to +25
Editor {
...
}
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Add link to Editor block documentation

The Editor block documentation exists at editor.mdx in the same directory, but there's no link to it from the introduction. Add a reference to help users find the detailed documentation.

🔗 Analysis chain

Verify Editor block documentation

The Editor block is introduced in the syntax framework, but ensure that there's a corresponding link to its detailed documentation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if Editor documentation exists
fd -t f "editor.mdx" docs/en/graphics/shader/shaderLab/syntax/

Length of output: 114


Script:

#!/bin/bash
# Check intro.mdx for links to editor documentation
cat docs/en/graphics/shader/shaderLab/syntax/intro.mdx | grep -i "editor" -A 2 -B 2

Length of output: 272

Comment on lines +169 to +171
* @param material - The material which the shader is bound to
*/
onMaterialShaderSwitched(material: Material): void {}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix JSDoc parameter documentation.

The JSDoc comments use @parma instead of the correct @param tag. This should be fixed for better documentation tooling support.

   /**
    * Register property change callback.
-   * @parma propertyName - Property name
-   * @parma onChanged - Fired on property changed
+   * @param propertyName - Property name
+   * @param onChanged - Fired on property changed
    */

   /**
    * Register macro change callback.
-   * @parma macroName - Macro name
-   * @parma onChanged - Fired on macro changed
+   * @param macroName - Macro name
+   * @param onChanged - Fired on macro changed
    */

Also applies to: 175-177, 181-183, 187-189

```glsl
Editor {
Properties {
material_BaseColor("Offset unit scale", Color) = (1,1,1,1);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix inconsistent property description.

The property name material_BaseColor suggests a base color property, but the description "Offset unit scale" seems incorrect and misleading. Consider updating the description to match the property's purpose, e.g., "Base Color".

-        material_BaseColor("Offset unit scale", Color) = (1,1,1,1);
+        material_BaseColor("Base Color", Color) = (1,1,1,1);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
material_BaseColor("Offset unit scale", Color) = (1,1,1,1);
material_BaseColor("Base Color", Color) = (1,1,1,1);

Comment on lines +46 to +54
/**
* @language zh
* Comments description
*/

/**
* @language en
* 注释描述
*/
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix swapped language descriptions in comments.

The multilingual comments have their descriptions in the wrong language sections. The Chinese description appears under the English tag and vice versa.

 /**
  * @language zh
- * Comments description
+ * 注释描述
  */

 /**
  * @language en
- * 注释描述
+ * Comments description
  */
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* @language zh
* Comments description
*/
/**
* @language en
* 注释描述
*/
/**
* @language zh
* 注释描述
*/
/**
* @language en
* Comments description
*/

Comment on lines +93 to +97
<Callout typ="warning">
Currently, only Int and Float types support enumeration, and type mixing is not supported. For example, the following
enumeration mixes Float and Int, and will not be correctly parsed. ```glsl propertyName("Property Description",
Enum("Item1":1, "Item2":2.0, "Item3": 3)) = 2.0; ```
</Callout>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in Callout component attribute.

The Callout component has a typo in its type attribute (typ instead of type).

-<Callout typ="warning">
+<Callout type="warning">
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<Callout typ="warning">
Currently, only Int and Float types support enumeration, and type mixing is not supported. For example, the following
enumeration mixes Float and Int, and will not be correctly parsed. ```glsl propertyName("Property Description",
Enum("Item1":1, "Item2":2.0, "Item3": 3)) = 2.0; ```
</Callout>
<Callout type="warning">
Currently, only Int and Float types support enumeration, and type mixing is not supported. For example, the following

@eyworldwide eyworldwide added this to the 1.4 milestone Jan 23, 2025
@eyworldwide eyworldwide merged commit 7fc8cc7 into galacean:main Jan 23, 2025
9 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jan 24, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation medium priority Medium priority issue shader Shader related functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants