Skip to content

Instantly share code, notes, and snippets.

View mandarinx's full-sized avatar

Thomas Viktil mandarinx

View GitHub Profile
@mandarinx
mandarinx / Volumetric.shader
Created June 19, 2018 08:41
Faux volumetric lighting
Shader "Phigames/Volumetric" {
Properties {
_MainTex ("Particle Texture", 2D) = "white" {}
[HDR]_C("Tint Color", Color) = (1,1,1,1)
_InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.5
_RP ("Rim Fade Power", Range(0.1, 8)) = 8
_AM ("Alpha Multiplier", Range(0,3)) = 1
_P("Fall Off Power", Range(0,10)) = 1
_FO ("Fall Off", Range(0, 10)) = 10
}
@mandarinx
mandarinx / Workbook.cs
Last active October 22, 2022 00:04
Quantize color channels
public static int Quantize(float value, int bits) {
return (int)(value * (Math.Pow(2, bits) - 1));
}
public static int JoinColors(int maskWidth, params int[] colors) {
int joined = colors[0];
for (int i=1; i<colors.Length; ++i) {
joined = JoinColor(joined, colors[i], i, maskWidth);
}
return joined;
@mandarinx
mandarinx / PICO-8.colors
Last active October 22, 2022 00:05
Unity3D PICO-8 palette
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &1
MonoBehaviour:
m_ObjectHideFlags: 52
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 1
@mandarinx
mandarinx / README.md
Last active October 4, 2021 11:19
Monospaced console log in Unity3D

Displaying the console log in Unity3D using a monospaced font

I'm on macOS and haven't tried this on Windows. I'm sure it's equally easy to achieve on Windows.

Open Terminal.app and type tail -f ~/Library/Logs/Unity/Editor.log to output the entire editor log to the terminal.

Optionally, you can use grep to filter out certain lines using a regular expression as filter. In this example, I only want the lines that starts with "[MEM]": tail -f ~/Library/Logs/Unity/Editor.log | grep --line-buffered '^\[MEM\]'.

Logging with a monospaced font enables you to output tables and prettify your logs with spaces and tabs, like this:

@mandarinx
mandarinx / Unity_NewerThan2017_1.cs
Last active November 5, 2022 16:49
Unity3D: Detect when play mode changes to what
// For Unity versions newer than 2017.1
using UnityEditor;
[InitializeOnLoad]
public class DetectPlayModeChanges {
static DetectPlayModeChanges() {
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
}
@mandarinx
mandarinx / Evaporating.shader
Created February 28, 2018 08:34
Evaporating shader
Shader "Custom/Evaporating"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_Color("Color", Color) = (1, 1, 1, 1)
_GradientTex("Gradient Texture", 2D) = "white" {}
_GradientThreshold("Gradient Threshold", float) = 0.5
_NoiseTex("Noise Texture", 2D) = "white" {}
_UVOffset("UV Offset", vector) = (1, 1, 1, 1)
@mandarinx
mandarinx / GameEvent.cs
Created February 21, 2018 13:44
Game Events as ScriptableObjects
using System;
using System.Collections.Generic;
using UnityEngine;
namespace GameEvents {
[CreateAssetMenu(menuName = "Game Events/GameEvent")]
public class GameEvent : ScriptableObject {
private readonly List<GameEventListener> eventListeners = new List<GameEventListener>();
@mandarinx
mandarinx / notes.md
Last active July 19, 2023 14:08
altitude fog shader

Copied from https://jakobknudsen.wordpress.com/2013/08/06/altitude-fog/ for archival purpose.

When you submerge an object in water you expect it to become more and more obscured as it sinks further into the depths. As far as I can see, this is usually accomplished in Unity3D with a fullscreen image-effect like the global fog standard asset. But that only works in the pro-version of Unity, and I want something that works in the free version. This post shows my solution.

In Unity3D, you can implement your own custom fog on a material by writing your own final color function in a custom shader. The final color function is applied after any lightning has been applied, so we wont have light­sources brightening up objects that are supposed to be hidden. The incredibly useful Surface Shader Examples page in the Unity documentation includes an example titled “Custom Fog with Final Color Modifier”, where a custom finalcolor function is used to apply fog based on the vertical position of the pixel in screenspace. Thi

@mandarinx
mandarinx / ChromeKey.shader
Created December 12, 2017 15:05
Chroma key shader
// Shader created with Shader Forge v1.38
// Shader Forge (c) Neat Corporation / Joachim Holmer - http://www.acegikmo.com/shaderforge/
// Note: Manually altering this data may prevent you from opening it in Shader Forge
/*SF_DATA;ver:1.38;sub:START;pass:START;ps:flbk:,iptp:1,cusa:True,bamd:0,cgin:,lico:1,lgpr:1,limd:0,spmd:1,trmd:0,grmd:0,uamb:True,mssp:True,bkdf:False,hqlp:False,rprd:False,enco:False,rmgx:True,imps:True,rpth:0,vtps:0,hqsc:True,nrmq:1,nrsp:0,vomd:0,spxs:True,tesm:0,olmd:1,culm:2,bsrc:3,bdst:7,dpts:2,wrdp:False,dith:0,atcv:False,rfrpo:True,rfrpn:Refraction,coma:15,ufog:False,aust:True,igpj:True,qofs:0,qpre:3,rntp:2,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.5,fgcg:0.5,fgcb:0.5,fgca:1,fgde:0.01,fgrn:0,fgrf:300,stcl:True,atwp:True,stva:128,stmr:255,stmw:255,stcp:6,stps:0,stfa:0,stfz:0,ofsf:0,ofsu:0,f2p0:False,fnsp:False,fnfb:False,fsmp:False;n:type:ShaderForge.SFN_Final,id:1873,x:35436,y:32424,varname:node_1873,prsc:2|emission-1286-OUT,alpha-1659-OUT;n:type:ShaderForge.SFN_Tex2d,
@mandarinx
mandarinx / MaskedSprite.shader
Created October 15, 2017 18:17
Masked sprite shader
Shader "Unlit/maskedSprite"
{
Properties
{
[Toggle]_ShowMask ("Preview mask", Float) = 0
[Space]
[Toggle]_UseAlpha ("Vertex Alpha > Threshold", Float) = 0
[Space]
_MaskThrs ("Mask Threshold", Range(0,1)) = .5
_MaskSoft ("Mask Width", Range (0.001, 3)) = 1