Skip to content

Instantly share code, notes, and snippets.

View haxiomic's full-sized avatar
:octocat:
Everything is happening

George Corney haxiomic

:octocat:
Everything is happening
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);
}
@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 / 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,
@haxiomic
haxiomic / ObjectPool.hx
Last active June 28, 2024 03:42
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
*
@haxiomic
haxiomic / show-errors.js
Created July 27, 2021 09:50
When you can't access the console, this script will display errors and warnings over the html (ensure this runs before your own code)
(() => {
let errorDisplayEl = document.createElement('div');
errorDisplayEl.classList.add('error-display');
errorDisplayEl.style.display = 'none';
errorDisplayEl.style.position = 'absolute';
errorDisplayEl.style.zIndex = '2000';
errorDisplayEl.style.backgroundColor = 'rgba(146, 0, 0, 0.6)';
errorDisplayEl.style.padding = '20px';
errorDisplayEl.style.fontFamily = 'monospace, sans-serif';
errorDisplayEl.style.color = '#fff5f5';

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

import * as THREE from 'three';
function glslFloat(f) {
let s = f + '';
if (s.indexOf('.') == -1) {
s += '.';
}
return s;
}