Skip to content

Instantly share code, notes, and snippets.

View StagPoint's full-sized avatar

StagPoint Software StagPoint

  • StagPoint Software
  • Seattle, WA
View GitHub Profile
@tansey
tansey / gist:1444070
Created December 7, 2011 18:49
Sampling from a Gaussian Distribution in C#
public static double SampleGaussian(Random random, double mean, double stddev)
{
// The method requires sampling from a uniform random of (0,1]
// but Random.NextDouble() returns a sample of [0,1).
double x1 = 1 - random.NextDouble();
double x2 = 1 - random.NextDouble();
double y1 = Math.Sqrt(-2.0 * Math.Log(x1)) * Math.Cos(2.0 * Math.PI * x2);
return y1 * stddev + mean;
}
@jstanden
jstanden / gist:1489447
Last active May 15, 2024 20:47
Simplex Noise in C# for Unity3D - Adapted from James Livingston's MinePackage: http://forum.unity3d.com/threads/minepackage-minecraft-starter-package.69573/
using UnityEngine;
using System.Collections;
public class SimplexNoiseGenerator {
private int[] A = new int[3];
private float s, u, v, w;
private int i, j, k;
private float onethird = 0.333333333f;
private float onesixth = 0.166666667f;
private int[] T;
@qwertie
qwertie / Clipper.cs
Created February 15, 2012 23:05
Refactored Clipper library (Vatti polygon intersection/union/difference)
/*******************************************************************************
* *
* Author : Angus Johnson *
* Edited by : David Piepgrass *
* Version : 4.7 + edits *
* Date : 15 February 2012 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2012 *
* *
* Note: I, David Piepgrass, refactored this library from its original version *
@KvanTTT
KvanTTT / PolygonTriangulator.cs
Created October 8, 2012 21:31
Short solution for splitting concave polygon on convex polygons or triangles with other utils (SelfIntersection checking).
using System.Collections.Generic;
using System.Drawing;
public class PolygonTriangulator
{
/// <summary>
/// Calculate list of convex polygons or triangles.
/// </summary>
/// <param name="Polygon">Input polygon without self-intersections (it can be checked with SelfIntersection().</param>
/// <param name="triangulate">true: splitting on triangles; false: splitting on convex polygons.</param>
@radiatoryang
radiatoryang / TriplanarWorld.shader
Created February 6, 2013 19:24
a triplanar / procedural UV / world space UV shader for Unity, cobbled together bits from @quickfingerz and @Farfarer
Shader "Tri-Planar World" {
Properties {
_Side("Side", 2D) = "white" {}
_Top("Top", 2D) = "white" {}
_Bottom("Bottom", 2D) = "white" {}
_SideScale("Side Scale", Float) = 2
_TopScale("Top Scale", Float) = 2
_BottomScale ("Bottom Scale", Float) = 2
}
@Farfarer
Farfarer / CombineNormalMapsWizard.cs
Created February 12, 2013 10:40
Combines a base and a detail normal map to a new normal map texture, for Unity3D.
using UnityEditor;
using UnityEngine;
using System.IO;
// PLACE IN EDITOR FOLDER
class CombineNormalMapsWizard : ScriptableWizard {
public Texture2D baseNormal = null;
@Jerdak
Jerdak / FreeFormDeformer.cs
Created August 12, 2013 04:24
Example of free form deformation using Unity. Full package can be found in my main repository: https://github.com/Jerdak/FreeFormDeformation/tree/master/Unity
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Helper class that represents a parameterized vertex
/// </summary>
public class Vector3Param {
///bernstein polynomial packing
// 2D triangulation using ear clipping by urraka
//
// Usage:
// std::vector<vec2> polygon;
// std::vector<int> result = math::triangulate<int>(polygon);
//
// * vec2 is anything that has float x,y
// * result is a list of indices that point to the polygon vector (a triangle is defined every 3 indices).
#include <vector>
@RyanNielson
RyanNielson / TrackTargets.cs
Created March 30, 2014 20:15
A orthographic camera script for Unity that keeps all targets in frame by adjusting orthographic size and camera position.
using UnityEngine;
public class TrackTargets : MonoBehaviour {
[SerializeField]
Transform[] targets;
[SerializeField]
float boundingBoxPadding = 2f;
@KeyMaster-
KeyMaster- / spriteGlitch.shader
Last active April 15, 2025 14:16
A glitch effect shader for Sprites in Unity3D
//Copyright (c) 2014 Tilman Schmidt (@KeyMaster_)
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in