Skip to content

Instantly share code, notes, and snippets.

View MateSteinforth's full-sized avatar
🌴
On vacation

Mate Steinforth MateSteinforth

🌴
On vacation
View GitHub Profile
@MateSteinforth
MateSteinforth / StretchAndOrientByVelocity.vfxblock
Last active February 16, 2025 18:03
Orient and scale particles along velocity. adapted from https://github.com/robcupisz/flying-embers
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!2058629511 &1
VisualEffectResource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: StretchAndOrientByVelocity
m_Graph: {fileID: 114350483966674976}
@MateSteinforth
MateSteinforth / RoundedBox.sca
Last active March 16, 2024 19:38
Rounded Box Outline SDF in SparkSL
//==============================================================================
// Rounded Box Outline SDF
//==============================================================================
float roundedBoxSDF(vec2 CenterPosition, vec2 Size, float Radius)
{
return length(max(abs(CenterPosition)-Size+Radius,0.0))-Radius;
}
float roundBoxOutline(vec2 size, float thickness, float radius)
# taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/
# generate server.xml with the following command:
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
# run as follows:
# python simple-https-server.py
# then in your browser, visit:
# https://localhost:4443
import BaseHTTPServer, SimpleHTTPServer
import ssl
@MateSteinforth
MateSteinforth / Update.ts
Last active December 21, 2023 15:16
Spark Imperative Update Loop
import Time from 'Time';
/**
* The Update class manages subscriptions to snapshot items and provides an update method that can be overridden by subclasses.
*
* import Scene from 'Scene';
* import Update from './Update';
*
* class OtherClass extends Update {
* private _mySceneObject: Scene.SceneObjectBase = Scene.root.findFirstSync('plane0');
*
// Remember to put the script you choose inside a folder called Editor inside your Assets folder.
using UnityEditor;
public static class CompileBeforePlay
{
[InitializeOnLoadMethod]
public static void Initialize()
{
if (EditorApplication.isPlaying) return;
int numbers[10] = { 31599, 25751, 25255, 25230, 23241, 31118, 14826, 29257, 11242, 15306 };
//==============================================================================
// Shadow
//==============================================================================
#import <utils>
using namespace std;
vec4 main() { return vec4(vec3(0.0), smoothstep(0.5, 0.0, safeDistance(fragment(getVertexTexCoord()), vec2(0.5)))); }
//==============================================================================
// MatCap Shader
// via https://www.clicktorelease.com/code/spherical-normal-mapping/
//==============================================================================
using namespace std;
#import <utils>
export vec2 calculateNormal( optional<std::Texture2d> normalTex,
mat3 tangentFrame,
//==============================================================================
// Simple Displacement Shader
// make sure to add 'Vertex Texture Fetch' to Capabilities
//==============================================================================
void main(optional<std::Texture2d> displace, optional<std::Texture2d> tex, float depth, out vec4 Color, out vec4 Position) {
vec2 uv = std::getVertexTexCoord();
vec4 texturePos = displace.sampleLod(uv, 0.0).valueOr(vec4(1.0));
vec4 outPosition = std::getVertexPosition() + vec4(std::getVertexNormal()*texturePos.rgb*depth, 0.0);
Color = tex.sampleLod(fragment(uv), 0.0).valueOr(vec4(1.0));
function setup() {
createCanvas(256, 256);
}
function draw() {
for (let i = 0; i < width ; i++) {
for (let j = 0; j < height; j++) {
let c = color(i & j, i | j, i ^ j);
set(i, j, c);
}