Skip to content

Instantly share code, notes, and snippets.

@MightyPrinny
MightyPrinny / ChooseWithProbabilities.cs
Created January 24, 2020 06:43
Chooses values from an array using a probabilities array
/// <summary>
///Returns a random object from the array with probabilities
///</summary>
/// <param name="prob">the probability of being chosen for each value in the array, their sum must be <= 1</param>
public static T ChooseWithProbabilities<T>(float[] prob,params T[] array)
{
float rn = RNG.Randf();
int len = array.Length;
float[][] intervals = new float[len][];
if (len != prob.Length || len == 0)
@MightyPrinny
MightyPrinny / smooth_pixels.shader
Last active December 24, 2019 19:52
Godot shader to make pixel art look less jittery when the resolution isn't a multiple of the internal resolution.
shader_type canvas_item;
uniform vec2 texelsPerPixel = vec2(1.5,1.5);
void fragment()
{
vec2 uv = SCREEN_UV/SCREEN_PIXEL_SIZE;
vec2 locationWithinTexel = fract(uv);
vec2 interpolationAmount = clamp(locationWithinTexel/texelsPerPixel ,0 , 0.5)
+ clamp( (locationWithinTexel - 1.0) / (texelsPerPixel + .5), 0, 0.5);