All Projects → s-ol → Gpwfc

s-ol / Gpwfc

openCL-accelerated python implementation of the Wave Function Collapse procgen algorithm

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Gpwfc

Texturesynthesis
Texture synthesis from examples
Stars: ✭ 709 (+1816.22%)
Mutual labels:  algorithm, procedural-generation, gamedev
Convchain
Bitmap generation from a single example with convolutions and MCMC
Stars: ✭ 581 (+1470.27%)
Mutual labels:  algorithm, procedural-generation, gamedev
Wavefunctioncollapse
Bitmap & tilemap generation from a single example with the help of ideas from quantum mechanics
Stars: ✭ 17,156 (+46267.57%)
Mutual labels:  algorithm, procedural-generation, gamedev
Primestereomatch
A heterogeneous and fully parallel stereo matching algorithm for depth estimation, implementing a local adaptive support weight (ADSW) Guided Image Filter (GIF) cost aggregation stage. Developed in both C++ and OpenCL.
Stars: ✭ 191 (+416.22%)
Mutual labels:  algorithm, opencl
Godot3 procgen demos
Exploring Procedural Generation algorithms in Godot
Stars: ✭ 85 (+129.73%)
Mutual labels:  procedural-generation, gamedev
wfc
Go port of the Wave Function Collapse algorithm
Stars: ✭ 47 (+27.03%)
Mutual labels:  gamedev, procedural-generation
Utymap
Highly customizable library for procedural world generation based on real map data
Stars: ✭ 825 (+2129.73%)
Mutual labels:  procedural-generation, gamedev
Blog
About math, programming and procedural generation
Stars: ✭ 37 (+0%)
Mutual labels:  procedural-generation, gamedev
Sudoku Generator
A Sudoku puzzle generator written in C++ using modified and efficient backtracking algorithm.
Stars: ✭ 33 (-10.81%)
Mutual labels:  algorithm
Opencl.uplugin
OpenCL Plugin for Unreal Engine 4
Stars: ✭ 34 (-8.11%)
Mutual labels:  opencl
Katsudo
Katsudö is an animation library for LÖVE
Stars: ✭ 32 (-13.51%)
Mutual labels:  gamedev
Rhashmap
Robin Hood hash map library
Stars: ✭ 33 (-10.81%)
Mutual labels:  algorithm
Data Structures Questions
golang sorting algorithm and data construction.
Stars: ✭ 977 (+2540.54%)
Mutual labels:  algorithm
Algo
📚 My solutions to algorithm problems on various websites
Stars: ✭ 32 (-13.51%)
Mutual labels:  algorithm
Google Hash Code 2020
More Pizza : Solution for the Practice Round of Google Hash Code 2020
Stars: ✭ 36 (-2.7%)
Mutual labels:  algorithm
Algorithms
Study cases for Algorithms and Data Structures.
Stars: ✭ 32 (-13.51%)
Mutual labels:  algorithm
Algos
Popular Algorithms and Data Structures implemented in popular languages
Stars: ✭ 966 (+2510.81%)
Mutual labels:  algorithm
Openclpapers
A Collection of Articles and other OpenCL Papers
Stars: ✭ 37 (+0%)
Mutual labels:  opencl
Autexousious
Main repository for Will -- 2.5D moddable action adventure game
Stars: ✭ 36 (-2.7%)
Mutual labels:  gamedev
Learn
learn
Stars: ✭ 970 (+2521.62%)
Mutual labels:  algorithm

gpWFC

Implementation of the Wave Function Collapse procedural content generation algorithm, using (py)OpenCL for GPU acceleration.

circuit example simple  example

Getting Started

make sure you have the python packages pyopencl, numpy and pyglet installed.

You can then run a basic example using

python main.py

in the preview window the following keybindings are set:

  • escape: close
  • space: do one oberservation/propagation cycle and render
  • r: cycle until stable, then render again
  • d: debug view (overlay decimal display of bitmask for each tile)

There is also a more interesting sprite-based example that you can run using

python circuit.py [render]

but as you can see I didn't set up the model constraints properly. Maybe you want to fix that?

main.py can take a few options that are just passed as strings on the command line, in any order. They might not all be compatible with each other, in any case main.py is only a starting point to write your own set up code with a more serious model.

cpu

propagate using a simplistic CPU algorithm.

3d

work in a 3d space (4x4x2 by default), with a very rudimentary preview. more of a proof of concept, but totally workable.

In the 3d preview, the up and down keys can be used to cycle through slices of the Z axis.

silent

don't open a preview or render, just measure the execution time.

render

automatically step execution forward and take save a screenshot to shots/0001.png etc. You can use e.g. ffmpeg to turn the png frames into an animation.

Programatic Usage

gpWFC is set up to follow a 'mix and match' modular architecture as best as possible. It is therefore divided into a couple of components that need to be used to run a simulation:

  • the Tiles (Tile and SpriteTile from models.py):
    • tile.weight (float): the relative probability of occurence
    • tile.compatible(other, direction_id) (bool): constraint information
    • additional information for the Preview, e.g. tile.image and tile.rotation for SpriteTile
  • the Model (Model2d and Model3d from models.py):
    • information about the world:
      • model.world_shape (tuple): dimensions of the world (any nr of axes)
      • model.get_neighbours(pos) (generator): tile adjacency information
    • information about the tiles:
      • model.tiles (list): the tiles to be used
      • model.get_allowed_tiles(bitmask) (list): a way to resolve the opaque bitmask
  • the Runner (Runner and BacktrackingRunner from runners.py):
    • runner.step() (string): execute a single observartion/propagation cycle
    • runner.finish() (string): run the simulation until it either fails or stabilizes
    • runner.run() (generator): iterate over runner.step()
    • all of these return/yield status strings, which are one of:
      • 'done' - fully collapsed
      • 'error' - overconstrained / stuck
      • 'continue' - step successful but uncollapsed tiles remain
  • the Preview (PreviewWindow* from previews.py):
    • preview.draw_tiles(pos, bits): draw the tiles at pos (tuple)
    • preview.launch(): enter interactive preview mode
    • preview.render(): enter non-interactive render loop
  • the Observer and Propagator (observers.py and propagators.py):
    • you probably don't need to touch these

You can find a straightforward example of the basic setup steps in circuit.py, it should follow this flow:

  • instantiate a Model
  • instantiate Tiles and register them with the Model
  • instantiate a Runner and pass it the Model
  • instantiate a Preview and pass it the Runner
  • launch the Preview

GPU-only rendering

There is a terribly broken glsl-render branch that tries to not ever get the buffer back to CPU memory during propagation, while still rendering the world in a GLSL shader. Unfortunately I could never get it to work properly with pyOpenCL to date, and due to some other constraints I also cannot test or bring the current version back to the best state it was in, so it will remain in a messy test state for now.

If anyone is brave enough to touch it though, when working, it should give some incredible performance gains as the rendering and memory transfer / gpu blocking are by far the biggest slow-downs at the moment. There is also some hope since a new version of pyOpenCL is apparently on the way.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].