Skip to content

Instantly share code, notes, and snippets.

View runevision's full-sized avatar

Rune Skovbo Johansen runevision

View GitHub Profile
@runevision
runevision / BurstMethodTester.cs
Last active February 27, 2026 22:09
Using Unity Burst directly on methods without jobs - unofficial example code
using Unity.Burst;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs;
using UnityEngine;
// This example code demonstrates using Unity Burst directly on a static method without jobs.
// Unity NativeArrays can't be used directly in Unity Burst methods (only in Burst jobs),
// so we have to pass pointers to arrays instead.
@runevision
runevision / ProjectionViewer.cs
Created August 17, 2024 12:01
Script to create visual illusion of rotating wireframe object that tricks the eye into switching orientation and rotation direction
using UnityEngine;
// Visual effect/illusion where a rotating model alternates between
// seeming to rotate one way around and the other.
// Unlike many similar effects, the eyes are nudged/forced to see it
// in alternating ways by oscillating between regular perspective and
// inverse perspective, changing which parts of the model appear
// bigger or smaller on the screen.
// Attach this script on the GameObject with the Camera component.
@runevision
runevision / BurstSDFGenerator.cs
Created September 11, 2024 07:48
Signed Distance Field generator for Unity with Burst support
/*
Based on the Anti-aliased Euclidean distance transform described by Stefan Gustavson and
Robin Strand. For further information, see https://contourtextures.wikidot.com/ and
https://web.archive.org/web/20220503051209/https://weber.itn.liu.se/~stegu/edtaa/
The algorithm is an adapted version of Stefan Gustavson's code, it inherits the copyright
statement below, which applies to this file only.
The rewrite with Unity Burst support makes the execution 40 times faster by default,
and 75 times faster if the passed in textures are both of type TextureFormat.RGBAFloat.
@runevision
runevision / ErosionNoise.cs
Last active September 10, 2025 11:35
Erosion noise implementation in C#
/*
Erosion noise implementation in C# (with the Unity.Mathematics package),
ported one-to-one from the Shadertoy shader code by Fewes and clayjohn.
Please note that while the majority of the code is provided under the MIT license,
the quite central "erosion" function is adapted from code shared under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Shadertoy comment by Fewes from https://www.shadertoy.com/view/7ljcRW :
@runevision
runevision / BalloonTouch.cs
Last active March 11, 2026 11:21
Demo code for calculating the touch point between a "ballooning" circle and a rectangle
using UnityEngine;
[ExecuteAlways]
public class BalloonTouch : MonoBehaviour {
public Transform start;
public Transform other;
void Update() {
Vector2 startPoint = start.position;
@runevision
runevision / IntNoise.cginc
Created May 29, 2026 15:16
GPU fixed point noise (HLSL)
/*
Fixed point 2D and 3D noise functions:
float Noise(in int2 p, float pRes, float freq)
float Noise(in int3 p, float pRes, float freq)
Fixed point 2D noise function with derivatives:
float3 NoiseD(in int2 p, float pRes, float freq)
- p is the input coordinates in raw integers.
- pRes is the "resolution" of one unit; the integer value