Skip to content

Instantly share code, notes, and snippets.

View haxiomic's full-sized avatar

George Corney haxiomic

View GitHub Profile
@haxiomic
haxiomic / default.json
Created April 17, 2024 14:12
Powertoys Keyboard Manager Mac Shortcuts
{
"remapKeys": {
"inProcess": [
{
"originalKeys": "36",
"newRemapKeys": "260;37"
},
{
"originalKeys": "35",
"newRemapKeys": "260;39"
@haxiomic
haxiomic / TextureVisualizer.ts
Created November 9, 2023 20:23
Three.js TextureVisualizer Developer Tool
import { Blending, ColorRepresentation, DoubleSide, LinearFilter, LinearMipMapLinearFilter, MathUtils, Mesh, MeshBasicMaterial, Object3D, PlaneGeometry, RepeatWrapping, ShaderMaterial, Texture, Uniform, Vector2 } from "three";
export class TextureVisualizer extends Object3D {
texturePlanes = new Map<string, Mesh<PlaneGeometry, MeshBasicMaterial>>();
readonly gridWidth = 4;
constructor() {
super();
// this.layers.set(Layer.Developer);
@haxiomic
haxiomic / WebGLLogger.ts
Last active November 9, 2023 20:22
Log all WebGL calls, print constant names
export function WebGLLogger(gl: WebGL2RenderingContext, filter: Array<string | RegExp> | null = null) {
let constantNameMap = new Map<number, string>();
// enumerate gl
for (let key in gl) {
let value = (gl as any)[key];
if (typeof value === 'number' && key.toUpperCase() === key) {
constantNameMap.set(value, key);
continue;
}
@haxiomic
haxiomic / shader-library.glsl
Created September 28, 2023 00:45
Shader Library: frequently used shader functions
/**
First order approximation of acos()
See https://seblagarde.wordpress.com/2014/12/01/inverse-trigonometric-functions-gpu-optimization-for-amd-gcn-architecture/
**/
float acosPoly1(float inX) {
float x = abs(inX);
float res = -0.156583 * x + 1.570796;
res *= sqrt(1.0 - x);
return (inX >= 0.0) ? res : (3.141593 - res);
}
// https://www.shadertoy.com/view/dlfXDN
// 2023 myth0genesis
// 4D Simplex Noise Gradient
// I saw that Stefan Gustavson didn't seem to have published any shader
// with an analytic solution for the gradients of his variant
// of 4D simplex noise, so I thought I'd try solving it myself
// and publish it here for anyone who finds it useful.
// Compares the analytic solution to the numerically approximated one (for a sanity check)
// and shows the results of all four derivatives with respect to each dimension.
// Top : Analytic gradient | Bottom: Forward differences approximated gradient
@haxiomic
haxiomic / ObjectPool.hx
Last active September 21, 2023 12:48
Structure of Array and Array of Structures in Haxe
/**
* ObjectPool is a type building macro to create array-of-structure or structure-of-array pools.
* With the intention being to improve access performance, both in CPU cache coherence and by avoiding the GC
*
* This implementation is a minimal working proof of concept
*
* Improvements you may want to make
* - Support deallocation of instances and space reclaiming
* - Replace haxe.io.Bytes because field access has overhead
*

Tide visualization

What you know about tides is wrong It could be super cool and interesting to see this in 3D https://twitter.com/mayfer/status/1633601289505632257

Interactive electromagnetism simulation

Thiiiisss but to demonstrate how the waves can be used for sending signals – (i.e. wiggle electron here, see others wiggle = radio :D), and all sorts of other EM intuition related to relativity (which admittedly I don't have enough of yet...)

Talked with plasma fusion physicist friend at JET and he had the same lack of intuition and 🤯 reaction so I feel validated at least

@haxiomic
haxiomic / shader-editor.js
Last active March 23, 2023 20:50
BodgeShaderEditor. Many of the WebGL shader editor tooling out there is broken or doesn't support WebGL2 and interesting setups like wasm. I created this bodge in a few hours to help solve an issue. See comments for usage. Feel free to do what you like with the code (please build a real shader editor <3)
/**
* BodgeShaderEditor
*
* Many of the WebGL shader editor tooling out there is broken or doesn't support WebGL2 and interesting setups like wasm.
* I created this bodge in a few hours to help solve an issue
*
* @author haxiomic
*/
// replace getContext with our own function
@haxiomic
haxiomic / Partial.hx
Last active February 26, 2023 11:44
Haxe macro to make all fields of a type optional (similar to Typescript's Partial<T>)
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.TypeTools;
#if !macro
@:genericBuild(PartialMacro.build())
#end
class Partial<T> {}
class PartialMacro {
@haxiomic
haxiomic / StructView.hx
Last active October 16, 2022 17:43
Macro to generated structured field access to a raw byte array
/**
* StructView – Typed access of a byte buffer
*
* Example:
* ```
* typedef MessageView = StructView<{
* a: Int,
* b: Float,
* sub: {
* c: StructView.UInt8,