Skip to content

Instantly share code, notes, and snippets.

View mzandvliet's full-sized avatar

Mar Zandvliet mzandvliet

View GitHub Profile
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
/*
Possible effects to model:
Attenuation of taps
- Apparent surface area
import math
import random;
from sympy import *
'''
=== Toying with Benford's law ===
https://en.wikipedia.org/wiki/Benford's_law
Introductory video by Numberphile: www.youtube.com/watch?v=XXjlR2OK1kM
Shader "Unlit/Outline"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_OutlineColor("Outline Color", Color) = (0,0,0,1)
_OutlineThickness("Outline Thickness", Range(0,1)) = 0.03
}
SubShader
@mzandvliet
mzandvliet / ColliderMovingCost.cs
Last active November 26, 2019 11:32
Test script for profiling moving of colliders with various configurations in Unity
using System.Collections.Generic;
using UnityEngine;
public class ColliderMovingCost : MonoBehaviour {
[SerializeField] private bool _useKinematicRigidbodies = true;
[SerializeField] private bool _moveCollidersUsingRigidbody = false;
private List<Transform> _colliderTransforms;
private List<Rigidbody> _colliderBodies;
@mzandvliet
mzandvliet / LookAt2dWithoutTrig.cs
Created October 30, 2019 23:59
Rotating A Thing To Look At Another Thing, Without Trigonometry - Part 1
using UnityEngine;
using Unity.Mathematics;
public struct Transform2D {
public float2 position;
public float2 velocity;
}
public class LookAt2dWithoutTrig : MonoBehaviour
{
@mzandvliet
mzandvliet / ProceduralGeometryExample.cs
Created October 26, 2019 11:14
Sketch of how you procedurally generate data using Burst, then pass it to gpu through compute buffers
// C# side
public class LineRenderer : MonoBehaviour {
[SerializeField] private Camera _camera;
[SerializeField] private Material _lineMaterial;
private NativeArray<float3> _linePoints;
private ComputeBuffer _linePointBuffer;
private ComputeBuffer _lineIndexBuffer;
private int _lineCount;
@mzandvliet
mzandvliet / NativeCollectionUtilities.cs
Created October 26, 2019 10:53
Some utilities for copying data between native and managed containers as quickly as possible
using Unity.Collections;
using Unity.Mathematics;
using UnityEngine;
using Unity.Collections.LowLevel.Unsafe;
/*
Utility for memcopying data from native to managed containers and vice versa.
Todo: Is it possible to generic memcopy implementations, where Source, Dest : struct?
If not, you know what to do: *** code generation ***
@mzandvliet
mzandvliet / DspApplication.cs
Last active July 23, 2022 00:13
A quick example of how to play a mouse-controlled sine wave using the DSPGraph preview package
using UnityEngine;
using Unity.Collections;
using Unity.Audio;
using Unity.Mathematics;
using Unity.Burst;
using System.Collections;
/*
For allocations inside AudioKernels, use Allocator.AudioKernel
*/
/*
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-7.0/pattern-matching
Cool proposal. Here I do a quick rewrite using the Unity ~C#6 syntax:
*/
namespace Algebra {
public abstract class Expr { }
-------------------------------------------------------------------------------
Build Report
Uncompressed usage by category:
Textures 2165.0 mb 19.4%
Meshes 7832.8 mb 70.2%
Animations 1.1 mb 0.0%
Sounds 148.2 mb 1.3%
Shaders 58.7 mb 0.5%
Other Assets 676.7 mb 6.1%
Levels 218.6 mb 2.0%