• Stars
    star
    1,384
  • Rank 33,758 (Top 0.7 %)
  • Language
    C#
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Unity Technologies management has fucked everything up. this is a guide to the job system circa 2019

C# Job System Cookbook

This is a repo of examples I've written to learn how to use the C# job system to write systems at scale, here for reference and sharing.

The goal of this repo is making it clearer how you can structure your data, schedule your jobs, and use the results. So, the examples use easy to understand problems & algorithms.

This repo does not cover using C# jobs with the Entity Component System. Please see the official example repo for more on that.

Each example script has a corresponding scene where it's set up.

Job System Details

You can use the job system in Unity 2018.x right now. I recommend 2018.2 for these examples now.

For a detailed look into how the C# job system works, please watch the Unite Austin presentation if you haven't seen it. There is also a Q & A from Unite Berlin in 2018

Examples

Note: examples in this repo use LateUpdate() as an easy way to handle completing jobs later than we schedule them, but in real code you might want to schedule the jobs early in Update (using Script Execution Order maybe) so you can use the result later in the same frame.

All examples demonstrate the use of persistently-allocated job memory.

Realtime Image Processing (with Burst compilation)

Process input from a webcam in real time using Burst-compiled jobs.

the job details are all in this file, and the above file is the main script.

This demo implements 5 different effects , all based around operating on a pixel only if it's color channel value is over some threshold

To change the color thresholds, select the WebcamDisplay in the heirarchy of the example scene & check out the Webcam Processing component. You can also change the scanline effect as well as select a webcam resolution that works for you there.

Change Mesh Vertices & Normals Every Frame

Modify all vertices & normals of a mesh in parallel every frame.

This is the most visually interesting example. Uses a more complex single job.

Change Mesh Vertices Every Frame

Modify all 20678 vertices of a mesh in parallel every frame, using Perlin noise & sin(time).

Uses a single job.

Accelerate 10000 Cubes

First determine velocities, then change positions based on those velocities.

Demonstrates using the TransformAccessArray, necessary for doing transform operations in jobs.

Point & Bounds Intersection Checks

Check a Vector3 and a Bounds for intersection against a list of 10000 Bounds.

Demonstrates running 2 independent jobs.

Ray / Bounds Intersection Checks

Check a Ray for intersection with a large Bounds array in two steps.

Demonstrates reducing an array of checks to a smaller list, and using temporarily-allocated job memory.

Point Cloud Generation & Processing

Generates a cloud of 10000 points, then calculates magnitudes & normalizes the points.

Further Examples

Keijiro Takahashi has a great example of using the job system with ECS

More Repositories

1

SharedArray

Zero-copy sharing between managed and native arrays in Unity
C#
152
star
2

OscCore

A performance-oriented OSC library for Unity
C#
142
star
3

Resolink

Unity package to make integrating with Resolume (a VJing software) easier
C#
64
star
4

weekend-tracer

An implementation of 'Ray Tracing in One Weekend', using C# and Unity's Burst compiler
C#
45
star
5

BurstImageProcessing

fast parallel image processing on the CPU, using Unity C# jobs and Burst compilation
C#
21
star
6

SharedArray-Demo

Demo Unity project for SharedArray library
C#
19
star
7

vision-union

simple CV pipeline prototype using Unity C# jobs
C#
18
star
8

SchlickCurve

Unity implementation of a generalization of Schlick’s bias & gain functions
C#
10
star
9

ByteStrings

Minimal implementation of storing strings in native memory
C#
8
star
10

BlobHandles

A way to use chunks of bytes as hash keys, for Unity
C#
6
star
11

NtpTimestamp

A representation of 64-bit NTP timestamps for use in other projects
C#
3
star
12

DotGraph

Basic graph theory constructs implemented via the Unity C# Job System
C#
3
star
13

pubbable

DAO-ish thing for cocktail bars
TypeScript
3
star
14

star

toy 3d engine
C++
2
star
15

micro-benchmarks

C# micro benchmarks for Unity
C#
2
star
16

solana-data

toy CLI tool for accessing & analyzing Solana blockchain data
Rust
1
star
17

ucharts-prototype

C#
1
star
18

readback-loop-demo

C#
1
star
19

Serial-Object-Stream

do you need to serialize a fuckton of some object to disk in Unity, but you can't stop the app to do so? probably not, but that's what this does
C#
1
star
20

AR-Clips

C#
1
star
21

rave-strategies

a port of https://github.com/datacorruption/Rave-Strategies to the browser
JavaScript
1
star
22

ExternJobs-Project

Auto-generate wrappers to integrate native code with Unity's C# job system
C#
1
star