Skip to content

Instantly share code, notes, and snippets.

using UnityEngine;
using UnityEditor;
using System.Reflection;
using Type = System.Type;
public class InlineCurveEditor
{
private object curveEditor;
private Type curveType;
#name emoji
#subs default
#hidden nsfw
#class add emoji
> +1 #0x1f44d
> -1 #0x1f44e
> 100 #0x1f4af
> 1234 #0x1f522
> 8ball #0x1f3b1
@Polkm
Polkm / minal_pico8_raytracer.lua
Last active April 9, 2019 03:23
A minimal implementation of a distance field ray marching in pico 8. Has color dithering and soft shadows.
--math
local function length(x, y, z) return sqrt(x*x + y*y + z*z) end
local function norm(x, y, z) local l = length(x,y,z) return x/l, y/l, z/l end
local function dot(xa, ya, za, xb, yb, zb) return xa*xb + ya*yb + za*zb end
--globals
local ex, ey, ez = 0, 1, -1.5 --camera position
local fov = 90 --camera FOV
local tmin, tmax = .1, 100 --minimum and maximum distance from camera
local maxSteps = 45 --maximum number of steps to take
shadowMapShader = require('shadowMapShader')
lightShader = require('lightShader')
light = {x = 256, y = 256, size = 512}
local g = love.graphics
function love.load()
love.window.setMode(512, 512)
Wwidth, Wheight = love.window.getDimensions()
Xcenter, Ycenter = Wwidth/2, Wheight/2
extern number testDepth;
extern Image depthMap;
vec4 effect(vec4 color, Image texture, vec2 tc, vec2 sc) {
sc = sc / vec2(1024, 512); // Size of my canvas
sc.y = 1 - sc.y; // Flip the y axis
vec4 d = Texel(depthMap, sc);
// If the sprite's depth is less than the static depth map then hide it
if (testDepth < d.r * 256 + d.g * 256 * 256) {
local function deafultSort(a, b) return a > b end
function table.insertSort(tbl, func)
func = func or deafultSort
local len = #tbl
for j = 2, len do
local key, i = tbl[j], j - 1
while i > 0 and not func(tbl[i], key) do
tbl[i + 1] = tbl[i]
i = i - 1
end
-- So shaders in love only are applied to drawables, which means you can apply
-- diffrent shaders to diffrent sprites, which is nice. Although if you want to
-- apply a shader to a whole scene at once, for example a bloom shader, then you
-- will have to draw all your sprites to a canvas or image, and then draw that
-- composite with the shader.
-- Creates a shader with the given vertex and fragment shader source code. I'll
-- explain that in more detail later. You want to be caching this shader somewhere
-- because it's expensive to create.
@Polkm
Polkm / gist:bddba73c33e55bc3191e
Created April 20, 2015 05:33
Null propagation operator for Nim
template `?.`(a, b): expr =
if a != nil: a.b else: nil
template `??`(a, b): expr =
if a != nil: a else: b