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

Voxel shader (initial impl.) #6

Merged
merged 5 commits into from
Jun 13, 2024
Merged

Voxel shader (initial impl.) #6

merged 5 commits into from
Jun 13, 2024

Conversation

ciscorn
Copy link
Member

@ciscorn ciscorn commented Jun 8, 2024

rel: #5

shader

Summary by CodeRabbit

  • New Features

    • Added dependency on palette version 0.7.6 for enhanced color management.
    • Updated glam dependency to version 0.28 for improved performance and features.
  • Bug Fixes

    • Clarified README to specify that the 3D mesh voxelizer only voxelizes surfaces, not volumes.
  • Chores

    • Updated .gitignore to exclude .DS_Store files.
    • Removed unnecessary release profile settings in Cargo.toml.

@ciscorn ciscorn self-assigned this Jun 8, 2024
coderabbitai[bot]

This comment was marked as outdated.

@MIERUNE MIERUNE deleted a comment from coderabbitai bot Jun 8, 2024
Copy link

coderabbitai bot commented Jun 8, 2024

Walkthrough

The recent updates to the repository include modifications to the .gitignore file to exclude .DS_Store files, changes to Cargo.toml to update dependencies and remove release profile settings, and clarifications in README.md about the functionality of the 3D mesh voxelizer. Significant changes were made to examples/voxelize.rs and src/voxelize.rs, including the introduction of the Shader trait, refactoring for voxel and color handling, and adjustments to the voxelization process.

Changes

File(s) Change Summary
.gitignore Updated to exclude .DS_Store files.
Cargo.toml Updated glam dependency to 0.28, added palette dependency, and removed [profile.release] settings.
README.md Clarified the functionality of the 3D mesh voxelizer regarding surface voxelization.
examples/voxelize.rs Removed hashbrown::HashMap, added palette::FromColor, refactored voxel and color handling, and more.
src/voxelize.rs Introduced Shader trait, refactored DdaVoxelizer, updated line and triangle handling, added put_voxel.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DdaVoxelizer
    participant Shader
    participant Buffer

    User ->> DdaVoxelizer: new()
    DdaVoxelizer ->> Buffer: initialize()
    User ->> DdaVoxelizer: add_triangle(triangle, shader)
    DdaVoxelizer ->> Shader: apply_shader(triangle)
    Shader ->> Buffer: update_with_voxels(triangle)
    User ->> DdaVoxelizer: add_line(start, end, shader)
    DdaVoxelizer ->> Shader: apply_shader(line)
    Shader ->> Buffer: update_with_voxels(line)
    User ->> DdaVoxelizer: finalize()
    DdaVoxelizer ->> User: return buffer
Loading

Poem

In the code, a change does glow,
Colors and voxels now in tow.
Palette's hues begin to blend,
Voxelizer's tasks transcend.
From lines to triangles, all so bright,
A rabbit's joy in code's delight. 🐇✨


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.

@MIERUNE MIERUNE deleted a comment from coderabbitai bot Jun 8, 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 (1)
src/voxelize.rs (1)

Line range hint 65-102: Optimize the draw_line function.

Consider optimizing the 3D DDA algorithm as suggested by the TODO comment. This could improve performance, especially for large datasets.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 118b2fe and 47c2e23.

Files selected for processing (5)
  • .gitignore (1 hunks)
  • Cargo.toml (1 hunks)
  • README.md (1 hunks)
  • examples/voxelize.rs (6 hunks)
  • src/voxelize.rs (11 hunks)
Files skipped from review due to trivial changes (2)
  • Cargo.toml
  • README.md
Files skipped from review as they are similar to previous changes (2)
  • .gitignore
  • examples/voxelize.rs
Additional comments not posted (7)
src/voxelize.rs (7)

7-8: Define the Shader trait and its implementation.

This trait definition and its blanket implementation are well-defined, allowing any function matching the signature to be used as a shader. This is a flexible design that facilitates easy extension.


14-17: Constructor method for DdaVoxelizer.

The new method correctly delegates to default, which is a common Rust pattern to keep initialization logic in one place.


21-24: Default constructor for DdaVoxelizer.

The implementation of the default method is concise and clear, initializing the buffer with a new, empty HashMap.


29-30: Add triangle method in DdaVoxelizer.

The method correctly uses the shader to fill the triangle. This maintains separation of concerns by delegating the voxelization logic to the shader.


33-39: Add line method in DdaVoxelizer.

This method effectively uses the shader to draw a line between two points. The use of Vec3::from_array ensures type safety and clarity in converting arrays to vector types.


Line range hint 105-207: Implement fill_triangle function.

The function is well-implemented with detailed logic for handling different cases of triangle rasterization. The use of vector operations and conditional logic is appropriate and seems efficient.


Line range hint 238-265: Test cases for DdaVoxelizer.

The test cases are comprehensive and cover various scenarios including minimum polygons, square polygons, and complex shapes with holes. This is good practice to ensure the robustness of the voxelization logic.

Also applies to: 296-322, 362-389, 468-495

src/voxelize.rs Outdated
Comment on lines 47 to 63
fn put_voxel<V: Clone>(
buffer: &mut HashMap<[i32; 3], V>,
position: glam::IVec3,
shader: impl Shader<V>,
) {
let position = position.to_array();
let weight = [1., 0., 0.]; // FIXME: not impletmented yet
match buffer.entry(position) {
Entry::Occupied(mut v) => {
let v = v.get_mut();
*v = shader(Some(v), position, weight);
}
Entry::Vacant(v) => {
v.insert(shader(None, position, weight));
}
}
}
Copy link

Choose a reason for hiding this comment

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

Implement put_voxel function.

- let weight = [1., 0., 0.]; // FIXME: not implemented yet
+ let weight = calculate_weight(position, some_other_params); // Replace with actual weight calculation logic

The FIXME comment indicates that the weight calculation is not implemented. It's crucial to replace the placeholder with actual logic to ensure the shader function works correctly.

Committable suggestion was skipped due to low confidence.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 47c2e23 and da9114e.

Files selected for processing (2)
  • examples/voxelize.rs (6 hunks)
  • src/voxelize.rs (11 hunks)
Additional comments not posted (7)
examples/voxelize.rs (4)

10-10: Updated import to use palette::FromColor instead of hashbrown::HashMap.

This change aligns with the new functionality to handle color calculations within the voxelization process.


18-21: Adjusted vertices defining the exterior of a shape.

Ensure that these new coordinates correctly represent the intended geometry of the shape.


39-39: Initialization of DdaVoxelizer without parameters.

This simplifies the instantiation process, assuming default values are properly set within the DdaVoxelizer itself.


134-205: Significant changes in handling voxel positions and colors, including adjustments to buffer sizes and the glTF JSON structure.

These changes are necessary to accommodate the new data representation. Ensure that the buffer sizes and JSON structure are correctly calculated and validated.

src/voxelize.rs (3)

5-8: Introduced a Shader trait to encapsulate shader functionality.

This is a good use of Rust's trait system to abstract shader behavior, making the voxelizer more flexible and reusable.


Line range hint 65-102: Enhanced draw_line method to incorporate shader functionality.

This modification integrates the shader directly into the line drawing process, allowing for more complex voxel manipulations based on the shader's output.


Line range hint 105-225: Refined the fill_triangle method to use the shader for filling triangles.

This change ensures that the shader's logic is consistently applied across different geometric primitives, which is crucial for maintaining visual consistency in the voxelization output.

Comment on lines +65 to +81
voxelizer.add_triangle(
&[
buf3d[index[0] as usize],
buf3d[index[1] as usize],
buf3d[index[2] as usize],
],
&|_current_value, [x, y, z], _vertex_weight| {
let [x, y, z] = [x as f32, y as f32, z as f32];
let color_lab = palette::Okhsl::new(
x.atan2(z).to_degrees(),
1.0 - (x * x + z * z) / 2500.,
y / 90. + 0.5,
);
let color_srgb = palette::Srgb::from_color(color_lab);
[color_srgb.red, color_srgb.green, color_srgb.blue]
},
);
Copy link

Choose a reason for hiding this comment

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

Refactored add_triangle method to accept a closure for color calculation.

This change enhances flexibility by allowing dynamic color calculations. However, consider encapsulating color calculation logic into a separate function or module for better maintainability.

Comment on lines +47 to +61
fn put_voxel<V: Clone>(
buffer: &mut HashMap<[i32; 3], V>,
position: glam::IVec3,
shader: impl Shader<V>,
) {
let position = position.to_array();
let weight = [1., 0., 0.]; // FIXME: not impletmented yet
match buffer.entry(position) {
Entry::Occupied(mut v) => {
let v = v.get_mut();
*v = shader(Some(v), position, weight);
}
Entry::Vacant(v) => {
v.insert(shader(None, position, weight));
}
Copy link

Choose a reason for hiding this comment

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

Updated put_voxel function to manage voxel insertion based on a shader function.

- let weight = [1., 0., 0.]; // FIXME: not implemented yet
+ let weight = calculate_weight(position, some_other_params); // Replace with actual weight calculation logic

The FIXME comment indicates that the weight calculation is not implemented. It's crucial to replace the placeholder with actual logic to ensure the shader function works correctly.

Committable suggestion was skipped due to low confidence.

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 da9114e and 1344459.

Files selected for processing (1)
  • Cargo.toml (3 hunks)
Additional comments not posted (3)
Cargo.toml (3)

3-3: Version update to "0.2.0-alpha.1" seems appropriate for the significant feature addition of the voxel shader.


12-12: Removal of [profile.release] settings (lto, codegen-units, panic). Please clarify the rationale behind this change and ensure it does not adversely affect performance or error handling in production.


12-12: Updated glam to "0.28" and added palette "0.7.6". Ensure compatibility and integration tests with the existing codebase.

Also applies to: 22-22

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 df94df7 into main Jun 13, 2024
1 check passed
@nokonoko1203 nokonoko1203 deleted the shader-init branch June 13, 2024 00:03
nokonoko1203 pushed a commit to MIERUNE/plateau-gis-converter that referenced this pull request Jun 13, 2024
### Description(変更内容)

- ボクセルに任意の値を持たせられるようになった
MIERUNE/dda-voxelize-rs#6 ので、それを利用する。
    - → 地物ごとにボクセライザを作る必要がなくなる。
- 上記のデモも兼ねて、Thematic surfaces の類(壁とか屋根とか窓とか)で塗り分けられるように変更する。
    - ボクセライズアルゴリズムの都合で、窓より外側に壁が塗られてしまうこともある、などの問題はありますが、これの回避は難しそう。


![Untitled](https://github.com/MIERUNE/plateau-gis-converter/assets/5351911/150016c4-955e-4c8c-a55d-6ae798b8bbeb)
@ciscorn ciscorn mentioned this pull request Jun 22, 2024
2 tasks
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.

2 participants