Skip to content

new #2

Description

@ahidharb

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
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions