Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
‏‏‎

mika unitycoder

‏‏‎
View GitHub Profile
@ryan-at-melcher
ryan-at-melcher / FixAssetMainObjectNames.cs
Last active November 26, 2025 10:01
Automated/batch solution to fix "Main Object Name '{0}' does not match filename '{1}'" in Unity assets
using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.PackageManager;
using PackageInfo = UnityEditor.PackageManager.PackageInfo;
/// <summary>
/// Adds a menu command to find and fix all assets that have mismatched main
/// object names and file names. I.e., "Main Object Name '{0}' does not match
@Birch-san
Birch-san / separated_matmul.py
Created January 19, 2023 23:07
Matrix multiplication, by computing mantissae and exponents separately
# suppose we want to matmul some matrix against some column vector..
# the usual way is this:
mat = np.array([[1.3e2, 8.e2], [1.6e1, 5.e-1]])
vec = np.array([2.1e2, 3.6e-4])
mat @ vec
array([27300.288 , 3360.00018])
# but what if we wanted to exploit some efficiencies..
# - addition can use less cycles / energy / silicon / time than multiplication
# - for machine learning training: we want to represent a wide range of exponents, but don't need such range on the mantissa
@sketchpunk
sketchpunk / FetchBatch.js
Last active April 4, 2024 02:16
Various Fetch / Downloading functions or Objects
function nanoID( t=21 ){
const r = crypto.getRandomValues( new Uint8Array( t ) );
let n, e = '';
for( ;t--; ){
n = 63 & r[ t ];
e += ( n < 36 )? n.toString( 36 ) :
( n < 62 )? ( n - 26 ).toString( 36 ).toUpperCase() :
( n < 63 )? '_' : '-';
}
return e;
@kurtdekker
kurtdekker / HeadNodYesSensor.cs
Last active July 16, 2024 15:25
Head shake no and nod yes gesture detector
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// @kurtdekker - head nod yes sensor
//
// To use:
// Put this on a mouse-controlled FPS camera and it can detect:
// - up/down "head nods yes."
// Optionally give it an audio to play
@NegInfinity
NegInfinity / GlobeVisualizer.cs
Created July 26, 2022 17:46
Spherical Worlds in Unity Tests - subdivision of sphere into tetrahedra, cube and adjusted cube
/*
#License:
MIT. Copyrigh 2022 Victor "NegInfinity" Eremin.
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
furnished to do so, subject to the following conditions:
@nilpunch
nilpunch / BlurImage.shader
Last active April 25, 2025 16:47
Blur for UI elements. Compatible with Built in RP, HDRP, URP and SRP.
Shader "UI/BlurImage"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[Space(50)]
_BlurX ("X Blur", Range(0.0, 0.5)) = 0.001
_BlurY ("Y Blur", Range(0.0, 0.5)) = 0.001
@h3r2tic
h3r2tic / kajiya-all-the-jiggarays.md
Last active May 22, 2022 00:22
kajiya ray count breakdown

There are two types of rays being traced: shadow and "gbuffer". The latter return gbuffer-style information from hit points, and don't recursively launch more rays. Lighting is done in a deferred way. There is just one light: the sun.

  • irradiance cache: usually fewer than 16k cache entries:

    • main trace: 4/entry * (1 gbuffer ray + 1 shadow ray for the sun)
    • restir validation trace: 4/entry * (1 gbuffer ray + 1 shadow ray for the sun)
    • accessibility check: 16/entry short shadow rays
  • sun shadow pass: 1/pixel shadow ray

  • final gather done at half-res; every third frame is a ReSTIR validation frame, and instead of tracing new candidates, it checks the old ones, and updates their radiance. in addition to that, the validation frame also traces very short contact rays; on paper it seems like it would be doing more work, but it's actually slightly cheaper, so I'm counting conservatively here:

@AlexMerzlikin
AlexMerzlikin / UniversalRenderPipelineTemplateWithDotsInstancing.shader
Last active May 28, 2025 08:10
Template unlit URP shader that supports DOTS instancing to use as a guide to create shaders for BatchRendererGroup since BRG only works with DOTS instancing compatible shaders. Unfortunately, the official docs about it haven't helped me that much, and I thought others might face the same issues.
Shader "Universal Render Pipeline/Custom/UnlitWithDotsInstancing"
{
Properties
{
_BaseMap ("Base Texture", 2D) = "white" {}
_BaseColor ("Base Colour", Color) = (1, 1, 1, 1)
}
SubShader
{
@scho
scho / UiToolkitBindingExtensions.cs
Last active July 17, 2025 15:05
UI Toolkit Reactive Binding Extensions using UniRx
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using JetBrains.Annotations;
using ProjectHive.Core.Util.UniRx;
using UniRx;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.Video;
@marcotmp
marcotmp / UnityGMail.cs
Last active August 28, 2025 10:04
Code to send email from unity using a Google account.
using System.ComponentModel;
using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public class UnityGMail
{
public void SendMailFromGoogle()
{