Skip to content

Instantly share code, notes, and snippets.

@natevm
natevm / utils.slang
Created June 18, 2025 02:02
Little utility slang file containing SDF functions, intersectors, and other useful geometric tools collected from a variety of resources. Useful for creating procedural shaders.
// The MIT License
// Copyright © 2025 Nate 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SO
@natevm
natevm / hploc.slang
Last active June 20, 2025 09:54
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:
@natevm
natevm / helperMath.h
Created December 3, 2021 20:05
CUDA Math Helper Functions
#pragma once
#include <iostream>
#include <cuda_runtime.h>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#ifndef __CUDACC__
using namespace std;
@natevm
natevm / pseudoangle.h
Created October 11, 2017 21:37
Pseudo-angle method
// angle relative to the x axis.
inline float pseudoangle(float2 p1, float2 p2) {
float dx, dy, t;
dx = p2.x - p1.x;
dy = p2.y - p1.y;
if ((dx == 0.0) && (dy == 0.0)) {
return -1; // indicating error
}
else {
t = dy / (fabs(dx) + fabs(dy));