Skip to content

Instantly share code, notes, and snippets.

@troughton
troughton / MetalStateCaches.swift
Last active April 7, 2023 01:42
MetalStateCaches for concurrency debugging
//
// Caches.swift
// MetalRenderer
//
// Created by Thomas Roughton on 24/12/17.
//
#if canImport(Metal)
@preconcurrency import Metal
@troughton
troughton / DebugDraw Shader Code
Created September 24, 2022 22:54
DebugDraw.hlsl
struct DebugVertex {
float3 position : POSITION;
float4 colour : COLOR;
};
struct DebugVertexUniforms {
float4x4 worldToProjection;
};
[[vk::push_constant]] DebugVertexUniforms uniforms;
@troughton
troughton / DebugDraw.swift
Created September 24, 2022 22:52
DebugDraw
import SubstrateMath
import SubstrateUtilities
public final class DebugDraw {
public struct DrawStyle {
public static let defaultStyle : DrawStyle = DrawStyle(colour: RGBAColour(1), depthEnabled: false, wireframe: false)
public var colour : RGBAColour
public var depthEnabled : Bool
@troughton
troughton / DebugDrawPass.swift
Created September 24, 2022 22:50
DebugDraw
import Substrate
import SubstrateMath
import DebugDraw
import SubstrateUtilities
import ShaderReflection
final class DebugDrawPass : ReflectableDrawRenderPass {
public typealias Reflection = DebugDrawPassReflection
@troughton
troughton / ExtrudeAlongCurve.py
Created March 9, 2017 06:40
Maya script to extrude along a curve.
import maya.cmds as cmds
import math
import numpy
def basisToEuler(tangent, bitangent, normal):
#Adapted from http://www.staff.city.ac.uk/~sbbh653/publications/euler.pdf
m = [tangent, bitangent, normal]
if abs(m[2][0]) != 1:
theta = -math.asin(m[2][0])
@troughton
troughton / AmbientDice.cpp
Last active April 23, 2020 14:32
Ambient Dice
struct Vertex {
vec3 value;
vec3 directionalDerivativeU;
vec3 directionalDerivativeV;
};
void AmbientDice::hybridCubicBezierWeights(u32 i0, u32 i1, u32 i2, float b0, float b1, float b2, VertexWeights *w0Out, VertexWeights *w1Out, VertexWeights *w2Out) const {
const float alpha = 0.5f * sqrt(0.5f * (5.0f + sqrt(5.0f))); // 0.9510565163
const float beta = -0.5f * sqrt(0.1f * (5.0f + sqrt(5.0f))); // -0.4253254042
Computer Information:
Manufacturer: Apple
Model: iMacPro1,1
Form Factor: Desktop
No Touch Input Detected
Processor Information:
CPU Vendor: GenuineIntel
CPU Brand: Intel(R) Xeon(R) W-2150B CPU @ 3.00GHz
CPU Family: 0x6
@troughton
troughton / swift-windows-crosscompile-instrs.md
Last active April 5, 2019 15:15
Swift Cross-Compilation on Windows 10

Cross-compiling Swift for Windows through the Linux Subsystem for Windows

This tutorial will walk you through the process of compiling your own native programs for Windows using the Ubuntu on Windows. While the development environment and Swift compiler used here will be the standard toolchain for Linux, you'll also be able to cross-compile programs that run natively on Windows like any other executable.

Required Environment

This tutorial assumes a computer running an up-to-date 64-bit version of Windows 10 (at the time of writing, the Fall Creators' Update was the most recent build).

You'll also need Visual Studio 2017; the Community Edition is sufficient, since we'll only be using the SDKs that come with it and some command line tools.

@troughton
troughton / main.swift
Last active November 30, 2018 11:17
Swift Tromino Algorithm - Windows Test
import Swift
print("Hello")
struct Position : Hashable {
let x : Int
let y : Int
var hashValue: Int {
return 31 &* x &+ y
@troughton
troughton / .purview_helper.js
Last active October 24, 2016 23:52 — forked from dribnet/gist:a0ef81cf281d53066ebb2416c1cae3b4
MDDN 342 Final Project
// note: this file is poorly named - it can generally be ignored.
// helper functions below for supporting blocks/purview
function saveBlocksImages(doZoom) {
if(doZoom == null) {
doZoom = false;
}
// generate 960x500 preview.jpg of entire canvas