Skip to content

Instantly share code, notes, and snippets.

View dwilliamson's full-sized avatar

Don Williamson dwilliamson

View GitHub Profile
@dwilliamson
dwilliamson / MarchingCubes.js
Last active April 17, 2024 16:05
Marching Cubes Lookup Tables
//
// Lookup Tables for Marching Cubes
//
// These tables differ from the original paper (Marching Cubes: A High Resolution 3D Surface Construction Algorithm)
//
// The co-ordinate system has the more convenient properties:
//
// i = cube index [0, 7]
// x = (i & 1) >> 0
// y = (i & 2) >> 1
//
// TinyCRT, revamp and TinyWin support by Don Williamson, 2011
// Based on http://www.codeproject.com/KB/library/tlibc.aspx and LIBCTINY by Matt Pietrek
//
#pragma once
#ifdef USE_DEFAULT_CRT
@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
@dwilliamson
dwilliamson / Doc.md
Last active April 23, 2023 14:17
Minimal Code Generation for STL-like Containers

This is my little Christmas-break experiment trying to (among other things) reduce the amount of generated code for containers.

THIS CODE WILL CONTAIN BUGS AND IS ONLY PRESENTED AS AN EXAMPLE.

The C++ STL is still an undesirable library for many reasons I have extolled in the past. But it's also a good library. Demons lie in this here debate and I have no interest in revisiting it right now.

The goals that I have achieved with this approach are:

@dwilliamson
dwilliamson / Adjacency.cpp
Last active February 26, 2023 10:34
Simple, fast adjacency builder
struct Adjacency
{
struct Vertex
{
// Vertices are shared by a variable number of edges. This indexes the global EdgeRef array.
uint32_t edgeStartRef;
uint32_t nbEdges;
};
union EdgeRef
@dwilliamson
dwilliamson / shellmap.md
Created January 11, 2019 16:38
Shell Mapping

So the technique is called Shell Mapping and I got the basics from:

Interactive Smooth and Curved Shell Mapping
https://www.cg.tuwien.ac.at/research/publications/2007/JESCHKE-2007-ISC/

The technique as documented starts with Geometry Shaders which is a really bad idea so I kept things simple and did all the pre-processing on the CPU when meshes were imported. These days I'd look at doing it on-demand in a Compute Shader. Preprocessing steps are:

  1. Parameterise a heightmap for your mesh.
@dwilliamson
dwilliamson / MarchingCubesCaseGen.js
Created August 22, 2022 21:09
Marching Cubes Edge/Triangle LUT Generator
// Marching Cubes Edge/Triangle LUT Generator
// From Transvoxel paper http://transvoxel.org/Lengyel-VoxelTerrain.pdf
// We have ambiguous case when a cube has an ambiguous face
// An ambiguous face has two diagonally opposing corners that are inside and the other two are outside
// This can be tesellated two different ways and when you place this face up against another cube, can introduce holes
// In Lengyel's paper, his ambiguous cases are 2, 6, 7, 8, 9, and 10.
// These map to cases 3, 7, 8, 12, 10 and 13
// Key observation is that in MC ambiguous cases always arise due to the inclusion of the inverses
#pragma once
// This allows windows.h to be included first, overriding this header file, but be careful
// not to do this everywhere as compile-times suffer.
#ifndef _WINDOWS_
#define _WIN32_WINNT 0x0601 // _WIN32_WINNT_WIN7
@dwilliamson
dwilliamson / Text.md
Created December 22, 2021 21:35
Prince of Persia style Character Controller with no Level Markup

Documenting a tiny fraction of the Character Physics/Locomotion/Animation of Advent Shadow for PSP (2004).

The first thing I will say before I start this is; if you can get hold of a guy that can both code and animate stick them in the guts of the implementation and you'll get something that surpasses anything a paired programmer/animator can achieve. Have them responsible for implementing rough first-pass animations and writing the code that drives the animation engine. They might be responsible for final animations here and there, it really depends on your setup. However as far as the code goes, keep them purely on the gameplay side and away from the core technology - you don't want to over-burden them. If you have to use a separate programmer/animator, these guys have to be good. This is not easy stuff and both guys need to be artistic - if you have a programmer who looks at a bunch of moves to implement as a tasklist to be ticked off whenever something is in the game, that's not good enough. The sam

@dwilliamson
dwilliamson / vsync.txt
Created November 30, 2015 22:44
Windows vsync
VSync under Windows, revisited
http://www.virtualdub.org/blog/pivot/entry.php?id=157
Windowed mode, vsync stutter, DWM (Vista+)
http://armageddongames.net/showthread.php?96793-Windowed-mode-vsync-stutter-DWM-(Vista-)
DwmFlush function
https://msdn.microsoft.com/en-us/library/windows/desktop/dd389405(v=vs.85).aspx
Bug 856427 - Add vsync support on windows