GithubHelp home page GithubHelp logo

emmetot / buffersorter Goto Github PK

View Code? Open in Web Editor NEW
16.0 1.0 4.0 26 KB

This is a very simple tool for in-place sorting of ComputeBuffers of ints on the GPU, meant for use in Unity.

License: The Unlicense

C# 100.00%
unity gpu sorting-algorithms bitonic-merge-sort compute-shader hlsl unity3d shaders

buffersorter's Introduction

BufferSorter

This is a very simple tool for in-place sorting of ComputeBuffers of ints or uints on the GPU, meant for use in Unity. I wrote this to use with a basic GPU particle system I'm working on, which needs to always be sorted consistently between frames.

This is based on the great work of nobnak, available here. I simply wanted to make it a little more user friendly for my own needs. The fundamental sorting algorithm is their own work.

My additions are:

  • It now works in-place, changing the data in the given ComputeBuffer to be sorted.
  • The data buffer no longer needs to have a power of two size.
  • You can optionally sort in reverse.
  • You can provide a distinct buffer containing sort keys if you want custom sorting behaviour.
  • You can optionally sort only a subset of the data, the first of N. Note that this option completely disregards the content of the remainder of the buffer, so it could be considered 'destructive' in that the set of ints will no longer be the same.
  • I've generally just hidden a lot of the extra bits and bobs away inside the class, making it very simple to use from the outside.

How to Use

Like this:

image

It couldn't be simpler, really. Reverse, sublist length, and sort key buffer are optional parameters.

The project included is Unity version 2020.3.0f1, but there's nothing in the project other than the C# file and compute shader (as well as some unit tests in a demo script), and nothing especially version dependent. Just copy the scripts and meta files over and you're good to go.

buffersorter's People

Contributors

emmetot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

buffersorter's Issues

doesnt work on vulkan

Hello! I am using this in a unity GPU instancing tool where instances need to be sorted by the distance to the camera. it sorts properly on dx11 and dx12, however on vulkan most of the attempts fail. im using unity 2021.2/3, though i doubt that should matter.

Screenshot_1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.