Skip to content

Instantly share code, notes, and snippets.

View mandarinx's full-sized avatar

Thomas Viktil mandarinx

View GitHub Profile
@BrianAmadori
BrianAmadori / OutlineShader.shader
Last active August 7, 2023 22:46
Screen buffer based depth outline shader
//
// Screen space based depth outline. No post processing setup needed.
//
// - Enable Depth Buffer on URP settings.
// - Put any geometry with this shader (like a Quad) in front of geometry.
// - Voila.
//
// This shader is based on the work of Mirza Beig.
// https://github.com/MirzaBeig/Post-Processing-Wireframe-Outlines
//
@runevision
runevision / Text2.cs
Last active December 15, 2022 10:01
Text2 extends the Unity UI Text class and makes hyphens and soft hypens work
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
// Text2 extends the Text component in Unity UI.
// It makes hyphens and soft hyphens work.
// Inserting soft hyphens in text can be tricky and confusing, given they are invisible,
// so you can instead also insert Hyphenation Point characters, which will be replaced by soft hyphens:
// https://www.compart.com/en/unicode/U+2027
public class Text2 : Text {
@brihernandez
brihernandez / ComputeGunLead.cs
Last active June 1, 2021 03:49
Computes a point for a gun to aim at in order to hit a target using linear prediction.
/// <summary>
/// Computes a point for a gun to aim at in order to hit a target using linear prediction.
/// Assumes a bullet with no gravity or drag. I.e. A bullet that maintains a constant
/// velocity after it's been fired.
/// </summary>
public static Vector3 ComputeGunLead(Vector3 targetPos, Vector3 targetVel, Vector3 ownPos, Vector3 ownVel, float muzzleVelocity)
{
// Extremely low muzzle velocities are unlikely to ever hit. This also prevents a
// possible division by zero if the muzzle velocity is zero for whatever reason.
if (muzzleVelocity < 1f)
@JimmyCushnie
JimmyCushnie / UnityGraphicsBullshit.cs
Last active April 30, 2024 18:17
Exposes some Unity URP graphics settings that are (for some stupid fucking bullshit reason) private.
using System.Reflection;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using ShadowResolution = UnityEngine.Rendering.Universal.ShadowResolution;
/// <summary>
/// Enables getting/setting URP graphics settings properties that don't have built-in getters and setters.
global.THREE = require("three");
const canvasSketch = require('canvas-sketch');
const Random = require('canvas-sketch-util/random');
const gradientHeight = 512;
const settings = {
dimensions: [ 2048, gradientHeight * 2 ]
};
using UnityEngine;
public class MeshBlit : MonoBehaviour
{
public RenderTexture rt;
public Mesh mesh;
public Material material;
public Vector3 meshPosition = new Vector3(0.5f, 0.5f, -1);
@bugshake
bugshake / SortedGizmos.cs
Created September 28, 2018 12:27
Depth sorted Gizmos in the Unity Editor
using System;
using System.Collections.Generic;
using UnityEngine;
public static class SortedGizmos
{
static List<ICommand> commands = new List<ICommand>(1000);
public static Color color { get; set; }
@LotteMakesStuff
LotteMakesStuff / NativeMeshTest.cs
Created August 8, 2018 00:30
[NativeCollections] How to copy a regular .C# array into a NativeArray suuuuuper quick using memcpy. its about as fast as its ever gunna get!
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Mathematics;
using UnityEngine;
public class NativeMeshTest : MonoBehaviour
{
private NativeArray<float3> vertexBuffer;
private Vector3[] vertexArray;
@addie-lombardo
addie-lombardo / CustomInspectorCreator.cs
Last active April 9, 2022 07:34 — forked from LotteMakesStuff/CustomInspectorCreator.cs
Editor extension that adds a tool to automagically generate boilerplate custom inspector code~ YES! Just drop it into a folder called 'Editor' and it adds a 'custom inspector' option into the Project window!
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
/// <summary>
/// Generates a boilerplate custom inspector script for Monobehaviours and populates it with its serialized fields.
// threshold for mask can be controlled using vertex color alpha (useful for spriteRenderers or particle systems)
// _MainTex: alpha of this texture is used as a mask
// _EmissionTex: usually rgb noise texture, adjust it's scaling if needed
// color remap and oscilation for each channel of emission can be modified in _EmStrobeBFALR, _EmStrobeBFALG, _EmStrobeBFALB
// Base: base amplitude of brightness oscilation
// Freq: frequency of oscilation
// Ampl: amplitude of oscilation
// L: how much _EmissionTex affects this color
Shader "StandardWMask" {