Skip to content

Instantly share code, notes, and snippets.

View bean-mhm's full-sized avatar

Bean (Hadi Farid) bean-mhm

View GitHub Profile
@bean-mhm
bean-mhm / index.html
Last active June 26, 2025 12:23
HSV background color picker for Display P3 color space
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>HSV Display-P3 Background</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
html,
body {
@bean-mhm
bean-mhm / conv_kernel.py
Created January 21, 2025 21:18
High Pass Convolution Kernel for Blue Noise
# this script generates a high pass convolution kernel that we can apply on
# white noise to get something close to blue noise. check out the relevant
# shader in the link below.
# https://www.shadertoy.com/view/l3dBRf
import numpy as np
from scipy.signal import convolve2d
np.set_printoptions(precision=7, linewidth=80000, suppress=True)
import numpy as np
import scipy.signal
np.set_printoptions(precision=7, linewidth=80000, suppress=True)
# create NxN matrix (N must be a positive odd integer)
N = 11
k = np.zeros((N, N), dtype=np.float32)
# generate gaussian kernel
@bean-mhm
bean-mhm / npr.glsl
Last active October 10, 2024 13:55
Custom Non-Photorealistic Lighting Shader Function - https://youtu.be/7t1l0a_53tw
vec3 bean_non_photorealistic(
vec3 normal, // must be normalized
vec3 view_dir, // must be normalized
vec3 light_dir, // must be normalized
vec3 light_col,
vec3 albedo,
float roughness,
float metallic
)
{
@bean-mhm
bean-mhm / print_color_space_conversion_matrices.py
Created April 1, 2024 22:45
print color space conversion matrices
import numpy as np
# https://www.colour-science.org/
import colour
np.set_printoptions(precision=10, floatmode='fixed', suppress=True)
print(f'mat_bt2020_to_xyz:\n{colour.models.RGB_COLOURSPACE_BT2020.matrix_RGB_to_XYZ}\n')
print(f'mat_xyz_to_bt2020:\n{colour.models.RGB_COLOURSPACE_BT2020.matrix_XYZ_to_RGB}\n')
print(f'mat_bt709_to_xyz:\n{colour.models.RGB_COLOURSPACE_BT709.matrix_RGB_to_XYZ}\n')
print(f'mat_xyz_to_bt709:\n{colour.models.RGB_COLOURSPACE_BT709.matrix_XYZ_to_RGB}\n')
@bean-mhm
bean-mhm / int128.h
Last active January 10, 2024 06:23 — forked from kimwalisch/int128.h
A signed 128-bit integer type. Internally stores its data in Two's Complement within two unsigned 64-bit integer parts. Still needs more testing, but basic implementation is fairly complete.
// Original:
// https://gist.github.com/kimwalisch/c8c40c5505d1b2e2c9389b09ae48f306
// Fork:
// https://gist.github.com/bean-mhm/ff249cc45ed179b4ed59b9e1afd363f4
#pragma once
#include <cassert>
#include <cstdint>
@bean-mhm
bean-mhm / bt2020_to_bt709.py
Created October 28, 2023 19:23
Convert RGB Tristimulus from Linear BT.2020 to Linear BT.709 (Rec. 709)
import numpy as np
# https://www.colour-science.org/
import colour
mat_bt2020_to_xyz = colour.models.RGB_COLOURSPACE_BT2020.matrix_RGB_to_XYZ
mat_xyz_to_bt709 = colour.models.RGB_COLOURSPACE_BT709.matrix_XYZ_to_RGB
mat_bt2020_to_bt709 = np.matmul(
@bean-mhm
bean-mhm / screenshot_to_desktop.py
Created June 2, 2023 21:25
Save Screenshot Directly to Desktop with Hotkey (Windows-Only)
# python -m pip install --upgrade pywin32
# pip install pyautogui
import win32con, ctypes, ctypes.wintypes
import pyautogui
from datetime import datetime
# Your Windows username (to determine the desktop path)
windows_username = 'user'