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

feat: Finally a light engine! #304

Open
wants to merge 7 commits into
base: next
Choose a base branch
from
Open

feat: Finally a light engine! #304

wants to merge 7 commits into from

Conversation

zardoy
Copy link
Owner

@zardoy zardoy commented Mar 12, 2025

Summary by CodeRabbit

  • New Features
    • Introduced an enhanced dynamic lighting system that improves block light updates and overall light transitions, offering a more immersive environment.
    • Refined the processing of environment sections to ensure smoother and more accurate lighting updates.
    • Added a new dependency to support these lighting improvements.
    • Enabled new versions of lighting features by default in application settings.
    • Integrated new light processing functions for better light management in the world data emitter.

Copy link

codesandbox bot commented Mar 12, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

coderabbitai bot commented Mar 12, 2025

Walkthrough

This update adds a new dependency (minecraft-lighting) to the project and introduces a new TypeScript file that implements a light engine for Minecraft-like environments. The light engine provides functions for retrieving, initializing, processing light updates for chunks, and updating block light states. Additionally, the world data emitter has been adjusted to integrate the new light engine functions during initialization, chunk loading, and block state updates. The default options for lighting features have also been modified to enable new version lighting by default.

Changes

File(s) Summary of Changes
package.json Added new dependency: "minecraft-lighting": "^0.0.4" without altering the existing "yaml": "^2.3.2" dependency.
renderer/viewer/lib/lightEngine.ts Introduced a new light engine module with functions getLightEngine(), createLightEngine(), processLightChunk(x, z), and updateBlockLight(x, y, z, stateId).
renderer/viewer/lib/worldDataEmitter.ts Modified WorldDataEmitter to initialize the light engine during setup, refine chunk loading logic, and call processLightChunk() and updateBlockLight() for lighting updates.
renderer/viewer/lib/mesher/world.ts Adjusted logic in getLight method to incorporate new constants for light level calculations, modifying how minimum light levels are determined.
src/optionsStorage.ts Changed newVersionsLighting property in defaultOptions from false to true, enabling new version lighting features by default.

Sequence Diagram(s)

sequenceDiagram
    participant WDE as WorldDataEmitter
    participant LE as LightEngine

    Note over WDE,LE: Initialization
    WDE->>LE: createLightEngine()
    LE-->>WDE: Light engine instance

    Note over WDE,LE: Chunk Loading Flow
    WDE->>LE: processLightChunk(x, z)
    LE-->>WDE: Chunk light update results

    Note over WDE,LE: Block Update Flow
    WDE->>LE: updateBlockLight(x, y, z, stateId)
    LE-->>WDE: Light state updated
Loading

Possibly related PRs

Suggested labels

Review effort 4/5

Poem

I'm a rabbit, hopping through the code,
With light so bright on every node,
New functions shine like beams in the night,
Lighting our world with a digital delight,
I nibble on bugs and celebrate this mode!
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ace45a9 and 9f505f8.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • package.json (1 hunks)
  • renderer/viewer/lib/mesher/world.ts (2 hunks)
  • src/optionsStorage.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • package.json
  • src/optionsStorage.ts
  • renderer/viewer/lib/mesher/world.ts

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

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

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

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @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.

@zardoy
Copy link
Owner Author

zardoy commented Mar 12, 2025

/deploy

Copy link

Deployed to Vercel Preview: https://prismarine-8lcpkaej0-zaro.vercel.app
Playground
Storybook

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
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ad13ab8 and 037e297.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • package.json (1 hunks)
  • renderer/viewer/lib/lightEngine.ts (1 hunks)
  • renderer/viewer/lib/worldDataEmitter.ts (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-and-deploy
🔇 Additional comments (7)
renderer/viewer/lib/lightEngine.ts (2)

1-8: Good implementation of light engine module with proper error handling

The module correctly imports required dependencies and implements a proper singleton pattern with the getLightEngine function that includes error handling for uninitialized state.


19-25: Well-structured chunk processing function with async support

The processLightChunk function correctly handles chunk coordinates conversion and properly uses the light engine API.

renderer/viewer/lib/worldDataEmitter.ts (5)

11-11: Good modular import of light engine functions

The light engine functions are properly imported from the new module.


55-55: Light updates correctly integrated with block state changes

Block light updates are now properly triggered whenever a block state changes, which is essential for realistic lighting in the Minecraft environment.


149-149: Light engine initialization in the world initialization

The light engine is properly initialized during the world data emitter initialization, ensuring it's available when needed.


182-186: Code readability improvement with intermediate variables

The changes improve code readability by introducing intermediate variables chunkX and chunkZ for chunk coordinate calculations.


190-197: Advanced light processing with related chunks updates

This code nicely handles the cascading effect of light changes by:

  1. Processing the light for the current chunk
  2. Identifying affected neighboring chunks
  3. Triggering updates for already loaded affected chunks

This implementation ensures lighting consistency across chunk boundaries.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/optionsStorage.ts (1)

91-91: Enabling new lighting system by default is a significant change

Changing newVersionsLighting from false to true makes the new lighting engine enabled by default for all users. This aligns with the PR's purpose of introducing a new light engine feature.

Consider adding a brief comment to explain what this option controls, similar to other commented options in this file.

  smoothLighting: true,
+ /** Controls whether to use the new minecraft-lighting engine */
  newVersionsLighting: true,

Have you verified the performance impact of enabling this by default, especially on lower-end devices? If performance issues arise, you might consider implementing a progressive rollout strategy based on device capabilities.

renderer/viewer/lib/mesher/world.ts (2)

66-67: Consider removing commented code instead of keeping it

It appears the calculation for sky light has been intentionally commented out, likely because it's now being handled by the new light engine mentioned in the PR title. However, keeping commented code can lead to confusion and maintenance issues over time.

If the code is no longer needed due to the new light engine implementation, consider removing it entirely instead of commenting it out. If it's kept for historical or reference purposes, add a more descriptive comment explaining why it's disabled and how the functionality is now handled.

-      // Math.min(skyLight, column.getSkyLight(posInChunk(pos)))
+      // Sky light calculation now handled by the light engine in lightEngine.ts

84-84: Address TODO comment with clear implementation

This line overrides the light level to 15 when both isNeighbor is true and result is 2, with a TODO comment indicating this is not the intended final implementation. Now that you're implementing a proper light engine, this is a good opportunity to resolve this longstanding TODO.

Consider either:

  1. Implementing the correct behavior based on lighting physics
  2. Documenting why this special case exists and what the correct implementation should be
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 037e297 and ace45a9.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • package.json (1 hunks)
  • renderer/viewer/lib/mesher/world.ts (1 hunks)
  • src/optionsStorage.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-and-deploy
🔇 Additional comments (2)
renderer/viewer/lib/mesher/world.ts (2)

57-57: Consider how the new light engine interacts with the enableLighting configuration

Line 57 shows that lighting can be completely disabled through the enableLighting config option. Make sure the new light engine properly respects this configuration option and doesn't perform unnecessary calculations when lighting is disabled.


53-86:

❓ Verification inconclusive

Verify that the light calculation changes work with existing code

The removal of sky light calculation from this method might affect any code that relies on this method to provide combined block and sky light calculations. The current implementation now only considers block light, which could cause rendering issues if any parts of the codebase expect the previous behavior.

Make sure that all places using getLight() are aware of this change and that the new light engine properly integrates with the existing rendering system.


🏁 Script executed:

#!/bin/bash
# Find all places where getLight is called to ensure they work with the new implementation
rg "getLight\(" --type ts

Length of output: 1207


Action: Confirm that the updated light calculations integrate correctly with rendering

The revised implementation of getLight() now relies solely on block light (with sky light calculation code commented out). Our search confirms that all calls to getLight() occur in the following locations:

  • renderer/viewer/lib/mesher/world.ts (including recursive calls for handling stairs, slabs, and glass panes)
  • renderer/viewer/lib/mesher/models.ts (for computing baseLight, side light, and corner light)
  • renderer/viewer/lib/mesher/standaloneRenderer.ts (a commented-out invocation)

Please ensure that:

  • Consumers of getLight() (e.g., in the mesher models) are updated to work with block-light-only values.
  • Rendering outcomes—especially where baseLight is normalized by dividing by 15—are validated through integration or visual tests.
  • Any assumptions based on a combined skylight and block light approach are either revised or documented as intentional changes.

@jLn0n
Copy link

jLn0n commented Mar 17, 2025

why not process lighting in WASM?

@zardoy
Copy link
Owner Author

zardoy commented Mar 17, 2025

why not process lighting in WASM?

cause I don't have wasm, no one is gonna make it for me

@jLn0n
Copy link

jLn0n commented Mar 18, 2025

why not process lighting in WASM?

cause I don't have wasm, no one is gonna make it for me

maybe u could use assemblyscript which is like typescript that is compiled to wasm, would be easier than creating manual WASM code

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