Skip to content

Instantly share code, notes, and snippets.

@gradbot
gradbot / ReplaceZeros.hlsl
Last active September 28, 2020 17:04
Algorithm to replace zeros with previous non zero value
// This algorithm replaces zeros with whatever number came before them in an array.
// This code assumes the total data size (c_dataSize) is a multiple of 1024 the modern thread group size limit.
// It's an exercise for the reader to support odd lengths. :)
// What should the behavior be if the very first element in the sequence starts with zero?
// Set lastValue initial value to determine that behavior.
RWTexture2D<float> data;
@gradbot
gradbot / InitRandomHeap.h
Last active March 20, 2020 03:29
Overloads global new with random data for help with finding uninitialized data use.
#include <chrono>
struct XorShift128State
{
uint32_t a, b, c, d;
};
/* The state array must be initialized to not be all zero */
uint32_t xorshift128(XorShift128State *state)
{
@gradbot
gradbot / AlignedAllocator.h
Last active January 17, 2020 21:49
Simple aligned allocator for use with std::vector and DirectXMath in Visual Studio 2013.
#include <memory>
#include <vector>
struct XMVECTOR
{
float x, y, z, w;
};
template <typename T, unsigned int Alignment = 16>
class AlignedAllocator : public std::allocator<T>
@gradbot
gradbot / atan2.as
Created February 6, 2012 04:26
atan2(y, x) in AGAL using atan(x) = Pi / 2 * x / (1 + x)
context3D.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, Vector.<Number>([
1,
0,
Math.PI,
2 * Math.PI,
1e-10,
Math.PI / 2,
0, // not used
0, // not used
@gradbot
gradbot / Directory Monitor Execute.cpp
Created January 17, 2012 00:19
Monitor a directory and call SyncToy if something changes.
// This requires Windows XP or newer.
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
unsigned int flags = FILE_NOTIFY_CHANGE_LAST_WRITE |
FILE_NOTIFY_CHANGE_SIZE |
FILE_NOTIFY_CHANGE_DIR_NAME |
FILE_NOTIFY_CHANGE_FILE_NAME;