Skip to content

Instantly share code, notes, and snippets.

@darktable
darktable / WorldNormalFromDepthTexture.shader
Created November 11, 2023 18:00 — forked from bgolus/WorldNormalFromDepthTexture.shader
Different methods for getting World Normal from Depth Texture, without any external script dependencies.
Shader "WorldNormalFromDepthTexture"
{
Properties {
[KeywordEnum(3 Tap, 4 Tap, Improved, Accurate)] _ReconstructionMethod ("Normal Reconstruction Method", Float) = 0
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
LOD 100
@darktable
darktable / SpatialHash.cs
Last active August 29, 2023 13:43
Spatial hash implementation for Unity.
// The contents of this file is free and unencumbered software released into the
// public domain. For more information, please refer to <http://unlicense.org/>
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.Assertions;
public class SpatialHash<T>
@darktable
darktable / Loggers.cs
Created July 31, 2023 01:47 — forked from thygrrr/Loggers.cs
A zero-boilerplate static logger for Unity in 25 lines of code
//SPDX-License-Identifier: Unlicense OR CC0-1.0+
using System;
using System.Collections.Generic;
using UnityEngine;
using Object = UnityEngine.Object;
// ReSharper disable MemberCanBePrivate.Global
namespace Loggers
{
/// <summary>
@darktable
darktable / GenerateSceneLoaderMenu.cs
Created July 17, 2023 13:23
Utility script to generate a menu items to load the scenes included in build settings.
// The contents of this file is free and unencumbered software released into the
// public domain. For more information, please refer to <http://unlicense.org/>
using System;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
@darktable
darktable / DrawingColor.cs
Created July 8, 2023 01:12
A static class you can use in Unity to access all the predefined colors in Microsoft's System.Drawing.Color.
using UnityEngine;
/// <summary>
/// Microsoft has a ton of predefined colors in System.Drawing.Color
/// </summary>
public static class DrawingColor
{
// only Unity color not represented (Unity's "green" is Microsoft's "Lime")
public static readonly Color Clear = Color.clear;
@darktable
darktable / EventManager.cs
Created April 11, 2023 15:04
EventManager script found in the Unity's FPS Micro Game sample. Useful for global event broadcasting.
using System;
using System.Collections.Generic;
namespace Unity.FPS.Game
{
public interface IBroadcastEvent { }
// A simple Event System that can be used for remote systems communication
public static class EventManager
{
@darktable
darktable / ServiceLocator.cs
Created April 11, 2023 15:02
Service locator pattern with callback system derived from EventManager script found in Unity FPS Microgame.
/*****************************************************************************
MIT License
Copyright (c) 2023 Calvin Rien
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
@darktable
darktable / DoomGlow.cs
Created June 20, 2022 11:53 — forked from TiliSleepStealer/DoomGlow.cs
Doom glow - fake volumetric light glow effect in Unity by Tili_us
// This file is in the public domain. Where
// a public domain declaration is not recognized, you are granted
// a license to freely use, modify, and redistribute this file in
// any way you choose.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Unity remake of a fake volumetric light glow effect
@darktable
darktable / UnityGetNativeAndroidVersion
Created March 4, 2022 22:03 — forked from kibotu/UnityGetNativeAndroidVersion
Get versionCode and versionName with unity.
//int vesioncode = context().getPackageManager().getPackageInfo(context().getPackageName(), 0).versionCode;
public static int GetVersionCode() {
AndroidJavaClass contextCls = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject context = contextCls.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject packageMngr = context.Call<AndroidJavaObject>("getPackageManager");
string packageName = context.Call<string>("getPackageName");
AndroidJavaObject packageInfo = packageMngr.Call<AndroidJavaObject>("getPackageInfo", packageName, 0);
return packageInfo.Get<int>("versionCode");
}
@darktable
darktable / MaterialGradientDrawer.cs
Created October 20, 2021 17:44 — forked from totallyRonja/MaterialGradientDrawer.cs
A Material Property Drawer for the [Gradient] attribute which lets you edit gradients and adds them to the shader as textures. More information here: https://twitter.com/totallyRonja/status/1368704187580682240
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
public class MaterialGradientDrawer : MaterialPropertyDrawer {
private int resolution;