Skip to content

Instantly share code, notes, and snippets.

@jdupuy
jdupuy / SampleVndf_GGX.cpp
Last active April 15, 2024 20:09
Sampling Visible GGX Normals with Spherical Caps
// Helper function: sample the visible hemisphere from a spherical cap
vec3 SampleVndf_Hemisphere(vec2 u, vec3 wi)
{
// sample a spherical cap in (-wi.z, 1]
float phi = 2.0f * M_PI * u.x;
float z = fma((1.0f - u.y), (1.0f + wi.z), -wi.z);
float sinTheta = sqrt(clamp(1.0f - z * z, 0.0f, 1.0f));
float x = sinTheta * cos(phi);
float y = sinTheta * sin(phi);
vec3 c = vec3(x, y, z);
@flibitijibibo
flibitijibibo / glon12.md
Last active April 17, 2024 16:52
GLon12 Instructions
@dwilliamson
dwilliamson / ModifiedMarchingCubes.js
Created February 8, 2022 16:20
Transvoxel's Modified Marching Cubes Lookup Tables
//
// Lookup Tables for Transvoxel's Modified Marching Cubes
//
// Unlike the original paper (Marching Cubes: A High Resolution 3D Surface Construction Algorithm), these tables guarantee
// a closed mesh "whose connected components are continuous and free of holes."
//
// Rotations are prioritised over inversions so that 3 of the 6 cases containing ambiguous faces are never added. 3 extra
// cases are added as a post-process, overriding inverses through custom-build rotations to eliminate the rest.
//
// Uses the exact same co-ordinate system as https://gist.github.com/dwilliamson/c041e3454a713e58baf6e4f8e5fffecd
@Henje
Henje / papers_please_fix.cpp
Last active February 28, 2023 23:10
Simple hack to disable joystick scanning and remove stutters from Papers Please.
#include <string>
#include <dlfcn.h>
#include <stdio.h>
#include <sys/mman.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
using namespace std::literals;
@JarkkoPFC
JarkkoPFC / morton.h
Created September 30, 2021 06:19
Faster 16/32bit 2D Morton Code encode/decode functions
uint16_t encode16_morton2(uint8_t x_, uint8_t y_)
{
uint32_t res=x_|(uint32_t(y_)<<16);
res=(res|(res<<4))&0x0f0f0f0f;
res=(res|(res<<2))&0x33333333;
res=(res|(res<<1))&0x55555555;
return uint16_t(res|(res>>15));
}
//----
@KelSolaar
KelSolaar / cornell_box_to_sRGB.py
Last active October 23, 2021 14:19
Cornell Box to sRGB
import numpy as np
import colour
D = np.array([
[400, 0.343, 0.092, 0.040],
[404, 0.445, 0.096, 0.046],
[408, 0.551, 0.098, 0.048],
[412, 0.624, 0.097, 0.053],
[416, 0.665, 0.098, 0.049],
[420, 0.687, 0.095, 0.050],
@mikhailov-work
mikhailov-work / turbo_colormap.c
Created August 15, 2019 23:04
Turbo Colormap Look-up Table
// Copyright 2019 Google LLC.
// SPDX-License-Identifier: Apache-2.0
// Author: Anton Mikhailov
// The look-up tables contains 256 entries. Each entry is a an sRGB triplet.
float turbo_srgb_floats[256][3] = {{0.18995,0.07176,0.23217},{0.19483,0.08339,0.26149},{0.19956,0.09498,0.29024},{0.20415,0.10652,0.31844},{0.20860,0.11802,0.34607},{0.21291,0.12947,0.37314},{0.21708,0.14087,0.39964},{0.22111,0.15223,0.42558},{0.22500,0.16354,0.45096},{0.22875,0.17481,0.47578},{0.23236,0.18603,0.50004},{0.23582,0.19720,0.52373},{0.23915,0.20833,0.54686},{0.24234,0.21941,0.56942},{0.24539,0.23044,0.59142},{0.24830,0.24143,0.61286},{0.25107,0.25237,0.63374},{0.25369,0.26327,0.65406},{0.25618,0.27412,0.67381},{0.25853,0.28492,0.69300},{0.26074,0.29568,0.71162},{0.26280,0.30639,0.72968},{0.26473,0.31706,0.74718},{0.26652,0.32768,0.76412},{0.26816,0.33825,0.78050},{0.26967,0.34878,0.79631},{0.27103,0.35926,0.81156},{0.27226,0.36970,0.82624},{0.27334,0.38008,0.84037},{0.27429,0.39043,0.85393},{0.27509,0.40072,0.86692},{0.2757
@rygorous
rygorous / gist:2156668
Last active April 16, 2024 11:18
float->half variants
// float->half variants.
// by Fabian "ryg" Giesen.
//
// I hereby place this code in the public domain, as per the terms of the
// CC0 license:
//
// https://creativecommons.org/publicdomain/zero/1.0/
//
// float_to_half_full: This is basically the ISPC stdlib code, except
// I preserve the sign of NaNs (any good reason not to?)