Skip to content

Instantly share code, notes, and snippets.

View dwilliamson's full-sized avatar

Don Williamson dwilliamson

View GitHub Profile
@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.
//
// 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 / winmain.c
Created February 11, 2018 14:49
Old K-Libs game engine snippet
/*
===============================================================================================
K-Libs, Kernel, WINMAIN.C
-------------------------------------
by Don Williamson, 1999
===============================================================================================
*/
#include <windows.h>
#include "types.h"
@dwilliamson
dwilliamson / Example.cpp
Last active May 10, 2021 09:09
Static/compile-time reflection with JSON serialisation. Uses https://github.com/dropbox/json11
#include "Reflection.h"
#include <string>
#include <vector>
namespace mks
{
struct Rect
{
int top;
@dwilliamson
dwilliamson / Test.cpp
Created February 5, 2018 13:55
C++11 string-to-type
#include <stdio.h>
int main()
{
using T = TYPE_STRING("helo");
printf("%s\n", T::string);
}
@dwilliamson
dwilliamson / Reflection.h
Created February 3, 2018 23:20
Basic compile-time reflection for C++11
#pragma once
#include <typestring/typestring.hh>
namespace rfl
{
// Compile-time data member description
@dwilliamson
dwilliamson / ParallelogramTriangle.cpp
Created January 29, 2018 22:00
Swept ray test for character->world ledge hang intersection checks
// | = dot product, ^ = cross product. Please forgive my younger self for his sins.
void UpdateMinMax(float value, float& min, float& max)
{
if (value < min)
min = value;
else if (value > max)
max = value;
}
@dwilliamson
dwilliamson / BuildSystem.txt
Created January 20, 2018 18:57
Build System doc
Assuming we're talking about asset builds and to an
extent, the final build itself the best working
solution I've implemented in the past was based on
SCons. Sorry for the verbosity but it's lunch time and
I'm bored :)
My reasons for choosing it were simple:
- It's Python. Very easy to understand and change. The
language itself allows you to perform non-trivial
tasks such as parse an XML tree.
- I wanted to share the responsibility of maintainence
@dwilliamson
dwilliamson / Description.md
Last active December 8, 2017 17:50
Compile-time Shader Assembly for DX8

In the olden DX8 days a common technique was to compile shaders at runtime using assembly instructions in strings. You would composite sections of pre-written shader based on how many lights were active, what type of material you were lighting and any other properties that would affect rendering.

This had two problems, in order of effect:

  1. You'd have to pass the assembly code onto the DX8 runtime which would then parse and compile it.
  2. You're doing a whole bunch of string concatenations everywhere. With dynamic register allocation, that means sprintf calls.

The reason runtime compilation was common was that precompiling all combinations offline was prohibitive as the total count would be in the 10s of thousands.

Anyway, I was never happy with the performance of compiling shaders at runtime; there'd be noticable hitching as the game would spend upwards of 100ms compiling. There were imperfect ways of stepping around the issue, like precompiling all shaders on specific offline camera paths, but you'd st

@dwilliamson
dwilliamson / Silly.cpp
Created August 22, 2017 22:17
MSVC (multiple versions past) can NRVO this copy out of existence
#include <stdio.h>
#include <stdint.h>
#include <cstdlib>
// Dumbest array type possible with lots of copying and rubbish code
// Note absence of generated copy constructor calls for the array or its items
template <typename Type>
struct Array
{
Array()