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

Gltf Iridescence #2425

Open
wants to merge 37 commits into
base: dev/1.4
Choose a base branch
from
Open

Gltf Iridescence #2425

wants to merge 37 commits into from

Conversation

hhhhkrx
Copy link
Contributor

@hhhhkrx hhhhkrx commented Nov 6, 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

    • Introduced support for iridescence effects in materials, enhancing visual rendering capabilities.
    • Added new properties and interfaces for iridescence, allowing for more complex material definitions in 3D models.
  • Bug Fixes

    • Updated existing interfaces to allow optional properties for greater flexibility in material construction.
  • Documentation

    • Enhanced material parsing capabilities in the GLTF loader to include iridescence properties.

Sway007 and others added 30 commits September 20, 2023 12:06
Copy link

coderabbitai bot commented Nov 6, 2024

Walkthrough

The changes introduce enhancements to the PBRMaterial class and related GLTF extensions to support iridescence effects in materials. New properties and methods are added to manage iridescence parameters, such as factor, index of refraction, and thickness. Additionally, the GLTFExtensionSchema is updated to include a new interface for iridescence, while existing clearcoat properties are made optional. A new GLTF extension class is created to parse iridescence properties from materials, and the corresponding module is imported into the extension index.

Changes

File Path Change Summary
packages/core/src/material/PBRMaterial.ts Added properties and methods for iridescence effects, including iridescenceFactor, iridescenceIor, iridescenceThicknessMin, iridescenceThicknessMax, and related texture properties. Updated constructor for initialization.
packages/loader/src/gltf/extensions/GLTFExtensionSchema.ts Updated IKHRMaterialsClearcoat interface to make properties optional. Added new interface IKHRMaterialsIridescence with optional properties for iridescence. Updated GLTFExtensionSchema to include the new interface.
packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts Introduced a new GLTF extension class KHR_materials_iridescence for handling iridescence. Implemented additiveParse method to extract and assign iridescence properties from the schema to the material.
packages/loader/src/gltf/extensions/index.ts Added import statement for the new KHR_materials_iridescence module.

Possibly related PRs

  • Fix the mesh was not restored after context lost. #2418: This PR is related because it involves changes to the PBRMaterial class, specifically in the context of material management and restoration, which aligns with the enhancements made in the main PR regarding iridescence properties in materials.

Suggested reviewers

  • GuoLei1990
  • zhuxudong

Poem

In the realm of light where colors play,
Iridescence dances, brightening the day.
With new properties added, our materials gleam,
A shimmering world, like a vivid dream.
Hooray for the changes, let joy take flight,
For every rabbit knows, it’s a beautiful sight! 🐇✨


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 Nov 6, 2024

Codecov Report

Attention: Patch coverage is 45.32374% with 76 lines in your changes missing coverage. Please review.

Project coverage is 66.81%. Comparing base (4fe788f) to head (f4b16fd).

Files with missing lines Patch % Lines
packages/core/src/material/PBRMaterial.ts 52.52% 47 Missing ⚠️
...r/src/gltf/extensions/KHR_materials_iridescence.ts 27.50% 29 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           dev/1.4    #2425      +/-   ##
===========================================
- Coverage    66.84%   66.81%   -0.04%     
===========================================
  Files          895      896       +1     
  Lines        92100    92238     +138     
  Branches      7327     7328       +1     
===========================================
+ Hits         61565    61625      +60     
- Misses       30290    30368      +78     
  Partials       245      245              
Flag Coverage Δ
unittests 66.81% <45.32%> (-0.04%) ⬇️

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.

@hhhhkrx hhhhkrx closed this Nov 6, 2024
@hhhhkrx hhhhkrx reopened this Nov 6, 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: 5

🧹 Outside diff range and nitpick comments (6)
packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts (3)

11-39: Add test coverage for the new extension

The static analysis indicates that this new extension lacks test coverage. Please add tests to verify:

  1. Correct parsing of all iridescence properties
  2. Default value handling
  3. Texture loading and transformation checks
  4. Edge cases with missing or invalid values

Would you like me to help create a test suite for this extension?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 11-39: packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts#L11-L39
Added lines #L11 - L39 were not covered by tests

🪛 GitHub Check: lint

[failure] 20-20:
Delete ·


[failure] 21-21:
Delete ·

🪛 eslint

[error] 20-20: Delete ·

(prettier/prettier)


[error] 21-21: Delete ·

(prettier/prettier)


[error] 22-22: Delete ·

(prettier/prettier)


[error] 23-23: Delete ·

(prettier/prettier)


[error] 24-24: Delete ·

(prettier/prettier)


25-31: Verify texture loading error handling

The texture loading uses promises but doesn't handle potential errors. Consider adding error handling:

 if (iridescenceTexture) {
   GLTFMaterialParser._checkOtherTextureTransform(iridescenceTexture, "Iridescence texture");

   context.get<Texture2D>(GLTFParserType.Texture, iridescenceTexture.index).then((texture) => {
     material.iridescenceTexture = texture;
-  });
+  }).catch(error => {
+    console.warn(`Failed to load iridescence texture: ${error}`);
+  });
 }

Apply similar changes to the thickness texture loading as well.

Also applies to: 32-38


12-18: Consider validating numerical parameters

The code should validate that the numerical parameters are within reasonable ranges:

  • iridescenceFactor should be between 0 and 1
  • iridescenceIor should be greater than 1
  • Thickness values should be positive

Example validation:

if (iridescenceFactor < 0 || iridescenceFactor > 1) {
  console.warn(`Invalid iridescenceFactor: ${iridescenceFactor}. Clamping to [0,1]`);
  iridescenceFactor = Math.max(0, Math.min(1, iridescenceFactor));
}
packages/loader/src/gltf/extensions/GLTFExtensionSchema.ts (1)

179-189: LGTM! Consider adding property documentation.

The IKHRMaterialsIridescence interface is well-structured and follows GLTF extension conventions. All properties are properly typed and marked as optional.

Consider adding JSDoc comments for each property to document their purpose and valid ranges, similar to other GLTF specs. Example:

/**
 * Interfaces from the KHR_materials_iridescence extension
 */
export interface IKHRMaterialsIridescence {
  /** The iridescence effect strength. Default: 0 */
  iridescenceFactor?: number;
  /** The texture defining the iridescence effect strength */
  iridescenceTexture?: ITextureInfo;
  /** Index of refraction for the iridescent layer. Default: 1.3 */
  iridescenceIor?: number;
  /** Minimum thickness of the iridescent layer in nanometers. Default: 100 */
  iridescenceThicknessMinimum?: number;
  /** Maximum thickness of the iridescent layer in nanometers. Default: 400 */
  iridescenceThicknessMaximum?: number;
  /** The texture defining the thickness of the iridescent layer */
  iridescenceThicknessTexture?: ITextureInfo;
}
packages/core/src/material/PBRMaterial.ts (2)

237-238: LGTM! Consider documenting default values.

The initialization looks good with appropriate default values. Consider adding a comment explaining the default values and their significance, especially for thickness values in nanometers.

Add a comment like:

+    // Initialize iridescence properties with default values:
+    // factor=0 (disabled), ior=1.3 (typical thin film),
+    // thickness range=100-400 nanometers (typical interference range)
     shaderData.setVector4(PBRMaterial._iridescenceProp, new Vector4(0, 1.3, 100, 400));
🧰 Tools
🪛 GitHub Check: lint

[failure] 237-237:
Delete

🪛 eslint

[error] 237-238: Delete

(prettier/prettier)


Line range hint 1-238: Add comprehensive test suite for iridescence functionality.

The implementation looks solid but lacks test coverage. Consider creating a dedicated test file with the following test cases:

  1. Basic Property Tests:

    • Default values after construction
    • Setting/getting individual properties
    • Value validation and constraints
  2. Texture Integration Tests:

    • Texture assignment and retrieval
    • Macro state management
    • Resource cleanup
  3. Integration Tests:

    • Interaction with other PBR properties
    • Shader data consistency
    • GLTF loading/saving

Would you like me to help create a test plan or generate a basic test suite structure?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 144-145: packages/core/src/material/PBRMaterial.ts#L144-L145
Added lines #L144 - L145 were not covered by tests


[warning] 148-150: packages/core/src/material/PBRMaterial.ts#L148-L150
Added lines #L148 - L150 were not covered by tests


[warning] 157-158: packages/core/src/material/PBRMaterial.ts#L157-L158
Added lines #L157 - L158 were not covered by tests


[warning] 161-163: packages/core/src/material/PBRMaterial.ts#L161-L163
Added lines #L161 - L163 were not covered by tests


[warning] 170-171: packages/core/src/material/PBRMaterial.ts#L170-L171
Added lines #L170 - L171 were not covered by tests


[warning] 174-176: packages/core/src/material/PBRMaterial.ts#L174-L176
Added lines #L174 - L176 were not covered by tests


[warning] 183-184: packages/core/src/material/PBRMaterial.ts#L183-L184
Added lines #L183 - L184 were not covered by tests


[warning] 187-189: packages/core/src/material/PBRMaterial.ts#L187-L189
Added lines #L187 - L189 were not covered by tests


[warning] 195-196: packages/core/src/material/PBRMaterial.ts#L195-L196
Added lines #L195 - L196 were not covered by tests


[warning] 199-206: packages/core/src/material/PBRMaterial.ts#L199-L206
Added lines #L199 - L206 were not covered by tests


[warning] 212-213: packages/core/src/material/PBRMaterial.ts#L212-L213
Added lines #L212 - L213 were not covered by tests


[warning] 216-223: packages/core/src/material/PBRMaterial.ts#L216-L223
Added lines #L216 - L223 were not covered by tests

🪛 GitHub Check: lint

[failure] 140-140:
Delete


[failure] 153-153:
Delete


[failure] 166-166:
Delete ↹↹


[failure] 179-179:
Delete


[failure] 190-190:
Delete ··


[failure] 192-192:
Delete


[failure] 209-209:
Delete

🪛 eslint

[error] 140-140: Delete

(prettier/prettier)


[error] 153-153: Delete

(prettier/prettier)


[error] 166-166: Delete ↹↹

(prettier/prettier)


[error] 179-179: Delete

(prettier/prettier)


[error] 190-190: Delete ··

(prettier/prettier)


[error] 192-192: Delete

(prettier/prettier)


[error] 209-209: Delete

(prettier/prettier)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a0d1d58 and b5b9a0a.

📒 Files selected for processing (4)
  • packages/core/src/material/PBRMaterial.ts (4 hunks)
  • packages/loader/src/gltf/extensions/GLTFExtensionSchema.ts (3 hunks)
  • packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts (1 hunks)
  • packages/loader/src/gltf/extensions/index.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/loader/src/gltf/extensions/index.ts
🧰 Additional context used
🪛 GitHub Check: codecov/patch
packages/core/src/material/PBRMaterial.ts

[warning] 144-145: packages/core/src/material/PBRMaterial.ts#L144-L145
Added lines #L144 - L145 were not covered by tests


[warning] 148-150: packages/core/src/material/PBRMaterial.ts#L148-L150
Added lines #L148 - L150 were not covered by tests


[warning] 157-158: packages/core/src/material/PBRMaterial.ts#L157-L158
Added lines #L157 - L158 were not covered by tests


[warning] 161-163: packages/core/src/material/PBRMaterial.ts#L161-L163
Added lines #L161 - L163 were not covered by tests


[warning] 170-171: packages/core/src/material/PBRMaterial.ts#L170-L171
Added lines #L170 - L171 were not covered by tests


[warning] 174-176: packages/core/src/material/PBRMaterial.ts#L174-L176
Added lines #L174 - L176 were not covered by tests


[warning] 183-184: packages/core/src/material/PBRMaterial.ts#L183-L184
Added lines #L183 - L184 were not covered by tests


[warning] 187-189: packages/core/src/material/PBRMaterial.ts#L187-L189
Added lines #L187 - L189 were not covered by tests


[warning] 195-196: packages/core/src/material/PBRMaterial.ts#L195-L196
Added lines #L195 - L196 were not covered by tests


[warning] 199-206: packages/core/src/material/PBRMaterial.ts#L199-L206
Added lines #L199 - L206 were not covered by tests


[warning] 212-213: packages/core/src/material/PBRMaterial.ts#L212-L213
Added lines #L212 - L213 were not covered by tests


[warning] 216-223: packages/core/src/material/PBRMaterial.ts#L216-L223
Added lines #L216 - L223 were not covered by tests

packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts

[warning] 11-39: packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts#L11-L39
Added lines #L11 - L39 were not covered by tests

🪛 GitHub Check: lint
packages/core/src/material/PBRMaterial.ts

[failure] 140-140:
Delete


[failure] 153-153:
Delete


[failure] 166-166:
Delete ↹↹


[failure] 179-179:
Delete


[failure] 190-190:
Delete ··


[failure] 192-192:
Delete


[failure] 209-209:
Delete


[failure] 237-237:
Delete

packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts

[failure] 20-20:
Delete ·


[failure] 21-21:
Delete ·

🪛 eslint
packages/core/src/material/PBRMaterial.ts

[error] 140-140: Delete

(prettier/prettier)


[error] 153-153: Delete

(prettier/prettier)


[error] 166-166: Delete ↹↹

(prettier/prettier)


[error] 179-179: Delete

(prettier/prettier)


[error] 190-190: Delete ··

(prettier/prettier)


[error] 192-192: Delete

(prettier/prettier)


[error] 209-209: Delete

(prettier/prettier)


[error] 237-238: Delete

(prettier/prettier)

packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts

[error] 20-20: Delete ·

(prettier/prettier)


[error] 21-21: Delete ·

(prettier/prettier)


[error] 22-22: Delete ·

(prettier/prettier)


[error] 23-23: Delete ·

(prettier/prettier)


[error] 24-24: Delete ·

(prettier/prettier)

🔇 Additional comments (3)
packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts (1)

1-9: LGTM: Imports and extension registration are properly set up

The imports are comprehensive and the extension is correctly registered using the @registerGLTFExtension decorator with appropriate parameters.

packages/loader/src/gltf/extensions/GLTFExtensionSchema.ts (2)

209-209: LGTM! Extension schema properly updated.

The IKHRMaterialsIridescence interface is correctly added to the GLTFExtensionSchema union type.


29-33: Verify spec compliance for optional clearcoat properties.

Making all clearcoat properties optional is a breaking change that could affect existing code. Please verify that this change aligns with the KHR_materials_clearcoat extension specification.

✅ Verification successful

Let me analyze the results and generate one more verification script to check the GLTF spec requirements.

The previous results show that:

  1. The implementation in KHR_materials_clearcoat.ts uses default values (0) for factors
  2. Properties are properly null-checked before use
  3. Need to verify if this matches the spec requirements

Let me see the documentation to make a final determination.


Based on the results, I can now make a final determination. The search results show:

  1. The implementation follows the GLTF spec by providing default values (0) for factors when not specified
  2. The properties are properly handled with null checks in the implementation
  3. The documentation links to the official KHR_materials_clearcoat spec
  4. The test cases demonstrate proper usage with optional properties

Making clearcoat properties optional is correct and spec-compliant

The change to make clearcoat properties optional is not a breaking change, but rather aligns with the GLTF extension specification. The implementation in KHR_materials_clearcoat.ts correctly handles this by:

  • Using default values (0) for unspecified factors
  • Properly checking for texture presence before usage
  • Maintaining compatibility with the extension specification
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the clearcoat changes align with GLTF spec and existing usage

# Test 1: Search for clearcoat property access patterns
echo "Searching for clearcoat property access patterns..."
rg -A 2 "clearcoatFactor|clearcoatTexture|clearcoatRoughnessFactor|clearcoatRoughnessTexture|clearcoatNormalTexture"

# Test 2: Look for any null checks or default value assignments
echo "Searching for null checks or default assignments..."
ast-grep --pattern 'clearcoat$_? ?? $_'
ast-grep --pattern 'clearcoat$_? || $_'
ast-grep --pattern 'clearcoat$_? ?: $_'

Length of output: 4749


Script:

#!/bin/bash
# Search for any documentation or comments about the clearcoat extension requirements
echo "Searching for clearcoat extension documentation..."
rg -i "khr_materials_clearcoat" -B 2 -A 2

# Look for default value assignments in the clearcoat implementation
echo "Searching for default value assignments..."
rg "clearcoat.*=.*0" -A 2

Length of output: 7969

GLTFMaterialParser._checkOtherTextureTransform(iridescenceThicknessTexture, "IridescenceThickness texture");

context.get<Texture2D>(GLTFParserType.Texture, iridescenceThicknessTexture.index).then((texture) => {
material.irithicknessTexture = texture;
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 property name

There's a typo in the property name:

-        material.irithicknessTexture = texture;
+        material.iridescenceThicknessTexture = texture;

This could cause the thickness texture to not be applied correctly.

📝 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.irithicknessTexture = texture;
material.iridescenceThicknessTexture = texture;

Comment on lines 22 to 23
material.iridescenceThicknessMin = iridescenceThicknessMaximum;
material.iridescenceThicknessMax = iridescenceThicknessMinimum;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Thickness min/max values are swapped

The assignment of thickness values appears to be reversed:

-     material.iridescenceThicknessMin = iridescenceThicknessMaximum;
-     material.iridescenceThicknessMax = iridescenceThicknessMinimum;
+     material.iridescenceThicknessMin = iridescenceThicknessMinimum;
+     material.iridescenceThicknessMax = iridescenceThicknessMaximum;

This could lead to incorrect rendering of iridescence effects.

📝 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.iridescenceThicknessMin = iridescenceThicknessMaximum;
material.iridescenceThicknessMax = iridescenceThicknessMinimum;
material.iridescenceThicknessMin = iridescenceThicknessMinimum;
material.iridescenceThicknessMax = iridescenceThicknessMaximum;
🧰 Tools
🪛 eslint

[error] 22-22: Delete ·

(prettier/prettier)


[error] 23-23: Delete ·

(prettier/prettier)

Comment on lines 139 to 189
/**
* The iridescence intensity factor.
* @defaultValue `1.0`
*/
get iridescenceFactor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceProp).x;
}

set iridescenceFactor(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
IridescenceInfo.x = value;
}

/**
* The index of refraction of the dielectric thin-film layer.
* @defaultValue `1.3`
*/
get iridescenceIor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceProp).y;
}

set iridescenceIor(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
IridescenceInfo.y = value;
}

/**
* The minimum thickness of the thin-film layer given in nanometers.
* @defaultValue `100`
*/
get iridescenceThicknessMin(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceProp).z;
}

set iridescenceThicknessMin(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
IridescenceInfo.z = value;
}

/**
* The maximum thickness of the thin-film layer given in nanometers.
* @defaultValue `400`
*/
get iridescenceThicknessMax(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceProp).w;
}

set iridescenceThicknessMax(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
IridescenceInfo.w = value;
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add input validation and tests for iridescence properties.

  1. Input Validation: Consider adding validation for the following properties:

    • iridescenceFactor: Should be clamped to [0,1]
    • iridescenceIor: Should be positive
    • iridescenceThicknessMin/Max: Should be positive and min < max
  2. Test Coverage: The static analysis indicates no test coverage for these properties. Please add unit tests to verify:

    • Getter/setter functionality
    • Value constraints
    • Vector4 component mapping

Would you like me to help generate:

  1. Input validation code for the properties
  2. Unit test suite for the new functionality
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 144-145: packages/core/src/material/PBRMaterial.ts#L144-L145
Added lines #L144 - L145 were not covered by tests


[warning] 148-150: packages/core/src/material/PBRMaterial.ts#L148-L150
Added lines #L148 - L150 were not covered by tests


[warning] 157-158: packages/core/src/material/PBRMaterial.ts#L157-L158
Added lines #L157 - L158 were not covered by tests


[warning] 161-163: packages/core/src/material/PBRMaterial.ts#L161-L163
Added lines #L161 - L163 were not covered by tests


[warning] 170-171: packages/core/src/material/PBRMaterial.ts#L170-L171
Added lines #L170 - L171 were not covered by tests


[warning] 174-176: packages/core/src/material/PBRMaterial.ts#L174-L176
Added lines #L174 - L176 were not covered by tests


[warning] 183-184: packages/core/src/material/PBRMaterial.ts#L183-L184
Added lines #L183 - L184 were not covered by tests


[warning] 187-189: packages/core/src/material/PBRMaterial.ts#L187-L189
Added lines #L187 - L189 were not covered by tests

🪛 GitHub Check: lint

[failure] 140-140:
Delete


[failure] 153-153:
Delete


[failure] 166-166:
Delete ↹↹


[failure] 179-179:
Delete

🪛 eslint

[error] 140-140: Delete

(prettier/prettier)


[error] 153-153: Delete

(prettier/prettier)


[error] 166-166: Delete ↹↹

(prettier/prettier)


[error] 179-179: Delete

(prettier/prettier)

Comment on lines 191 to 223
/**
* The thickness texture of the thin-film layer.
*/
get irithicknessTexture(): Texture2D {
return <Texture2D>this.shaderData.getTexture(PBRMaterial._iridescenceThicknessTextureProp);
}

set irithicknessTexture(value: Texture2D) {
this.shaderData.setTexture(PBRMaterial._iridescenceThicknessTextureProp, value);

if (value) {
this.shaderData.enableMacro("MATERIAL_HAS_IRIDESCENCE_THICKNESS_TEXTURE");
} else {
this.shaderData.disableMacro("MATERIAL_HAS_IRIDESCENCE_THICKNESS_TEXTURE");
}
}

/**
* The iridescence intensity texture.
*/
get iridescenceTexture(): Texture2D {
return <Texture2D>this.shaderData.getTexture(PBRMaterial._iridescenceTextureProp);
}

set iridescenceTexture(value: Texture2D) {
this.shaderData.setTexture(PBRMaterial._iridescenceTextureProp, value);

if (value) {
this.shaderData.enableMacro("MATERIAL_HAS_IRIDESCENCE_TEXTURE");
} else {
this.shaderData.disableMacro("MATERIAL_HAS_IRIDESCENCE_TEXTURE");
}
}
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 property name typo and add texture handling tests.

  1. The property name "irithicknessTexture" appears to be a typo and should be "iridescenceThicknessTexture" for consistency with:

    • The shader property name "_iridescenceThicknessTextureProp"
    • The macro name "MATERIAL_HAS_IRIDESCENCE_THICKNESS_TEXTURE"
    • Standard naming conventions
  2. Test Coverage: Add tests to verify:

    • Texture assignment
    • Macro enabling/disabling
    • Texture cleanup

Apply this diff to fix the property name:

-  get irithicknessTexture(): Texture2D {
+  get iridescenceThicknessTexture(): Texture2D {
     return <Texture2D>this.shaderData.getTexture(PBRMaterial._iridescenceThicknessTextureProp);
   }

-  set irithicknessTexture(value: Texture2D) {
+  set iridescenceThicknessTexture(value: Texture2D) {
     this.shaderData.setTexture(PBRMaterial._iridescenceThicknessTextureProp, value);
📝 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
/**
* The thickness texture of the thin-film layer.
*/
get irithicknessTexture(): Texture2D {
return <Texture2D>this.shaderData.getTexture(PBRMaterial._iridescenceThicknessTextureProp);
}
set irithicknessTexture(value: Texture2D) {
this.shaderData.setTexture(PBRMaterial._iridescenceThicknessTextureProp, value);
if (value) {
this.shaderData.enableMacro("MATERIAL_HAS_IRIDESCENCE_THICKNESS_TEXTURE");
} else {
this.shaderData.disableMacro("MATERIAL_HAS_IRIDESCENCE_THICKNESS_TEXTURE");
}
}
/**
* The iridescence intensity texture.
*/
get iridescenceTexture(): Texture2D {
return <Texture2D>this.shaderData.getTexture(PBRMaterial._iridescenceTextureProp);
}
set iridescenceTexture(value: Texture2D) {
this.shaderData.setTexture(PBRMaterial._iridescenceTextureProp, value);
if (value) {
this.shaderData.enableMacro("MATERIAL_HAS_IRIDESCENCE_TEXTURE");
} else {
this.shaderData.disableMacro("MATERIAL_HAS_IRIDESCENCE_TEXTURE");
}
}
/**
* The thickness texture of the thin-film layer.
*/
get iridescenceThicknessTexture(): Texture2D {
return <Texture2D>this.shaderData.getTexture(PBRMaterial._iridescenceThicknessTextureProp);
}
set iridescenceThicknessTexture(value: Texture2D) {
this.shaderData.setTexture(PBRMaterial._iridescenceThicknessTextureProp, value);
if (value) {
this.shaderData.enableMacro("MATERIAL_HAS_IRIDESCENCE_THICKNESS_TEXTURE");
} else {
this.shaderData.disableMacro("MATERIAL_HAS_IRIDESCENCE_THICKNESS_TEXTURE");
}
}
/**
* The iridescence intensity texture.
*/
get iridescenceTexture(): Texture2D {
return <Texture2D>this.shaderData.getTexture(PBRMaterial._iridescenceTextureProp);
}
set iridescenceTexture(value: Texture2D) {
this.shaderData.setTexture(PBRMaterial._iridescenceTextureProp, value);
if (value) {
this.shaderData.enableMacro("MATERIAL_HAS_IRIDESCENCE_TEXTURE");
} else {
this.shaderData.disableMacro("MATERIAL_HAS_IRIDESCENCE_TEXTURE");
}
}
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 195-196: packages/core/src/material/PBRMaterial.ts#L195-L196
Added lines #L195 - L196 were not covered by tests


[warning] 199-206: packages/core/src/material/PBRMaterial.ts#L199-L206
Added lines #L199 - L206 were not covered by tests


[warning] 212-213: packages/core/src/material/PBRMaterial.ts#L212-L213
Added lines #L212 - L213 were not covered by tests


[warning] 216-223: packages/core/src/material/PBRMaterial.ts#L216-L223
Added lines #L216 - L223 were not covered by tests

🪛 GitHub Check: lint

[failure] 192-192:
Delete


[failure] 209-209:
Delete

🪛 eslint

[error] 192-192: Delete

(prettier/prettier)


[error] 209-209: Delete

(prettier/prettier)

Comment on lines 23 to 25
private static _iridescenceProp = ShaderProperty.getByName("material_IridescenceInfo");
private static _iridescenceThicknessTextureProp = ShaderProperty.getByName("material_IridescenceThicknessTexture");
private static _iridescenceTextureProp = ShaderProperty.getByName("material_IridescenceTexture");
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Missing shader variable declarations for iridescence properties

The shader properties defined in PBRMaterial.ts do not have corresponding uniform declarations in the shader files. The following uniforms are missing in the PBR shader files:

  • material_IridescenceInfo
  • material_IridescenceThicknessTexture
  • material_IridescenceTexture

This indicates that either:

  1. The shader implementation for iridescence is incomplete, or
  2. The shader properties are defined prematurely before their shader counterparts.
🔗 Analysis chain

LGTM! Verify shader variable declarations.

The shader property declarations look good and follow the existing naming pattern.

Let's verify the shader variable declarations:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for corresponding shader variable declarations
rg "material_IridescenceInfo|material_IridescenceThicknessTexture|material_IridescenceTexture" -t glsl

Length of output: 133


Script:

#!/bin/bash
# Search for shader files and then look for iridescence variables
fd -e frag -e vert -e glsl | xargs rg "material_IridescenceInfo|material_IridescenceThicknessTexture|material_IridescenceTexture"

# Also search with different file extensions that might contain shader code
fd -e shader | xargs rg "material_IridescenceInfo|material_IridescenceThicknessTexture|material_IridescenceTexture"

# Look for any files containing shader-related content
rg -l "uniform|varying|precision" --type-add 'shader:*.{frag,vert,glsl,shader}' -tshader

Length of output: 3327


Script:

#!/bin/bash
# Let's specifically check PBR shader files and material-related shader files
rg -l "material_" packages/core/src/shaderlib/pbr/
rg "material_" -A 5 -B 5 packages/core/src/shaderlib/pbr/pbr_frag_define.glsl

# Also check for any uniform declarations in PBR shaders
rg "uniform" -A 2 packages/core/src/shaderlib/pbr/pbr_frag_define.glsl

# Check for other material properties to understand the pattern
rg "material_[A-Z]" packages/core/src/shaderlib/pbr/

Length of output: 8678

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b5b9a0a and d7a82de.

📒 Files selected for processing (1)
  • packages/core/src/material/PBRMaterial.ts (4 hunks)
🧰 Additional context used
🪛 Biome
packages/core/src/material/PBRMaterial.ts

[error] 162-162: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 162-162: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 166-166: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 166-166: expected , but instead found :

Remove :

(parse)


[error] 166-166: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 175-175: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 175-175: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 179-179: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 179-179: expected , but instead found :

Remove :

(parse)


[error] 179-179: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 188-188: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 188-188: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 192-192: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 192-192: expected , but instead found :

Remove :

(parse)


[error] 192-192: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 200-200: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 200-200: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 204-204: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 204-204: expected , but instead found :

Remove :

(parse)


[error] 204-204: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 217-217: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 217-217: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 221-221: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 221-221: expected , but instead found :

Remove :

(parse)


[error] 221-221: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 163-163: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 176-176: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 189-189: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 201-201: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 218-218: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 166-175: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 175-188: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 188-200: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 200-204: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 205-211: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 217-217: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 217-221: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 222-228: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 162-164: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 175-177: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 188-190: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 200-202: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 204-212: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 217-219: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 221-229: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

🪛 eslint
packages/core/src/material/PBRMaterial.ts

[error] 162-162: Parsing error: Unexpected keyword or identifier.

🔇 Additional comments (4)
packages/core/src/material/PBRMaterial.ts (4)

23-25: LGTM! Static shader properties follow the established pattern.

The static shader properties are correctly defined using ShaderProperty.getByName() and follow the existing naming convention.


243-244: LGTM! Constructor initialization with sensible defaults.

The default values align with the GLTF specification:

  • iridescenceFactor: 0 (disabled by default)
  • iridescenceIor: 1.3 (common value for thin films)
  • thickness range: 100-400 nanometers (typical range for iridescent effects)

Line range hint 1-244: Add unit tests for iridescence properties.

The code coverage report indicates missing test coverage for the new iridescence properties.

Would you like me to help generate:

  1. Unit tests for getters/setters
  2. Tests for value constraints
  3. Tests for macro enabling/disabling
🧰 Tools
🪛 Biome

[error] 162-162: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 162-162: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 166-166: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 166-166: expected , but instead found :

Remove :

(parse)


[error] 166-166: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 175-175: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 175-175: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 179-179: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 179-179: expected , but instead found :

Remove :

(parse)


[error] 179-179: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 188-188: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 188-188: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 192-192: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 192-192: expected , but instead found :

Remove :

(parse)


[error] 192-192: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 200-200: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 200-200: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 204-204: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 204-204: expected , but instead found :

Remove :

(parse)


[error] 204-204: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 217-217: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 217-217: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 221-221: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 221-221: expected , but instead found :

Remove :

(parse)


[error] 221-221: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 163-163: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 176-176: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 189-189: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 201-201: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 218-218: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 166-175: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 175-188: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 188-200: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 200-204: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 205-211: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 217-217: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 217-221: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 222-228: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 162-164: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 175-177: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 188-190: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 200-202: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 204-212: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 217-219: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 221-229: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

🪛 eslint

[error] 162-162: Parsing error: Unexpected keyword or identifier.


197-212: ⚠️ Potential issue

Fix property name typo: "irithicknessTexture" → "iridescenceThicknessTexture".

The property name has a typo and should be consistent with other iridescence-related names.

🧰 Tools
🪛 Biome

[error] 200-200: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 200-200: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 204-204: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 204-204: expected , but instead found :

Remove :

(parse)


[error] 204-204: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 201-201: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 200-204: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 205-211: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 200-202: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 204-212: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

Comment on lines 139 to 156
/**
* The iridescence intensity factor.
* @defaultValue `1.0`
*/
get iridescenceFactor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceProp).x;
}

set iridescenceFactor(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
if (!!IridescenceInfo.x !== !!value) {
if (value === 0) {
this.shaderData.disableMacro("MATERIAL_ENABLE_IRIDESCENCE");
} else {
this.shaderData.enableMacro("MATERIAL_ENABLE_IRIDESCENCE");
}
IridescenceInfo.x = value;
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add input validation for iridescenceFactor.

The iridescenceFactor should be clamped to the range [0,1] as it represents an intensity value.

Apply this diff to add validation:

  set iridescenceFactor(value: number) {
    const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
+   value = Math.max(0, Math.min(1, value));
    if (!!IridescenceInfo.x !== !!value) {
      if (value === 0) {
        this.shaderData.disableMacro("MATERIAL_ENABLE_IRIDESCENCE");
      } else {
        this.shaderData.enableMacro("MATERIAL_ENABLE_IRIDESCENCE");
      }
    }
    IridescenceInfo.x = value;
  }
📝 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
/**
* The iridescence intensity factor.
* @defaultValue `1.0`
*/
get iridescenceFactor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceProp).x;
}
set iridescenceFactor(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
if (!!IridescenceInfo.x !== !!value) {
if (value === 0) {
this.shaderData.disableMacro("MATERIAL_ENABLE_IRIDESCENCE");
} else {
this.shaderData.enableMacro("MATERIAL_ENABLE_IRIDESCENCE");
}
IridescenceInfo.x = value;
}
/**
* The iridescence intensity factor.
* @defaultValue `1.0`
*/
get iridescenceFactor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceProp).x;
}
set iridescenceFactor(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
value = Math.max(0, Math.min(1, value));
if (!!IridescenceInfo.x !== !!value) {
if (value === 0) {
this.shaderData.disableMacro("MATERIAL_ENABLE_IRIDESCENCE");
} else {
this.shaderData.enableMacro("MATERIAL_ENABLE_IRIDESCENCE");
}
}
IridescenceInfo.x = value;
}

Comment on lines 158 to 169
/**
* The index of refraction of the dielectric thin-film layer.
* @defaultValue `1.3`
*/
get iridescenceIor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceProp).y;
}

set iridescenceIor(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
IridescenceInfo.y = value;
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add input validation for iridescenceIor.

The index of refraction (IOR) must be greater than 1.0 as it represents a physical property.

Apply this diff to add validation:

  set iridescenceIor(value: number) {
    const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
+   value = Math.max(1.0, value);
    IridescenceInfo.y = value;
  }
📝 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
/**
* The index of refraction of the dielectric thin-film layer.
* @defaultValue `1.3`
*/
get iridescenceIor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceProp).y;
}
set iridescenceIor(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
IridescenceInfo.y = value;
}
/**
* The index of refraction of the dielectric thin-film layer.
* @defaultValue `1.3`
*/
get iridescenceIor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceProp).y;
}
set iridescenceIor(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
value = Math.max(1.0, value);
IridescenceInfo.y = value;
}
🧰 Tools
🪛 Biome

[error] 162-162: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 162-162: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 166-166: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 166-166: expected , but instead found :

Remove :

(parse)


[error] 166-166: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 163-163: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 162-164: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

🪛 eslint

[error] 162-162: Parsing error: Unexpected keyword or identifier.

Comment on lines 171 to 195
/**
* The minimum thickness of the thin-film layer given in nanometers.
* @defaultValue `100`
*/
get iridescenceThicknessMin(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceProp).z;
}

set iridescenceThicknessMin(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
IridescenceInfo.z = value;
}

/**
* The maximum thickness of the thin-film layer given in nanometers.
* @defaultValue `400`
*/
get iridescenceThicknessMax(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceProp).w;
}

set iridescenceThicknessMax(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
IridescenceInfo.w = value;
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add validation for thickness values.

The thickness values should be:

  1. Non-negative
  2. Min should be less than max

Apply this diff to add validation:

  set iridescenceThicknessMin(value: number) {
    const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
+   value = Math.max(0, value);
+   const maxThickness = IridescenceInfo.w;
+   if (value >= maxThickness) {
+     value = maxThickness * 0.9; // Ensure min is less than max
+   }
    IridescenceInfo.z = value;
  }

  set iridescenceThicknessMax(value: number) {
    const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
+   value = Math.max(0, value);
+   const minThickness = IridescenceInfo.z;
+   if (value <= minThickness) {
+     value = minThickness * 1.1; // Ensure max is greater than min
+   }
    IridescenceInfo.w = value;
  }
📝 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
/**
* The minimum thickness of the thin-film layer given in nanometers.
* @defaultValue `100`
*/
get iridescenceThicknessMin(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceProp).z;
}
set iridescenceThicknessMin(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
IridescenceInfo.z = value;
}
/**
* The maximum thickness of the thin-film layer given in nanometers.
* @defaultValue `400`
*/
get iridescenceThicknessMax(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceProp).w;
}
set iridescenceThicknessMax(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
IridescenceInfo.w = value;
}
/**
* The minimum thickness of the thin-film layer given in nanometers.
* @defaultValue `100`
*/
get iridescenceThicknessMin(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceProp).z;
}
set iridescenceThicknessMin(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
value = Math.max(0, value);
const maxThickness = IridescenceInfo.w;
if (value >= maxThickness) {
value = maxThickness * 0.9; // Ensure min is less than max
}
IridescenceInfo.z = value;
}
/**
* The maximum thickness of the thin-film layer given in nanometers.
* @defaultValue `400`
*/
get iridescenceThicknessMax(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceProp).w;
}
set iridescenceThicknessMax(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
value = Math.max(0, value);
const minThickness = IridescenceInfo.z;
if (value <= minThickness) {
value = minThickness * 1.1; // Ensure max is greater than min
}
IridescenceInfo.w = value;
}
🧰 Tools
🪛 Biome

[error] 175-175: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 175-175: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 179-179: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 179-179: expected , but instead found :

Remove :

(parse)


[error] 179-179: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 188-188: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 188-188: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 192-192: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 192-192: expected , but instead found :

Remove :

(parse)


[error] 192-192: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 176-176: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 189-189: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 175-188: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 175-177: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 188-190: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

@zhuxudong zhuxudong added the Rendering Rendering related functions label Nov 8, 2024
@zhuxudong zhuxudong added this to the 1.4 milestone Nov 8, 2024
@@ -132,6 +136,98 @@ export class PBRMaterial extends PBRBaseMaterial {
}
}

/**
* The iridescence intensity factor.
* @defaultValue `1.0`
Copy link
Member

Choose a reason for hiding this comment

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

default is 0

clearcoatTexture?: ITextureInfo;
clearcoatRoughnessFactor?: number;
clearcoatRoughnessTexture?: ITextureInfo;
clearcoatNormalTexture?: IMaterialNormalTextureInfo;
Copy link
Member

Choose a reason for hiding this comment

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

thank you

material.iridescenceFactor = iridescenceFactor;
material.iridescenceIor = iridescenceIor;
material.iridescenceThicknessMin = iridescenceThicknessMaximum;
material.iridescenceThicknessMax = iridescenceThicknessMinimum;
Copy link
Member

Choose a reason for hiding this comment

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

revert min/max

/**
* The thickness texture of the thin-film layer.
*/
get irithicknessTexture(): Texture2D {
Copy link
Member

Choose a reason for hiding this comment

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

iri is not a good abbreviation, use iridescenceThicknessTexture to instead

}

set iridescenceThicknessMax(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
Copy link
Member

Choose a reason for hiding this comment

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

variable start with lowercase, such as iridescenceInfo

}

set iridescenceIor(value: number) {
const IridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceProp);
Copy link
Member

Choose a reason for hiding this comment

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

the same as below

@zhuxudong
Copy link
Member

do not submit code bypass the hook such asprettier, it cause some ci and symbol error 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: 3

🧹 Outside diff range and nitpick comments (3)
packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts (2)

20-24: Fix formatting: Remove leading spaces

The linter detected extra spaces at the beginning of these lines.

-     material.iridescenceFactor = iridescenceFactor;
-     material.iridescenceIor = iridescenceIor;
-     material.iridescenceThicknessMin = iridescenceThicknessMinimum;
-     material.iridescenceThicknessMax = iridescenceThicknessMaximum;
+    material.iridescenceFactor = iridescenceFactor;
+    material.iridescenceIor = iridescenceIor;
+    material.iridescenceThicknessMin = iridescenceThicknessMinimum;
+    material.iridescenceThicknessMax = iridescenceThicknessMaximum;
🧰 Tools
🪛 GitHub Check: lint

[failure] 20-20:
Delete ·


[failure] 21-21:
Delete ·


[failure] 22-22:
Delete ·


[failure] 23-23:
Delete ·


[failure] 24-24:
Delete ·

🪛 eslint

[error] 20-20: Delete ·

(prettier/prettier)


[error] 21-21: Delete ·

(prettier/prettier)


[error] 22-22: Delete ·

(prettier/prettier)


[error] 23-23: Delete ·

(prettier/prettier)


[error] 24-24: Delete ·

(prettier/prettier)


25-38: Consider enhancing error handling for texture loading

The texture loading implementation looks good, but consider adding error handling for the Promise chains.

 context.get<Texture2D>(GLTFParserType.Texture, iridescenceTexture.index).then((texture) => {
   material.iridescenceTexture = texture;
-});
+}).catch(error => {
+  console.warn(`Failed to load iridescence texture: ${error}`);
+});
packages/core/src/material/PBRMaterial.ts (1)

244-245: Add test coverage for iridescence properties.

The initialization looks good, but test coverage is missing for the iridescence properties according to static analysis.

Would you like me to help generate unit tests to cover:

  1. Default value initialization
  2. Getter/setter functionality
  3. Value constraints
  4. Texture handling
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d7a82de and 76c5423.

📒 Files selected for processing (2)
  • packages/core/src/material/PBRMaterial.ts (4 hunks)
  • packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts (1 hunks)
🧰 Additional context used
🪛 Biome
packages/core/src/material/PBRMaterial.ts

[error] 162-162: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 162-162: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 166-166: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 166-166: expected , but instead found :

Remove :

(parse)


[error] 166-166: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 175-175: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 175-175: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 180-180: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 180-180: expected , but instead found :

Remove :

(parse)


[error] 180-180: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 189-189: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 189-189: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 193-193: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 193-193: expected , but instead found :

Remove :

(parse)


[error] 193-193: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 201-201: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 201-201: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 205-205: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 205-205: expected , but instead found :

Remove :

(parse)


[error] 205-205: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 218-218: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 218-218: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 222-222: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 222-222: expected , but instead found :

Remove :

(parse)


[error] 222-222: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 163-163: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 176-176: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 190-190: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 202-202: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 219-219: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 166-175: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 175-189: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 189-201: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 201-205: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 206-212: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 218-218: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 218-222: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 223-229: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 162-164: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 175-178: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 189-191: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 201-203: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 205-213: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 218-220: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 222-230: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

🪛 GitHub Check: lint
packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts

[failure] 20-20:
Delete ·


[failure] 21-21:
Delete ·


[failure] 22-22:
Delete ·


[failure] 23-23:
Delete ·


[failure] 24-24:
Delete ·

🪛 eslint
packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts

[error] 20-20: Delete ·

(prettier/prettier)


[error] 21-21: Delete ·

(prettier/prettier)


[error] 22-22: Delete ·

(prettier/prettier)


[error] 23-23: Delete ·

(prettier/prettier)


[error] 24-24: Delete ·

(prettier/prettier)

🔇 Additional comments (4)
packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts (2)

1-9: LGTM! Clean implementation of GLTF extension setup

The imports are complete and the extension registration is properly configured.


10-18: Verify default values against GLTF spec

Please ensure the default values align with the KHR_materials_iridescence specification:

  • iridescenceFactor = 0
  • iridescenceIor = 1.3
  • iridescenceThicknessMinimum = 100
  • iridescenceThicknessMaximum = 400
✅ Verification successful

Default values match KHR_materials_iridescence specification

The default values implemented in the code align with the official KHR_materials_iridescence extension specification:

  • iridescenceFactor = 0: This is the correct default as per spec, making iridescence effect disabled by default
  • iridescenceIor = 1.3: This is the standard default IOR value for iridescence
  • iridescenceThicknessMinimum = 100 and iridescenceThicknessMaximum = 400: These are the correct default thickness range values

The implementation follows the standard schema interface IKHRMaterialsIridescence and properly handles all optional parameters with their spec-compliant default values.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any GLTF spec documentation files
fd -e md -e txt "KHR_materials_iridescence" | xargs rg "default.*value.*iridescence"

Length of output: 84


Script:

#!/bin/bash
# Let's try searching for any documentation or spec files related to iridescence
rg -i "iridescence.*default" -A 5 -B 5

# Also search for any test files that might validate these defaults
fd -e test.ts -e spec.ts | xargs rg "iridescence.*=.*[0-9]"

# Search for any constant definitions that might reference the spec
rg "const.*iridescence.*=.*[0-9]"

Length of output: 666


Script:

#!/bin/bash
# Let's check the KHR_materials_iridescence implementation in other major 3D engines/libraries
# to validate these default values, as they might be following the spec

# Search for any comments or documentation in the implementation file
rg -i "khr.*iridescence" -B 5 -A 5 packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts

# Also search for any test cases that might validate the behavior
fd -e test.ts -e spec.ts | xargs rg "KHR_materials_iridescence"

# Look for any schema definitions that might contain spec information
rg "interface.*IKHRMaterialsIridescence" -A 10

Length of output: 2015

packages/core/src/material/PBRMaterial.ts (2)

23-25: LGTM!

The shader property declarations follow the existing naming pattern consistently.


201-230: LGTM!

The texture property implementations follow the established pattern consistently, including proper macro management.

🧰 Tools
🪛 Biome

[error] 201-201: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 201-201: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 205-205: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 205-205: expected , but instead found :

Remove :

(parse)


[error] 205-205: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 218-218: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 218-218: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 222-222: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 222-222: expected , but instead found :

Remove :

(parse)


[error] 222-222: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 202-202: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 219-219: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 201-205: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 206-212: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 218-218: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 218-222: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 223-229: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 201-203: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 205-213: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 218-220: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 222-230: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

Comment on lines +166 to +169
set iridescenceIor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.y = value;
}
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 validation for iridescence IOR.

The index of refraction must be greater than 1.0 as it represents a physical property.

Apply this diff to add validation:

  set iridescenceIor(value: number) {
    const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
+   value = Math.max(1.0, value);
    iridescenceInfo.y = value;
  }
📝 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
set iridescenceIor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.y = value;
}
set iridescenceIor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
value = Math.max(1.0, value);
iridescenceInfo.y = value;
}
🧰 Tools
🪛 Biome

[error] 166-166: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 166-166: expected , but instead found :

Remove :

(parse)


[error] 166-166: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 166-175: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)

Comment on lines 147 to 156
set iridescenceFactor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
if (!!iridescenceInfo.x !== !!value) {
if (value === 0) {
this.shaderData.disableMacro("MATERIAL_ENABLE_IRIDESCENCE");
} else {
this.shaderData.enableMacro("MATERIAL_ENABLE_IRIDESCENCE");
}
iridescenceInfo.x = value;
}
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 iridescence factor implementation.

There are two issues in the implementation:

  1. The value should be clamped to [0,1] range as it represents an intensity factor
  2. The value is set after the macro check, which could lead to inconsistent state

Apply this diff to fix both issues:

  set iridescenceFactor(value: number) {
    const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
+   value = Math.max(0, Math.min(1, value));
    if (!!iridescenceInfo.x !== !!value) {
      if (value === 0) {
        this.shaderData.disableMacro("MATERIAL_ENABLE_IRIDESCENCE");
      } else {
        this.shaderData.enableMacro("MATERIAL_ENABLE_IRIDESCENCE");
      }
-     iridescenceInfo.x = value;
    }
+   iridescenceInfo.x = value;
  }
📝 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
set iridescenceFactor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
if (!!iridescenceInfo.x !== !!value) {
if (value === 0) {
this.shaderData.disableMacro("MATERIAL_ENABLE_IRIDESCENCE");
} else {
this.shaderData.enableMacro("MATERIAL_ENABLE_IRIDESCENCE");
}
iridescenceInfo.x = value;
}
set iridescenceFactor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
value = Math.max(0, Math.min(1, value));
if (!!iridescenceInfo.x !== !!value) {
if (value === 0) {
this.shaderData.disableMacro("MATERIAL_ENABLE_IRIDESCENCE");
} else {
this.shaderData.enableMacro("MATERIAL_ENABLE_IRIDESCENCE");
}
}
iridescenceInfo.x = value;
}

Comment on lines 180 to 196
set iridescenceThicknessMin(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.z = value;
}

/**
* The maximum thickness of the thin-film layer given in nanometers.
* @defaultValue `400`
*/
get iridescenceThicknessMax(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).w;
}

set iridescenceThicknessMax(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.w = value;
}
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 validation for thickness values.

The thickness values need validation to ensure:

  1. Non-negative values (physical constraint)
  2. Minimum thickness is less than maximum thickness

Apply this diff to add validation:

  set iridescenceThicknessMin(value: number) {
    const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
+   value = Math.max(0, value);
+   const maxThickness = iridescenceInfo.w;
+   if (value >= maxThickness) {
+     value = maxThickness * 0.9; // Ensure min is less than max
+   }
    iridescenceInfo.z = value;
  }

  set iridescenceThicknessMax(value: number) {
    const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
+   value = Math.max(0, value);
+   const minThickness = iridescenceInfo.z;
+   if (value <= minThickness) {
+     value = minThickness * 1.1; // Ensure max is greater than min
+   }
    iridescenceInfo.w = value;
  }
📝 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
set iridescenceThicknessMin(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.z = value;
}
/**
* The maximum thickness of the thin-film layer given in nanometers.
* @defaultValue `400`
*/
get iridescenceThicknessMax(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).w;
}
set iridescenceThicknessMax(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.w = value;
}
set iridescenceThicknessMin(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
value = Math.max(0, value);
const maxThickness = iridescenceInfo.w;
if (value >= maxThickness) {
value = maxThickness * 0.9; // Ensure min is less than max
}
iridescenceInfo.z = value;
}
/**
* The maximum thickness of the thin-film layer given in nanometers.
* @defaultValue `400`
*/
get iridescenceThicknessMax(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).w;
}
set iridescenceThicknessMax(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
value = Math.max(0, value);
const minThickness = iridescenceInfo.z;
if (value <= minThickness) {
value = minThickness * 1.1; // Ensure max is greater than min
}
iridescenceInfo.w = value;
}
🧰 Tools
🪛 Biome

[error] 180-180: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 180-180: expected , but instead found :

Remove :

(parse)


[error] 180-180: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 189-189: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 189-189: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 193-193: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 193-193: expected , but instead found :

Remove :

(parse)


[error] 193-193: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 190-190: The setter should not return a value.

The setter is here:

Returning a value from a setter is ignored.

(lint/correctness/noSetterReturn)


[error] 189-191: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

@hhhhkrx hhhhkrx changed the title gltf iridescence Gltf Iridescence Nov 11, 2024
@hhhhkrx hhhhkrx added glTF material shader Shader related functions labels Nov 11, 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: 3

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

199-231: LGTM! Consider adding test coverage.

The texture properties are implemented correctly, following the existing pattern for texture handling in the class. However, test coverage is missing for these properties.

Would you like me to help generate unit tests for the texture properties?

🧰 Tools
🪛 eslint

[error] 200-200: Delete

(prettier/prettier)


[error] 217-217: Delete

(prettier/prettier)


[error] 231-231: Delete ·

(prettier/prettier)

🪛 GitHub Check: codecov/patch

[warning] 203-204: packages/core/src/material/PBRMaterial.ts#L203-L204
Added lines #L203 - L204 were not covered by tests


[warning] 207-207: packages/core/src/material/PBRMaterial.ts#L207
Added line #L207 was not covered by tests


[warning] 209-214: packages/core/src/material/PBRMaterial.ts#L209-L214
Added lines #L209 - L214 were not covered by tests


[warning] 220-220: packages/core/src/material/PBRMaterial.ts#L220
Added line #L220 was not covered by tests


[warning] 224-231: packages/core/src/material/PBRMaterial.ts#L224-L231
Added lines #L224 - L231 were not covered by tests

🪛 GitHub Check: lint

[failure] 200-200:
Delete


[failure] 217-217:
Delete


[failure] 231-231:
Delete ·

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 76c5423 and aa41aaf.

📒 Files selected for processing (1)
  • packages/core/src/material/PBRMaterial.ts (3 hunks)
🧰 Additional context used
🪛 eslint
packages/core/src/material/PBRMaterial.ts

[error] 140-140: Delete

(prettier/prettier)


[error] 160-160: Delete

(prettier/prettier)


[error] 173-173: Delete ↹↹

(prettier/prettier)


[error] 177-178: Delete

(prettier/prettier)


[error] 187-187: Delete

(prettier/prettier)


[error] 200-200: Delete

(prettier/prettier)


[error] 217-217: Delete

(prettier/prettier)


[error] 231-231: Delete ·

(prettier/prettier)


[error] 233-233: Insert ··

(prettier/prettier)


[error] 234-234: Insert ··

(prettier/prettier)


[error] 235-235: Insert ··

(prettier/prettier)


[error] 236-236: Insert ··

(prettier/prettier)


[error] 237-237: Insert ··

(prettier/prettier)


[error] 238-238: Insert ··

(prettier/prettier)


[error] 240-240: Replace ·· with ····

(prettier/prettier)


[error] 241-241: Insert ··

(prettier/prettier)


[error] 242-242: Insert ··

(prettier/prettier)


[error] 243-243: Replace ·· with ····

(prettier/prettier)


[error] 244-244: Insert ··

(prettier/prettier)


[error] 245-245: Insert ··

(prettier/prettier)


[error] 246-247: Replace with ··

(prettier/prettier)


[error] 253-253: Insert ··

(prettier/prettier)


[error] 254-254: Replace ·· with ····

(prettier/prettier)


[error] 255-255: Insert ··

(prettier/prettier)


[error] 256-256: Insert ··

(prettier/prettier)

🪛 GitHub Check: codecov/patch
packages/core/src/material/PBRMaterial.ts

[warning] 144-145: packages/core/src/material/PBRMaterial.ts#L144-L145
Added lines #L144 - L145 were not covered by tests


[warning] 148-157: packages/core/src/material/PBRMaterial.ts#L148-L157
Added lines #L148 - L157 were not covered by tests


[warning] 164-165: packages/core/src/material/PBRMaterial.ts#L164-L165
Added lines #L164 - L165 were not covered by tests


[warning] 168-170: packages/core/src/material/PBRMaterial.ts#L168-L170
Added lines #L168 - L170 were not covered by tests


[warning] 177-179: packages/core/src/material/PBRMaterial.ts#L177-L179
Added lines #L177 - L179 were not covered by tests


[warning] 182-184: packages/core/src/material/PBRMaterial.ts#L182-L184
Added lines #L182 - L184 were not covered by tests


[warning] 191-192: packages/core/src/material/PBRMaterial.ts#L191-L192
Added lines #L191 - L192 were not covered by tests


[warning] 195-197: packages/core/src/material/PBRMaterial.ts#L195-L197
Added lines #L195 - L197 were not covered by tests


[warning] 203-204: packages/core/src/material/PBRMaterial.ts#L203-L204
Added lines #L203 - L204 were not covered by tests


[warning] 207-207: packages/core/src/material/PBRMaterial.ts#L207
Added line #L207 was not covered by tests


[warning] 209-214: packages/core/src/material/PBRMaterial.ts#L209-L214
Added lines #L209 - L214 were not covered by tests


[warning] 220-220: packages/core/src/material/PBRMaterial.ts#L220
Added line #L220 was not covered by tests


[warning] 224-231: packages/core/src/material/PBRMaterial.ts#L224-L231
Added lines #L224 - L231 were not covered by tests

🪛 GitHub Check: lint
packages/core/src/material/PBRMaterial.ts

[failure] 140-140:
Delete


[failure] 160-160:
Delete


[failure] 173-173:
Delete ↹↹


[failure] 177-177:
Delete


[failure] 187-187:
Delete


[failure] 200-200:
Delete


[failure] 217-217:
Delete


[failure] 231-231:
Delete ·


[failure] 233-233:
Insert ··


[failure] 234-234:
Insert ··

🔇 Additional comments (2)
packages/core/src/material/PBRMaterial.ts (2)

23-25: LGTM!

The shader properties are correctly defined following the existing pattern in the class.


233-247: LGTM!

The constructor correctly initializes the iridescence properties with appropriate default values.

🧰 Tools
🪛 eslint

[error] 233-233: Insert ··

(prettier/prettier)


[error] 234-234: Insert ··

(prettier/prettier)


[error] 235-235: Insert ··

(prettier/prettier)


[error] 236-236: Insert ··

(prettier/prettier)


[error] 237-237: Insert ··

(prettier/prettier)


[error] 238-238: Insert ··

(prettier/prettier)


[error] 240-240: Replace ·· with ····

(prettier/prettier)


[error] 241-241: Insert ··

(prettier/prettier)


[error] 242-242: Insert ··

(prettier/prettier)


[error] 243-243: Replace ·· with ····

(prettier/prettier)


[error] 244-244: Insert ··

(prettier/prettier)


[error] 245-245: Insert ··

(prettier/prettier)


[error] 246-247: Replace with ··

(prettier/prettier)

🪛 GitHub Check: lint

[failure] 233-233:
Insert ··


[failure] 234-234:
Insert ··

Comment on lines 159 to 170
/**
* The index of refraction of the dielectric thin-film layer.
* @defaultValue `1.3`
*/
get iridescenceIor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).y;
}

set iridescenceIor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.y = value;
}
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 validation for iridescence IOR.

The index of refraction must be greater than 1.0 as it represents a physical property.

Apply this diff to add validation:

  set iridescenceIor(value: number) {
    const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
+   value = Math.max(1.0, value);
    iridescenceInfo.y = value;
  }

Would you like me to help generate unit tests for this property?

📝 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
/**
* The index of refraction of the dielectric thin-film layer.
* @defaultValue `1.3`
*/
get iridescenceIor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).y;
}
set iridescenceIor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.y = value;
}
/**
* The index of refraction of the dielectric thin-film layer.
* @defaultValue `1.3`
*/
get iridescenceIor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).y;
}
set iridescenceIor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
value = Math.max(1.0, value);
iridescenceInfo.y = value;
}
🧰 Tools
🪛 eslint

[error] 160-160: Delete

(prettier/prettier)

🪛 GitHub Check: codecov/patch

[warning] 164-165: packages/core/src/material/PBRMaterial.ts#L164-L165
Added lines #L164 - L165 were not covered by tests


[warning] 168-170: packages/core/src/material/PBRMaterial.ts#L168-L170
Added lines #L168 - L170 were not covered by tests

🪛 GitHub Check: lint

[failure] 160-160:
Delete

Comment on lines 140 to 157
* The iridescence intensity factor.
* @defaultValue `0.0`
*/
get iridescenceFactor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).x;
}

set iridescenceFactor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
if (!!iridescenceInfo.x !== !!value) {
if (value === 0) {
this.shaderData.disableMacro("MATERIAL_ENABLE_IRIDESCENCE");
} else {
this.shaderData.enableMacro("MATERIAL_ENABLE_IRIDESCENCE");
}
iridescenceInfo.x = value;
}
}
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 iridescence factor implementation.

The implementation has several issues:

  1. The value should be clamped to [0,1] range as it represents an intensity factor
  2. The value is set after the macro check, which could lead to inconsistent state
  3. Missing test coverage

Apply this diff to fix the implementation:

  set iridescenceFactor(value: number) {
    const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
+   value = Math.max(0, Math.min(1, value));
    if (!!iridescenceInfo.x !== !!value) {
      if (value === 0) {
        this.shaderData.disableMacro("MATERIAL_ENABLE_IRIDESCENCE");
      } else {
        this.shaderData.enableMacro("MATERIAL_ENABLE_IRIDESCENCE");
      }
-     iridescenceInfo.x = value;
    }
+   iridescenceInfo.x = value;
  }

Would you like me to help generate unit tests for this property?

📝 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
* The iridescence intensity factor.
* @defaultValue `0.0`
*/
get iridescenceFactor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).x;
}
set iridescenceFactor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
if (!!iridescenceInfo.x !== !!value) {
if (value === 0) {
this.shaderData.disableMacro("MATERIAL_ENABLE_IRIDESCENCE");
} else {
this.shaderData.enableMacro("MATERIAL_ENABLE_IRIDESCENCE");
}
iridescenceInfo.x = value;
}
}
* The iridescence intensity factor.
* @defaultValue `0.0`
*/
get iridescenceFactor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).x;
}
set iridescenceFactor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
value = Math.max(0, Math.min(1, value));
if (!!iridescenceInfo.x !== !!value) {
if (value === 0) {
this.shaderData.disableMacro("MATERIAL_ENABLE_IRIDESCENCE");
} else {
this.shaderData.enableMacro("MATERIAL_ENABLE_IRIDESCENCE");
}
}
iridescenceInfo.x = value;
}
🧰 Tools
🪛 eslint

[error] 140-140: Delete

(prettier/prettier)

🪛 GitHub Check: codecov/patch

[warning] 144-145: packages/core/src/material/PBRMaterial.ts#L144-L145
Added lines #L144 - L145 were not covered by tests


[warning] 148-157: packages/core/src/material/PBRMaterial.ts#L148-L157
Added lines #L148 - L157 were not covered by tests

🪛 GitHub Check: lint

[failure] 140-140:
Delete

Comment on lines 172 to 197
/**
* The minimum thickness of the thin-film layer given in nanometers.
* @defaultValue `100`
*/
get iridescenceThicknessMin(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).z;

}

set iridescenceThicknessMin(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.z = value;
}

/**
* The maximum thickness of the thin-film layer given in nanometers.
* @defaultValue `400`
*/
get iridescenceThicknessMax(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).w;
}

set iridescenceThicknessMax(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.w = value;
}
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 validation for thickness values.

The thickness values need validation to ensure:

  1. Non-negative values (physical constraint)
  2. Minimum thickness is less than maximum thickness

Apply this diff to add validation:

  set iridescenceThicknessMin(value: number) {
    const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
+   value = Math.max(0, value);
+   const maxThickness = iridescenceInfo.w;
+   if (value >= maxThickness) {
+     value = maxThickness * 0.9; // Ensure min is less than max
+   }
    iridescenceInfo.z = value;
  }

  set iridescenceThicknessMax(value: number) {
    const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
+   value = Math.max(0, value);
+   const minThickness = iridescenceInfo.z;
+   if (value <= minThickness) {
+     value = minThickness * 1.1; // Ensure max is greater than min
+   }
    iridescenceInfo.w = value;
  }

Would you like me to help generate unit tests for these properties?

📝 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
/**
* The minimum thickness of the thin-film layer given in nanometers.
* @defaultValue `100`
*/
get iridescenceThicknessMin(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).z;
}
set iridescenceThicknessMin(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.z = value;
}
/**
* The maximum thickness of the thin-film layer given in nanometers.
* @defaultValue `400`
*/
get iridescenceThicknessMax(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).w;
}
set iridescenceThicknessMax(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.w = value;
}
/**
* The minimum thickness of the thin-film layer given in nanometers.
* @defaultValue `100`
*/
get iridescenceThicknessMin(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).z;
}
set iridescenceThicknessMin(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
value = Math.max(0, value);
const maxThickness = iridescenceInfo.w;
if (value >= maxThickness) {
value = maxThickness * 0.9; // Ensure min is less than max
}
iridescenceInfo.z = value;
}
/**
* The maximum thickness of the thin-film layer given in nanometers.
* @defaultValue `400`
*/
get iridescenceThicknessMax(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).w;
}
set iridescenceThicknessMax(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
value = Math.max(0, value);
const minThickness = iridescenceInfo.z;
if (value <= minThickness) {
value = minThickness * 1.1; // Ensure max is greater than min
}
iridescenceInfo.w = value;
}
🧰 Tools
🪛 eslint

[error] 173-173: Delete ↹↹

(prettier/prettier)


[error] 177-178: Delete

(prettier/prettier)


[error] 187-187: Delete

(prettier/prettier)

🪛 GitHub Check: codecov/patch

[warning] 177-179: packages/core/src/material/PBRMaterial.ts#L177-L179
Added lines #L177 - L179 were not covered by tests


[warning] 182-184: packages/core/src/material/PBRMaterial.ts#L182-L184
Added lines #L182 - L184 were not covered by tests


[warning] 191-192: packages/core/src/material/PBRMaterial.ts#L191-L192
Added lines #L191 - L192 were not covered by tests


[warning] 195-197: packages/core/src/material/PBRMaterial.ts#L195-L197
Added lines #L195 - L197 were not covered by tests

🪛 GitHub Check: lint

[failure] 173-173:
Delete ↹↹


[failure] 177-177:
Delete


[failure] 187-187:
Delete

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

🧹 Outside diff range and nitpick comments (4)
packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts (2)

11-18: Consider documenting the physical meaning of default values

The default values for iridescenceThicknessMinimum (100) and iridescenceThicknessMaximum (400) represent nanometers. Consider adding a comment to clarify this for maintainability.

 const {
   iridescenceFactor = 0,
   iridescenceTexture,
   iridescenceIor = 1.3,
+  // Thickness range in nanometers (nm)
   iridescenceThicknessMinimum = 100,
   iridescenceThicknessMaximum = 400,
   iridescenceThicknessTexture
 } = schema;
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 11-39: packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts#L11-L39
Added lines #L11 - L39 were not covered by tests


25-31: Consider batching texture loading

The current implementation loads textures sequentially. Consider batching the texture loading operations for better performance when both textures are present.

+const texturePromises: Promise<void>[] = [];

 if (iridescenceTexture) {
   GLTFMaterialParser._checkOtherTextureTransform(iridescenceTexture, "Iridescence texture");
-  context.get<Texture2D>(GLTFParserType.Texture, iridescenceTexture.index).then((texture) => {
+  texturePromises.push(context.get<Texture2D>(GLTFParserType.Texture, iridescenceTexture.index).then((texture) => {
     material.iridescenceTexture = texture;
-  });
+  }));
 }
 if (iridescenceThicknessTexture) {
   GLTFMaterialParser._checkOtherTextureTransform(iridescenceThicknessTexture, "IridescenceThickness texture");
-  context.get<Texture2D>(GLTFParserType.Texture, iridescenceThicknessTexture.index).then((texture) => {
+  texturePromises.push(context.get<Texture2D>(GLTFParserType.Texture, iridescenceThicknessTexture.index).then((texture) => {
     material.iridescenceThicknessTexture = texture;
-  });
+  }));
 }
+
+// Wait for all textures to load
+Promise.all(texturePromises).catch((error) => {
+  console.warn(`Failed to load one or more iridescence textures: ${error.message}`);
+});

Also applies to: 32-38

packages/core/src/material/PBRMaterial.ts (2)

23-25: Follow naming convention for shader properties.

The property _iridescenceInfoProp should follow camelCase convention like other properties in the class.

-  private static _iridescenceInfoProp = ShaderProperty.getByName("material_IridescenceInfo");
+  private static _iridescenceInfoProp = ShaderProperty.getByName("material_iridescenceInfo");

198-230: Add test coverage for texture properties.

The implementation looks good but lacks test coverage. Tests should verify:

  1. Texture assignment
  2. Macro enabling/disabling
  3. Texture cleanup

Would you like me to help generate unit tests for these properties?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 202-203: packages/core/src/material/PBRMaterial.ts#L202-L203
Added lines #L202 - L203 were not covered by tests


[warning] 206-213: packages/core/src/material/PBRMaterial.ts#L206-L213
Added lines #L206 - L213 were not covered by tests


[warning] 219-220: packages/core/src/material/PBRMaterial.ts#L219-L220
Added lines #L219 - L220 were not covered by tests


[warning] 223-230: packages/core/src/material/PBRMaterial.ts#L223-L230
Added lines #L223 - L230 were 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 aa41aaf and f4b16fd.

📒 Files selected for processing (2)
  • packages/core/src/material/PBRMaterial.ts (4 hunks)
  • packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
packages/core/src/material/PBRMaterial.ts

[warning] 144-145: packages/core/src/material/PBRMaterial.ts#L144-L145
Added lines #L144 - L145 were not covered by tests


[warning] 148-157: packages/core/src/material/PBRMaterial.ts#L148-L157
Added lines #L148 - L157 were not covered by tests


[warning] 164-165: packages/core/src/material/PBRMaterial.ts#L164-L165
Added lines #L164 - L165 were not covered by tests


[warning] 168-170: packages/core/src/material/PBRMaterial.ts#L168-L170
Added lines #L168 - L170 were not covered by tests


[warning] 177-178: packages/core/src/material/PBRMaterial.ts#L177-L178
Added lines #L177 - L178 were not covered by tests


[warning] 181-183: packages/core/src/material/PBRMaterial.ts#L181-L183
Added lines #L181 - L183 were not covered by tests


[warning] 190-191: packages/core/src/material/PBRMaterial.ts#L190-L191
Added lines #L190 - L191 were not covered by tests


[warning] 194-196: packages/core/src/material/PBRMaterial.ts#L194-L196
Added lines #L194 - L196 were not covered by tests


[warning] 202-203: packages/core/src/material/PBRMaterial.ts#L202-L203
Added lines #L202 - L203 were not covered by tests


[warning] 206-213: packages/core/src/material/PBRMaterial.ts#L206-L213
Added lines #L206 - L213 were not covered by tests


[warning] 219-220: packages/core/src/material/PBRMaterial.ts#L219-L220
Added lines #L219 - L220 were not covered by tests


[warning] 223-230: packages/core/src/material/PBRMaterial.ts#L223-L230
Added lines #L223 - L230 were not covered by tests

packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts

[warning] 11-39: packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts#L11-L39
Added lines #L11 - L39 were not covered by tests

🔇 Additional comments (2)
packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts (1)

1-9: LGTM! Proper extension setup and registration

The imports are comprehensive and the extension is correctly registered with the appropriate mode.

packages/core/src/material/PBRMaterial.ts (1)

244-244: LGTM!

The initialization of iridescence properties with default values is correct and matches the documentation.

Comment on lines +28 to +31
context.get<Texture2D>(GLTFParserType.Texture, iridescenceTexture.index).then((texture) => {
material.iridescenceTexture = texture;
});
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for texture loading

The async texture loading should include error handling to prevent silent failures.

 context.get<Texture2D>(GLTFParserType.Texture, iridescenceTexture.index).then((texture) => {
   material.iridescenceTexture = texture;
-});
+}).catch((error) => {
+  console.warn(`Failed to load iridescence texture: ${error.message}`);
+});

 // Similar change for iridescenceThicknessTexture

Also applies to: 35-38

Comment on lines +11 to +39
const {
iridescenceFactor = 0,
iridescenceTexture,
iridescenceIor = 1.3,
iridescenceThicknessMinimum = 100,
iridescenceThicknessMaximum = 400,
iridescenceThicknessTexture
} = schema;

material.iridescenceFactor = iridescenceFactor;
material.iridescenceIor = iridescenceIor;
material.iridescenceThicknessMin = iridescenceThicknessMinimum;
material.iridescenceThicknessMax = iridescenceThicknessMaximum;

if (iridescenceTexture) {
GLTFMaterialParser._checkOtherTextureTransform(iridescenceTexture, "Iridescence texture");

context.get<Texture2D>(GLTFParserType.Texture, iridescenceTexture.index).then((texture) => {
material.iridescenceTexture = texture;
});
}
if (iridescenceThicknessTexture) {
GLTFMaterialParser._checkOtherTextureTransform(iridescenceThicknessTexture, "IridescenceThickness texture");

context.get<Texture2D>(GLTFParserType.Texture, iridescenceThicknessTexture.index).then((texture) => {
material.iridescenceThicknessTexture = texture;
});
}
}
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 unit tests for the extension parser

The static analysis indicates that this new extension lacks test coverage. This is critical for ensuring the parser behaves correctly with various input scenarios.

Key scenarios to test:

  1. Default values when properties are missing
  2. Texture loading success and failure cases
  3. Edge cases for thickness values
  4. Invalid input handling

Would you like me to help generate a comprehensive test suite for this extension?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 11-39: packages/loader/src/gltf/extensions/KHR_materials_iridescence.ts#L11-L39
Added lines #L11 - L39 were not covered by tests

Comment on lines +159 to +170
/**
* The index of refraction of the dielectric thin-film layer.
* @defaultValue `1.3`
*/
get iridescenceIor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).y;
}

set iridescenceIor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.y = value;
}
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 validation for iridescence IOR.

The index of refraction must be greater than 1.0 as it represents a physical property.

Apply this diff to add validation:

  set iridescenceIor(value: number) {
    const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
+   value = Math.max(1.0, value);
    iridescenceInfo.y = value;
  }
📝 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
/**
* The index of refraction of the dielectric thin-film layer.
* @defaultValue `1.3`
*/
get iridescenceIor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).y;
}
set iridescenceIor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.y = value;
}
/**
* The index of refraction of the dielectric thin-film layer.
* @defaultValue `1.3`
*/
get iridescenceIor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).y;
}
set iridescenceIor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
value = Math.max(1.0, value);
iridescenceInfo.y = value;
}
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 164-165: packages/core/src/material/PBRMaterial.ts#L164-L165
Added lines #L164 - L165 were not covered by tests


[warning] 168-170: packages/core/src/material/PBRMaterial.ts#L168-L170
Added lines #L168 - L170 were not covered by tests

Comment on lines +139 to +157
/**
* The iridescence intensity factor.
* @defaultValue `0.0`
*/
get iridescenceFactor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).x;
}

set iridescenceFactor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
if (!!iridescenceInfo.x !== !!value) {
if (value === 0) {
this.shaderData.disableMacro("MATERIAL_ENABLE_IRIDESCENCE");
} else {
this.shaderData.enableMacro("MATERIAL_ENABLE_IRIDESCENCE");
}
iridescenceInfo.x = value;
}
}
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 iridescence factor implementation and add tests.

Issues found:

  1. The value should be clamped to [0,1] range as it represents an intensity factor
  2. The value is set after the macro check, which could lead to inconsistent state
  3. Missing test coverage for the property

Apply this diff to fix the implementation:

  set iridescenceFactor(value: number) {
    const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
+   value = Math.max(0, Math.min(1, value));
    if (!!iridescenceInfo.x !== !!value) {
      if (value === 0) {
        this.shaderData.disableMacro("MATERIAL_ENABLE_IRIDESCENCE");
      } else {
        this.shaderData.enableMacro("MATERIAL_ENABLE_IRIDESCENCE");
      }
-     iridescenceInfo.x = value;
    }
+   iridescenceInfo.x = value;
  }

Would you like me to help generate unit tests for this property?

📝 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
/**
* The iridescence intensity factor.
* @defaultValue `0.0`
*/
get iridescenceFactor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).x;
}
set iridescenceFactor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
if (!!iridescenceInfo.x !== !!value) {
if (value === 0) {
this.shaderData.disableMacro("MATERIAL_ENABLE_IRIDESCENCE");
} else {
this.shaderData.enableMacro("MATERIAL_ENABLE_IRIDESCENCE");
}
iridescenceInfo.x = value;
}
}
/**
* The iridescence intensity factor.
* @defaultValue `0.0`
*/
get iridescenceFactor(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).x;
}
set iridescenceFactor(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
value = Math.max(0, Math.min(1, value));
if (!!iridescenceInfo.x !== !!value) {
if (value === 0) {
this.shaderData.disableMacro("MATERIAL_ENABLE_IRIDESCENCE");
} else {
this.shaderData.enableMacro("MATERIAL_ENABLE_IRIDESCENCE");
}
}
iridescenceInfo.x = value;
}
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 144-145: packages/core/src/material/PBRMaterial.ts#L144-L145
Added lines #L144 - L145 were not covered by tests


[warning] 148-157: packages/core/src/material/PBRMaterial.ts#L148-L157
Added lines #L148 - L157 were not covered by tests

Comment on lines +172 to +196
/**
* The minimum thickness of the thin-film layer given in nanometers.
* @defaultValue `100`
*/
get iridescenceThicknessMin(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).z;
}

set iridescenceThicknessMin(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.z = value;
}

/**
* The maximum thickness of the thin-film layer given in nanometers.
* @defaultValue `400`
*/
get iridescenceThicknessMax(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).w;
}

set iridescenceThicknessMax(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.w = value;
}
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 validation for thickness values.

The thickness values need validation to ensure:

  1. Non-negative values (physical constraint)
  2. Minimum thickness is less than maximum thickness

Apply this diff to add validation:

  set iridescenceThicknessMin(value: number) {
    const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
+   value = Math.max(0, value);
+   const maxThickness = iridescenceInfo.w;
+   if (value >= maxThickness) {
+     value = maxThickness * 0.9; // Ensure min is less than max
+   }
    iridescenceInfo.z = value;
  }

  set iridescenceThicknessMax(value: number) {
    const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
+   value = Math.max(0, value);
+   const minThickness = iridescenceInfo.z;
+   if (value <= minThickness) {
+     value = minThickness * 1.1; // Ensure max is greater than min
+   }
    iridescenceInfo.w = value;
  }
📝 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
/**
* The minimum thickness of the thin-film layer given in nanometers.
* @defaultValue `100`
*/
get iridescenceThicknessMin(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).z;
}
set iridescenceThicknessMin(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.z = value;
}
/**
* The maximum thickness of the thin-film layer given in nanometers.
* @defaultValue `400`
*/
get iridescenceThicknessMax(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).w;
}
set iridescenceThicknessMax(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
iridescenceInfo.w = value;
}
/**
* The minimum thickness of the thin-film layer given in nanometers.
* @defaultValue `100`
*/
get iridescenceThicknessMin(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).z;
}
set iridescenceThicknessMin(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
value = Math.max(0, value);
const maxThickness = iridescenceInfo.w;
if (value >= maxThickness) {
value = maxThickness * 0.9; // Ensure min is less than max
}
iridescenceInfo.z = value;
}
/**
* The maximum thickness of the thin-film layer given in nanometers.
* @defaultValue `400`
*/
get iridescenceThicknessMax(): number {
return this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp).w;
}
set iridescenceThicknessMax(value: number) {
const iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
value = Math.max(0, value);
const minThickness = iridescenceInfo.z;
if (value <= minThickness) {
value = minThickness * 1.1; // Ensure max is greater than min
}
iridescenceInfo.w = value;
}
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 177-178: packages/core/src/material/PBRMaterial.ts#L177-L178
Added lines #L177 - L178 were not covered by tests


[warning] 181-183: packages/core/src/material/PBRMaterial.ts#L181-L183
Added lines #L181 - L183 were not covered by tests


[warning] 190-191: packages/core/src/material/PBRMaterial.ts#L190-L191
Added lines #L190 - L191 were not covered by tests


[warning] 194-196: packages/core/src/material/PBRMaterial.ts#L194-L196
Added lines #L194 - L196 were not covered by tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
glTF material Rendering Rendering related functions shader Shader related functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants