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

new #2

Open
ahidharb opened this issue Feb 3, 2024 · 0 comments
Open

new #2

ahidharb opened this issue Feb 3, 2024 · 0 comments

Comments

@ahidharb
Copy link

ahidharb commented Feb 3, 2024

typealias MeshColor = SIMD3

// You can provide custom locationRandomizer and turbulencyRandomizer for advanced usage
var meshRandomizer = MeshRandomizer(colorRandomizer: MeshRandomizer.arrayBasedColorRandomizer(availableColors: meshColors))

private var meshColors: [simd_float3] {
return [
MeshRandomizer.randomColor(),
MeshRandomizer.randomColor(),
MeshRandomizer.randomColor(),
]
}

// This methods prepares the grid model that will be sent to metal for rendering
func generatePlainGrid(size: Int = 6) -> Grid {
let preparationGrid = Grid(repeating: .zero, width: size, height: size)

// At first we create grid without randomisation. This is smooth mesh gradient without
// any turbulency and overlaps
var result = MeshGenerator.generate(colorDistribution: preparationGrid)

// And here we shuffle the grid using randomizer that we created
for x in stride(from: 0, to: result.width, by: 1) {
for y in stride(from: 0, to: result.height, by: 1) {
meshRandomizer.locationRandomizer(&result[x, y].location, x, y, result.width, result.height)
meshRandomizer.turbulencyRandomizer(&result[x, y].uTangent, x, y, result.width, result.height)
meshRandomizer.turbulencyRandomizer(&result[x, y].vTangent, x, y, result.width, result.height)

meshRandomizer.colorRandomizer(&result[x, y].color, result[x, y].color, x, y, result.width, result.height)

}
}

return result
}

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

No branches or pull requests

1 participant