Skip to content

Instantly share code, notes, and snippets.

@ruby0x1
ruby0x1 / tilt.shift.glsl
Last active February 19, 2024 02:46
Tilt shift shader, modified from something @grapefrukt gave me
// Modified version of a tilt shift shader from Martin Jonasson (http://grapefrukt.com/)
// Read http://notes.underscorediscovery.com/ for context on shaders and this file
// License : MIT
uniform sampler2D tex0;
varying vec2 tcoord;
varying vec4 color;
/*
Take note that blurring in a single pass (the two for loops below) is more expensive than separating
@ruby0x1
ruby0x1 / hash_fnv1a.h
Last active December 30, 2023 00:40
FNV1a c++11 constexpr compile time hash functions, 32 and 64 bit
#pragma once
#include <stdint.h>
//fnv1a 32 and 64 bit hash functions
// key is the data to hash, len is the size of the data (or how much of it to hash against)
// code license: public domain or equivalent
// post: https://notes.underscorediscovery.com/constexpr-fnv1a/
inline const uint32_t hash_32_fnv1a(const void* key, const uint32_t len) {
@ruby0x1
ruby0x1 / haxe-unzip-example.hx
Created June 7, 2014 19:36
Unzip a file with haxe - example
public static function unzip( _path:String, _dest:String, ignoreRootFolder:String = "" ) {
var _in_file = sys.io.File.read( _path );
var _entries = haxe.zip.Reader.readZip( _in_file );
_in_file.close();
for(_entry in _entries) {
var fileName = _entry.fileName;
@ruby0x1
ruby0x1 / PSXDither.hlsl
Created September 1, 2021 22:09 — forked from ompuco/PSXDither.hlsl
Color dither & truncation based on Sony's PlayStation (1) hardware features & limitations.
#ifdef PSXDTH
#else
#define PSXDTH
//PS1 Hardware Dithering & Color Precision Truncation Function
//by ompu co | Sam Blye (c) 2020
//PS1 dither table from PSYDEV SDK documentation
@ruby0x1
ruby0x1 / msdf.glsl
Last active February 13, 2022 05:30
simple MSDF shader
float r = sample.r;
float g = sample.g;
float b = sample.b;
float median = max(min(r, g), min(max(r, g), b));
float signed_dist = median - 0.5;
float d = fwidth(signed_dist);
float opacity = smoothstep(-d, d, signed_dist);
//apply opacity to final alpha
color.a *= opacity;
@ruby0x1
ruby0x1 / multi-player-html5-games-01-socket.io-server.js
Created March 27, 2012 14:59
Multi-player games in HTML5 : Setting up Socket.io on the server side
//Create and listen for clients on the existing web server
//we created above. app is the express server.
var io = require('socket.io').listen( app );
//We also introduce a UUID library, for unique identifiers.
//Not required, but I find useful.
var UUID = require('node-uuid');
/* Socket.io Configuration */
@ruby0x1
ruby0x1 / multi-player-html5-games-02-socket.io-client.html
Created March 27, 2012 14:58
Multi-player games in HTML5 : Client Side Socket.io
<!DOCTYPE html>
<html>
<head>
<title> Real time multi-player games with HTML5</title>
<style type="text/css">
html , body {
@ruby0x1
ruby0x1 / Runner.hx
Last active December 29, 2021 20:44
A simple Haxe class for easily running threads and calling functions on the primary thread.
package;
#if cpp
import cpp.vm.Thread;
import cpp.vm.Deque;
#elseif neko
import neko.vm.Thread;
import neko.vm.Deque;
#end
@ruby0x1
ruby0x1 / opt_fsr.fxh
Created August 26, 2021 08:29 — forked from atyuwen/opt_fsr.fxh
An optimized AMD FSR implementation for Mobiles
//==============================================================================================================================
// An optimized AMD FSR's EASU implementation for Mobiles
// Based on https://github.com/GPUOpen-Effects/FidelityFX-FSR/blob/master/ffx-fsr/ffx_fsr1.h
// -- FsrEasuSampleH should be implemented by calling shader, like following:
// half3 FsrEasuSampleH(float2 p) { return MyTex.SampleLevel(LinearSampler, p, 0).xyz; }
//==============================================================================================================================
void FsrEasuL(
out AH3 pix,
AF2 ip,
AF4 con0,
@ruby0x1
ruby0x1 / stb.c
Created February 24, 2021 17:55 — forked from urraka/stb.c
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#define STBI_ONLY_PNG
#define STBI_ONLY_JPEG
#define STBI_ONLY_BMP
#define STBI_ONLY_GIF
#include "stb_image.h"
#include "stb_image_write.h"