Skip to content

Instantly share code, notes, and snippets.

@tcantenot
tcantenot / hploc.slang
Created June 30, 2026 16:11 — forked from natevm/hploc.slang
An implementation of "H-PLOC Hierarchical Parallel Locally-Ordered Clustering for Bounding Volume Hierarchy Construction".
// MIT License
// Copyright (c) 2024 Nathan V. Morrical
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@tcantenot
tcantenot / gob.h
Created June 2, 2026 13:24 — forked from pervognsen/gob.h
gob.h
// My investigations on the C standard compliance of Gob and related techniques:
// https://gist.github.com/pervognsen/5249a405fe7d76ded1cf08ed50fa9176
#pragma once
#include <stdint.h>
#pragma pack(push, 8)
#if __cplusplus >= 201103L || (__cplusplus && _MSC_VER >= 1900)

Multi-dimensional array views for systems programmers

As C programmers, most of us think of pointer arithmetic for multi-dimensional arrays in a nested way:

The address for a 1-dimensional array is base + x. The address for a 2-dimensional array is base + x + y*x_size for row-major layout and base + y + x*y_size for column-major layout. The address for a 3-dimensional array is base + x + (y + z*y_size)*x_size for row-column-major layout. And so on.

@tcantenot
tcantenot / spherical_frustum_grid.md
Created February 12, 2026 10:29
Short description of a spherically distorted frustum grid. Authored with Claude Code, so some inconsistencies and oversights might have slipped through.

Spherically Distorted Frustum Grid

This document describes a variant of the frustum grid that uses spherical depth shells instead of planar depth slices, while retaining the standard perspective lateral coordinates.

Planar Grid Overview

The planar frustum grid uses a piecewise depth distribution. Key parameters:

  • κ = 2·tan(θ/2)/N — pixel cone slope (θ = FOV, N = pixels along one axis)
  • s — voxel size (world-space units)
@tcantenot
tcantenot / main.c
Last active September 12, 2025 12:05
Precise sleep function on Windows written in C using high resolution timers
#include "precise_sleep.h"
int main()
{
const int use_nt_set_timer_resolution = 1;
InitPreciseSleepFunction(use_nt_set_timer_resolution);
// Your app code that uses PreciseSleep(sleep_duration_s);
DeinitPreciseSleepFunction();
@tcantenot
tcantenot / exponentially_space_set.cpp
Last active May 30, 2025 08:50
Exponentially spaced set
// Based on: https://x.com/ptrschmdtnlsn/status/1840765584398840233
#include <stdint.h>
#include <stdio.h>
#include <string.h>
constexpr uint32_t N = 7;
constexpr uint32_t M = 1u << N;
constexpr uint32_t MaxNumStates = 6;
@tcantenot
tcantenot / tri.c
Created November 23, 2024 10:49 — forked from cshenton/tri.c
Seeing how fast a d3d11 swapchain can go.
#include <assert.h>
#include <stdio.h>
#include <time.h>
#define COBJMACROS
#include <windows.h>
#include <d3d11_1.h>
#include <d3dcompiler.h>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
@tcantenot
tcantenot / main.c
Created March 7, 2024 09:31 — forked from mattiasgustavsson/main.c
Minimal code example for creating a window to plot pixels to
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <windows.h>
#pragma comment( lib, "user32.lib" )
#pragma comment( lib, "gdi32.lib" )
#define SCRW 640
#define SCRH 480

From time to time I receive questions on the depth aware upsampling mentioned in the INSIDE-rendering presentation: https://loopit.dk/rendering_inside.pdf#page=39

noisy blur

The goal of this technique is to take the texture-output from a half-resolution pass, containing the results of sampling volumetric fog - and scale it up to full resolution. This presents two challenges:

  • Making sure samples from the low-resolution buffer, do not spill on top of foreground objects in the high-resolution buffer
  • Making sure the samples in the volumetric fog can be properly accumulated by TAA after upsampling

Core Coding Standard

Coding practices are a source of a lot of arguments among programmers. Coding standards, to some degree, help us to put certain questions to bed and resolve stylistic debates. No coding standard makes everyone happy. (And even their existence is sure to make some unhappy.) What follows are the standards we put together on the Core team, which have become the general coding standard for all programming teams on new code development. We’ve tried to balance the need for creating a common, recognizable and readable code base with not unduly burdening the programmer with minor code formatting concerns.

Table Of Contents