https://github.com/eleev/fractal-bline-motion-effect
Metal shader for FBM-based pattern generation
https://github.com/eleev/fractal-bline-motion-effect
Last synced: 6 months ago
JSON representation
Metal shader for FBM-based pattern generation
- Host: GitHub
- URL: https://github.com/eleev/fractal-bline-motion-effect
- Owner: eleev
- Created: 2024-06-11T11:24:12.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-11T12:13:30.000Z (about 2 years ago)
- Last Synced: 2025-01-19T06:26:27.876Z (over 1 year ago)
- Language: Metal
- Size: 9.41 MB
- Stars: 39
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Metal FBM Pattern Generator [](https://github.com/sindresorhus/awesome)
[]()
[]()
[]()
[]()
[]()
[]()
[]()
[]()
### If you like the project, please give it a star ⭐ It will show the creator your appreciation and help others to discover the repo.
# ✍️ About
🪄 **Metal shader** for Fractal Brownian Motion to generate animated glowing patterns from lines.
# 📺 Demo
Please note that the `.gif` files have low frame rate due to compression and accessibility of demo.

# 🏗️ Approach
This Metal shader leverages procedural noise and Fractal Brownian Motion (fbm) to generate dynamic and visually appealing animated colored lines. The core functionality of the shader is broken down into several key components that work together to create smooth transitions and natural-looking patterns.
The initial part starts from a hashing function.The hashing function is crucial for generating deterministic pseudo-random values. It operates by:
- Taking the dot product of the input vector with a fixed vector of constants.
- Calculating the sine of the resulting value.
- Scaling the sine value by a large constant and extracting the fractional part of this product. This fractional part serves as the pseudo-random number, constrained within the range [0, 1).
The next stage is noise function. The noise function is responsible for producing smoothly interpolated random values. It achieves this through the following steps:
- Dividing the input coordinates into their integer and fractional components.
- Applying a fade curve to the fractional parts to ensure smooth transitions between noise values.
- Generating hash values for the cell corners surrounding the point.
- Using the fade curve to interpolate these hash values, resulting in seamless transitions and continuous noise values.
This Metal shader utilizes procedural noise, hashing functions, and Fractal Brownian Motion (fbm) to create intricate and dynamic animated patterns of colored lines. Initially, the hashing function deterministically generates pseudo-random values by performing a dot product of the input vector with a fixed vector, applying a sine function, scaling the result by a large constant, and extracting the fractional part. The noise function further processes these values by splitting input coordinates into integer and fractional parts, applying a fade curve to the fractional parts, generating hash values for surrounding cell corners, and interpolating these values for smooth transitions.
Building on this, the fbm function creates complex and natural textures by initializing a result value to zero and adding noise values at varying frequencies (octaves), scaled by corresponding amplitudes from an amplitude vector. These scaled noise values are then combined to produce the final fbm value, with the summation of different frequencies and amplitudes yielding intricate patterns used in applications like terrain and cloud rendering.
The shader's visual pattern generation involves drawing animated colored lines influenced by procedural noise and fbm. This process is accomplished via multiple iterations, each iteration enhancing complexity through noise influences. The results from these iterations are combined to form a dynamic and aesthetically pleasing final pattern.
Operationally, the shader runs in two main loops. The first loop generates initial sets of colored lines through several iterations, while the second loop refines and combines these lines, influenced by noise and fbm, to produce the final animated visual pattern. By executing these processes, the shader achieves natural-looking textures and smooth transitions suitable for a variety of procedural texture applications.
# 👨💻 Author
[Astemir Eleev](https://github.com/eleev)
# 🔖 Licence
The project is available under [MIT Licence](https://github.com/eleev/swiftui-new-metal-shaders/blob/master/LICENSE)