Skip to content

Instantly share code, notes, and snippets.

View madmann91's full-sized avatar

Arsène Pérard-Gayot madmann91

View GitHub Profile
@madmann91
madmann91 / spherical_tri.py
Created June 29, 2021 13:57
Spherical triangle sampling according to [Arvo 95]
#!/bin/env python3
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt
import math
def vnorm(v):
return v / np.linalg.norm(v)
def draw_unit_sphere(ax):
@madmann91
madmann91 / gen_primes.c
Created September 20, 2021 09:32
Prime number generator for hash tables
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
static bool is_prime(size_t i) {
if (i <= 1)
return false;
if (i <= 3)
return true;
if (i % 3 == 0 || i % 2 == 0)
@madmann91
madmann91 / dx.cpp
Created February 15, 2022 21:32
Automatic differentiation
#include <cmath>
#include <iostream>
template <typename T>
struct dFloat {
T x, dx;
dFloat(T x, T dx = 0) : x(x), dx(dx) {}
};
template <typename T>
@madmann91
madmann91 / bvh.glsl
Last active June 22, 2022 22:03
Basic BVH traversal with early exit & traversal order optimizations
#version 440
#define STACK_SIZE 32
#define INVALID_HIT_ID uint(-1)
// The primitive data be changed to the desired primitive type
// (including using BVHs as primitives for top-level BVH traversal).
#define PrimitiveData Triangle
#define HitData vec2 // Barycentric coordinates of a hit on a triangle (can be changed to anything)
#define intersect_ray_primitive(ray, prim, hit, tnear, tfar) \
@madmann91
madmann91 / poly.c
Last active May 15, 2024 13:06
Solver for quartic and cubic polynomials
#include <stdio.h>
#include <tgmath.h>
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
#include <string.h>
#define PI 3.141592653589793f
#define SEARCH_RADIUS 1.e-5f // Initial search radius for the local search procedure
@madmann91
madmann91 / hilbert3d.c
Created May 18, 2024 09:52
Hilbert curve in 3D
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <inttypes.h>
#include <assert.h>
enum dim : uint8_t {
X, Y, Z, DIM_COUNT
};