Skip to content

Instantly share code, notes, and snippets.

View MattRix's full-sized avatar

Matt Rix MattRix

View GitHub Profile
@MattRix
MattRix / CurvatureImageEffect.shader
Last active February 2, 2024 20:15
Cavity/Curvature image effect shader based on the Blender node graph in this post: https://blender.community/c/rightclickselect/J9bbbc/
Shader "Milkbag/CurvatureImageEffect"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_LightStrength ("LightStrength", Float) = 0.3
_DarkStrength ("DarkStrength", Float) = 0.3
_Spread ("Spread", Float) = 1.0
[Toggle(USE_MULTIPLY)] _UseMultiply("Use Multiply", Float) = 0
[Toggle(CURVATURE_ONLY)] _CurvatureOnly("Curvature Only", Float) = 0
@MattRix
MattRix / cellular_noise.cginc
Created March 1, 2021 23:10
Worley cellular noise for HLSL (and Unity), translated from from Stefan Gustavson's GLSL version
// Cellular noise ("Worley noise") in 2D in GLSL.
// Copyright (c) Stefan Gustavson 2011-04-19. All rights reserved.
// This code is released under the conditions of the MIT license.
// See LICENSE file for details.
// https://github.com/stegu/webgl-noise
// Modulo 289 without a division (only multiplications)
float3 mod289(float3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
@MattRix
MattRix / BezierLineRenderer.cs
Created March 7, 2020 21:27
A simple single bezier line graphic with a repeating texture pattern
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
[RequireComponent(typeof(CanvasRenderer))]
public class BezierLineRenderer : Graphic
{
public Texture texture;
@MattRix
MattRix / EditorUtils.cs
Created February 26, 2020 19:56
Tools for forcing Unity to pick up changes to .asset files
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Linq;
using System.IO;
public class EditorUtils
{
[MenuItem("CONTEXT/ScriptableObject/Sync")]
@MattRix
MattRix / DrawTile.html
Last active April 21, 2020 14:08
Simple tool to generate the uints necessary for u8x8 drawtile: https://github.com/olikraus/u8g2/wiki/u8x8reference#drawtile - jsfiddle version: https://jsfiddle.net/hongm3tu/3/
<div id="main"></div>
<br/>
<button id="clear">Clear</button>
<button id="fill">Fill</button>
<button id="load">Load</button>
<br/>
<br/>
<textarea id="output"></textarea>
@MattRix
MattRix / avril14.ino
Created November 16, 2019 21:10
Avril 14 on the Arduino OPL2
#include <SPI.h>
#include <OPL2.h>
#include <midi_instruments.h>
OPL2 opl2;
float tempo = 80;
const int numParts = 3;
int bassNotes[] = {32,36,37,34};
@MattRix
MattRix / EditorZoomer.cs
Created October 27, 2019 23:18
EditorZoomer - an easy way to do panning and zooming inside Unity Editor IMGUI
using UnityEngine;
using System.Collections;
using System;
//based on the code in this post: http://martinecker.com/martincodes/unity-editor-window-zooming/
//but I changed how the API works and made it much more flexible
//usage: create an EditorZoomer instance wherever you want to use it (it tracks the pan + zoom state)
//in your OnGUI, draw your scrollable content between zoomer.Begin() and zoomer.End();
//you also must offset your content by zoomer.GetContentOffset();
@MattRix
MattRix / EditorZoomArea.cs
Last active April 7, 2023 04:44
Unity Editor Window Zooming (fixed version of code from http://martinecker.com/martincodes/unity-editor-window-zooming/)
using UnityEngine;
// Helper Rect extension methods
public static class RectExtensions
{
public static Vector2 TopLeft(this Rect rect)
{
return new Vector2(rect.xMin, rect.yMin);
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BackwardEulerController : MonoBehaviour
{
public float gain = 200; //200-700;
public float damp = 20; //20-100;
public Transform target = null;
@MattRix
MattRix / EmoPacker.cs
Last active March 13, 2024 17:02
Packing a folder of images into a sprite atlas for use with TextMeshPro
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;