Skip to content

Refactor noise computation and update benchmark results in README#3

Merged
kelindar merged 1 commit intomainfrom
grads
Aug 10, 2025
Merged

Refactor noise computation and update benchmark results in README#3
kelindar merged 1 commit intomainfrom
grads

Conversation

@kelindar
Copy link
Owner

This pull request refactors the 2D simplex noise implementation for improved clarity and performance, particularly in how gradients are handled and accessed. The main changes include switching the gradient representation from packed integers to float arrays, updating the initialization logic, and simplifying the noise calculation code. Benchmark results in the README.md have also been updated to reflect new performance metrics.

Gradient representation and initialization:

  • Changed the grad array from storing packed uint16 values to storing [2]float32 arrays, making the gradient vectors easier to use and understand.
  • Updated the gradient initialization in init() to unpack and store gradients directly as float pairs, improving clarity and reducing bit manipulation.

Noise computation simplification:

  • Refactored the Noise2 function to use float values for simplex triangle selection and offsets, streamlining the calculation and reducing unnecessary type conversions.
  • Simplified the lookup and use of permutation and gradient arrays by using slice windows and direct array access, making the code more readable and efficient.
  • Inlined the dot product calculation for gradients, removing the need for a separate dot2D function and improving performance.

Benchmark update:

  • Updated the benchmark section in README.md to show new performance results with more descriptive labels, reflecting the impact of the code changes.

@kelindar kelindar merged commit bc3d6bd into main Aug 10, 2025
2 checks passed
@kelindar kelindar deleted the grads branch August 10, 2025 23:29
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.

1 participant