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

Calculate vertex weight for each voxels (for UV calculations) #7

Merged
merged 2 commits into from
Jul 10, 2024

Conversation

ciscorn
Copy link
Member

@ciscorn ciscorn commented Jun 28, 2024

Closes #5

This PR adds the calculation of vertex weights for each voxel, which is needed to derive UV coordinates from vertex data.

(The calculation logic and algorithms are immature and could be further optimized.)

Screenshot 2024-06-28 at 15 52 56

Summary by CodeRabbit

  • New Features

    • Introduced a new file for voxelizing 3D polygons and generating glTF files.
    • Enhanced voxelization process by incorporating weight parameters for voxels, lines, and triangles.
  • Improvements

    • Adjusted color calculation logic to improve visual fidelity.
    • Updated coordinate ranges for better precision.

Copy link

coderabbitai bot commented Jun 28, 2024

Walkthrough

This update introduces features for voxel coloring and handling in a voxelization example (voxelize_uv.rs) and adjusts existing voxelization logic in DdaVoxelizer to support weights for voxels. Enhancements include new parameters to manage voxel color textures and weights and expanded the functionality to export voxelized 3D polygons to a glTF format.

Changes

File Change Summary
examples/voxelize.rs Updated voxel coordinates and adjusted color calculation logic for voxel shading.
examples/voxelize_uv.rs Introduced a new code example to voxelize 3D polygons and generate a glTF file with voxelized geometry using several external libraries.
src/voxelize.rs Enhanced DdaVoxelizer to handle weights for voxels including new parameters in functions like put_voxel, draw_line, and fill_triangle.

Assessment against linked issues

Objective Addressed Explanation
Use generics for color buffer type, beyond just supporting 24-bit RGB (#5)
Potential future use of textures and UV coordinates (#5) There is no clear evidence of UV coordinate handling for textures.

Poem

In the realm of pixels fine and bright,
Voxel colors now paint the night.
With weights and shades, they gain new cheer,
Crafting scenes both far and near.
From glTF, they leap with glee,
Into the world, for all to see.
🌈🖌️🎨


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between df94df7 and 61f128c.

Files selected for processing (3)
  • examples/voxelize.rs (3 hunks)
  • examples/voxelize_uv.rs (1 hunks)
  • src/voxelize.rs (8 hunks)
Additional comments not posted (5)
examples/voxelize.rs (2)

75-76: Verify the new color calculation formulas.

The color calculation logic has been changed. Ensure that the new formulas provide the intended color effects and do not introduce visual artifacts or performance issues.


22-23: Verify the impact of updated coordinate values.

The coordinate values have been altered, potentially affecting the spatial processing range of the voxelizer. Ensure these values are within valid bounds and align with the intended use cases.

examples/voxelize_uv.rs (1)

14-282: Approve the implementation of the main function in the new file.

The implementation of the main function in examples/voxelize_uv.rs appears to correctly handle the voxelization of polygons and the generation of glTF files. Ensure that all external dependencies are properly managed and that the function integrates well with the rest of the project.

src/voxelize.rs (2)

52-63: Approve the addition of the weight parameter in the put_voxel function.

The inclusion of the weight parameter in the put_voxel function is a necessary change to support vertex weights. Ensure that the weight values are correctly clamped between 0.0 and 1.0 to prevent any unintended behavior.


Line range hint 79-137: Approve the modifications to the draw_line function.

The addition of start_w and end_w parameters in the draw_line function allows for the interpolation of weights along the line, which is crucial for achieving accurate voxel shading. Verify that the weight interpolation is implemented correctly and efficiently.

@ciscorn ciscorn self-assigned this Jun 28, 2024
@ciscorn ciscorn changed the title Vertex weight of voxels for UV calculation Calculate vertex weight for each voxels (for UV calculations) Jun 28, 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: 1

Outside diff range and nitpick comments (2)
src/voxelize.rs (2)

Line range hint 79-137: Review the enhanced draw_line function.

The updates to include vertex weights are well-implemented. However, the TODO comment about optimizing from 3D DDA to 2D DDA suggests further performance improvements could be made. It would be beneficial to address this in future work to enhance efficiency.

Would you like me to explore potential optimizations or open a GitHub issue to track this enhancement?


Line range hint 184-296: Complex implementation in fill_triangle handles vertex weights effectively.

The handling of vertex weights and the reordering of vertices based on the sweep axis are well-implemented. This function is complex, and while it is currently effective, future optimizations could simplify the logic and improve performance.

Consider reviewing the complexity of this function periodically to identify opportunities for simplification or optimization, especially as related features evolve.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 61f128c and 89179b8.

Files selected for processing (1)
  • src/voxelize.rs (9 hunks)

Comment on lines +52 to +63
weight: glam::Vec3,
shader: impl Shader<V>,
) {
let position = position.to_array();
let weight = [1., 0., 0.]; // FIXME: not impletmented yet
let weight = {
let mut w = weight.to_array();
w[0] = w[0].clamp(0.0, 1.0);
w[1] = w[1].clamp(0.0, 1.0);
w[2] = w[2].clamp(0.0, 1.0);
w
};

Copy link

@coderabbitai coderabbitai bot Jun 28, 2024

Choose a reason for hiding this comment

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

Optimize weight processing in put_voxel.

The current implementation recalculates and clamps the weight every time put_voxel is called. Consider precomputing these weights before passing them to put_voxel to reduce computational overhead.

- let weight = {
-    let mut w = weight.to_array();
-    w[0] = w[0].clamp(0.0, 1.0);
-    w[1] = w[1].clamp(0.0, 1.0);
-    w[2] = w[2].clamp(0.0, 1.0);
-    w
- };
+ // Assume weight is already clamped and converted before being passed to this function.
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
weight: glam::Vec3,
shader: impl Shader<V>,
) {
let position = position.to_array();
let weight = [1., 0., 0.]; // FIXME: not impletmented yet
let weight = {
let mut w = weight.to_array();
w[0] = w[0].clamp(0.0, 1.0);
w[1] = w[1].clamp(0.0, 1.0);
w[2] = w[2].clamp(0.0, 1.0);
w
};
weight: glam::Vec3,
shader: impl Shader<V>,
) {
let position = position.to_array();
// Assume weight is already clamped and converted before being passed to this function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, the current implementation cannot avoid numerical errors that may result in values outside of [0.0, 1.0].

Copy link

Choose a reason for hiding this comment

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

@ciscorn, I understand your point regarding the numerical errors that may result in values outside the [0.0, 1.0] range. Given this, it makes sense to keep the clamping logic inside the put_voxel function to ensure the weights are within the correct range. Thank you for the clarification.

@ciscorn ciscorn mentioned this pull request Jul 7, 2024
2 tasks
Copy link
Collaborator

@nokonoko1203 nokonoko1203 left a comment

Choose a reason for hiding this comment

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

lgtm!

@nokonoko1203 nokonoko1203 merged commit 1e0844a into main Jul 10, 2024
1 check passed
@nokonoko1203 nokonoko1203 deleted the vertex-weight branch July 10, 2024 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Coloring voxels (voxel shader)
2 participants