Icon

Dithering GPU

Cem Baspinar

You must be logged in to obtain assets

Description

This extension allows you to run various dithering algorithms on the GPU for procedural placement.

Works with latest GM:S 1.4 and GM:S 1.99 EA.

Procedural placement can be used to distribute objects (like flowers, trees, different terrain soil) to achieve more natural look.

Jaap van Muijden explains how they used this technique to achive GPU-based procedural placement for Horizon: Zero Dawn game on his GDC 2017 Talk. (Summary and slides can be accessed via this link: www.guerrilla-games.com/read/gpu-based-procedural-placement-in-horizon-zero-dawn www.youtube.com/watch?v=t258ePDlxtQ )

With this extension you can turn any grayscale gradient to a placement grid, surface or buffer. Dithering is done using a shader on the GPU and the rest is handled by the scripts.

Package Includes several Dithering Algorithms that can be programmed in GLSL ES. Here is the included ones:

  1. Random noise (Cheap & Dirty)
  2. Random with mod
  3. Random with Voronoi
  4. Triangle noise
  5. Blue noise
  6. Interleaved gradient noise
  7. Temporal dithering
  8. Ordered dithering (a.k.a. bayer matrix)

This package does NOT include well-known algorithms like Floyd-Steinberg, Sierra, Atkinson, Burkes or Jarvis-Judice- Ninke. Such algorithms are not very suitable for the architecture of the GPU programming. Although they are not impossible to code with GLSL, they are less likely to perform better than CPU-based versions. Due to the speed of the GPU being extremely fast, we see new GPU-based algorithms are being invented and the old ones are used less and less.

If you are interested in new dithering efforts for image processing (which is a little different than disk sampling), you can check out the algorithm that the developer of the indie game Return of the Obra Dinn created. The source code is also available on Github. Here is an article he, himself, explains the algorithm. https://forums.tigsource.com/index.php?topic=40832.msg1217196#msg1217196

The included shader can be used for image processing too. But the scripts are focused more on procedural placement.

They are all designed to be super-fast and low cost.

HOW TO USE IT

Create a grayscale image procedurally or using an image editor.

Basic Usage:

gpu_dither_init(); // Sets required enums
dither = gpu_dither_create_from_sprite(spr);
// or use these depending on your source:
// dither = gpu_dither_create_from_surface(surface);
// dither = gpu_dither_create_from_background(bg); 
// these will create a buffer which you can get values from.

// Gets the value for x and y. This script has almost 
// zero cost. Should take around ~0.005 ms
tile_value = gpu_dither_get_value(dither, x, y);

// Remember to free up the memory after you are done
gpu_dither_free(dither);

More Advanced Example:

gpu_dither_init(); // Always run this first
dither = gpu_dither_create_from_surface(some_surface, _w, _h, 0, 1, algorithm);
algorithm++; // algorithm is an instance variable or global var.

// Update the dither with the new algorithm value
dither = gpu_dither_update(dither, _w, _h, 0, 1, algorithm);

// on Draw event:
var new_surface = gpu_dither_to_surface(dither);
if (!is_undefined(new_surface)) {
    draw_surface(new_surface, mouse_x, mouse_y);
}

// on GameEnd event:
gpu_dither_free(dither);

Documentation is included in the scripts folder. (README_gpu_dither.gml)

End User Licence Agreement (EULA).

Age Rating: 4+

Version

GMS1 - Version 1.0.0. Published September 4, 2017

Loading, please wait

Package contents

Loading, please wait

What is the issue?

Loading, please wait