Skip to content

Instantly share code, notes, and snippets.

View CodyJasonBennett's full-sized avatar

Cody Bennett CodyJasonBennett

View GitHub Profile
@wiseConst
wiseConst / 3_byte_tangent_frames.md
Last active June 17, 2025 05:59
3 BYTE TANGENT FRAMES + bitmask array for TBN sign. Doom Eternal 2020

3-Byte Tangent Frame Encoding (Doom Eternal 2020)

This method stores a full TBN frame using just 3 bytes per vertex (plus a bitfield), instead of the traditional 28 bytes (normal: vec3, tangent: vec4). It leverages octahedral encoding for normals and a rotation angle for tangent reconstruction.

Motivation

Storing both glm::vec3 normal and glm::vec4 tangent is costly. Since the bitangent can be reconstructed via a cross product, we only need:

  • A unit normal (encoded in 2 bytes)
  • An angle to rotate a base tangent around the normal (1 byte)
// Rounds up to the next nearest power-of-two value
static inline unsigned int pow2_ceil( unsigned int x ) {
#if defined( __clang__ ) || defined( __GNUC__ )
return 1 + ( ( x >= 2 ) * ( ( ( 1u << 31 ) >> ( __builtin_clz( ( x - 1 ) | 1 ) - 1 ) ) - 1 ) );
#elif defined( _MSC_VER ) && ( defined( _M_IX86 ) || defined( _M_X64 ) )
return ( 1u << 31 ) >> ( __lzcnt( ( x - 1 ) | ( x == 0 ) ) - 1 );
#elif defined( _MSC_VER ) && ( defined( _M_ARM ) || defined( _M_ARM64 ) )
return ( 1u << 31 ) >> ( __clz( ( x - 1 ) | ( x == 0 ) ) - 1 );
#else
--x; // if x is already pow2, we don't want the next pow2
@natevm
natevm / hploc.slang
Last active July 24, 2025 12:14
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:
@mattdesl
mattdesl / random.wgsl
Last active June 20, 2025 09:51
high quality deterministic PRNG in WebGPU & WGSL (xorshift128) - MIT licensed
// each pixel is assigned 4 random u32 values per frame
@group(0) @binding(1)
var<storage, read> rnd_state: array<u32>;
// the current state within this pixel
var<private> local_rnd_state:vec4u;
fn random_u32(state:ptr<private,vec4u>) -> u32 {
var st:vec4u = *state;
/* Algorithm "xor128" from p. 5 of Marsaglia, "Xorshift RNGs" */
import time
import math
import torch
import taichi as ti
import taichi.math as tm
import tinytex as ttex
from tinycio import fsio
@h3r2tic
h3r2tic / raymarch.hlsl
Last active September 13, 2025 21:53
Depth buffer raymarching for contact shadows, SSGI, SSR, etc.
// Copyright (c) 2023 Tomasz Stachowiak
//
// This contribution is dual licensed under EITHER OF
//
// Apache License, Version 2.0, (http://www.apache.org/licenses/LICENSE-2.0)
// MIT license (http://opensource.org/licenses/MIT)
//
// at your option.
#include "/inc/frame_constants.hlsl"
@sketchpunk
sketchpunk / arcball.js
Last active September 30, 2024 16:53
Maths for various camera movement ( Orbit, Arcball, FPS, Zoom, etc )
/** Using a faux sphere in screen space, determine the arc transform to orbit
* the camera around a target position. A continuous orientation will
* be provided for further calls.
*/
function arcBallTransform(
scrSize, // Screen size, vec2
scrPos0, // Starting mouse position, vec2
scrPos1, // Ending Mouse Positiong, vec2
rotOrientation, // Current arc orientation, quaternion
targetPos, // Position to orbit around
@mrdoob
mrdoob / index.html
Created April 23, 2021 15:15
11 years of Three.js
<html>
<head>
<style>
body {
margin: 0;
padding: 10px;
color: #ffffff;
background: #222222;
font-family: sans-serif;
font-size: 7px;
@Popov72
Popov72 / using_pix_with_canary.md
Last active April 12, 2025 19:25
Using PIX with Chrome

In PIX, Select Target Process => Launch Win32 and set the following 2 entries according to where Canary / Chrome is installed:

  • Path to executable: "C:\Users\alexis\AppData\Local\Google\Chrome SxS\Application\chrome.exe"
  • Working directory: "C:\Users\alexis\AppData\Local\Google\Chrome SxS\Application"
  • Command line arguments: --disable-gpu-sandbox --disable-direct-composition
    • You can add those arguments if you want to be able to see the disassembled shader code: --enable-dawn-features=emit_hlsl_debug_symbols,disable_symbol_renaming
  • Launch Suspended unchecked, Launch for GPU capture and Force D3D11On12 checked

Then click on "Launch".

Important: you should close all your Canary / Chrome windows/processes before clicking on the "Launch" button!

@patriciogonzalezvivo
patriciogonzalezvivo / SimpleCameraFollower.md
Last active September 19, 2021 19:20
Simple Camara Follow in OF
cam.setPosition( cam.getPosition()+(targetPos-cam.getPosition())*0.01 );
cam.lookAt(targetPos);