Skip to content

Instantly share code, notes, and snippets.

// read the PDF about this if you precompute it! it's got helpful info!
// can be optimized into lut (compute can gen it)
float GTTonemap(float x) {
float m = 0.22; // linear section start
float a = 1.0; // contrast
float c = 1.33; // black brightness
float P = 1.0; // maximum brightness
float l = 0.4; // linear section length
float l0 = ((P-m)*l) / a; // 0.312
@shakesoda
shakesoda / gc-simple.frag.glsl
Created February 24, 2021 06:05
simple per vertex shading example
#version 330
in vec2 uv;
in vec3 diffuse;
in vec3 specular;
in vec2 color_mixes; // x=diffuse mix, y=specular mix
out vec4 outColor;
uniform sampler2D texture0;
// cofactor matrix. drop-in replacement for the traditional transpose(inverse(m)) normal matrix calculation.
// this is a substantial performance improvement.
// short form found via shadertoy: https://www.shadertoy.com/view/3s33z
mat3 cofactor(mat4 m) {
return mat3(
cross(m[1].xyz, m[2].xyz),
cross(m[2].xyz, m[0].xyz),
cross(m[0].xyz, m[1].xyz)
);
}
@shakesoda
shakesoda / main.lua
Created January 9, 2018 04:41
flexible box layout prototype
local start_time = love.filesystem.getLastModified("main.lua")
function love.update(dt)
if (love.filesystem.getLastModified("main.lua") > start_time) then
love.event.quit("restart")
end
end
local function round(value, precision)
if precision then return round(value / precision) * precision end
@shakesoda
shakesoda / imgui_bgfx.cpp
Last active February 17, 2021 19:56
imgui for bgfx (works with unmodified imgui)
#include <imgui/imgui.h>
#include <SDL2/SDL_syswm.h>
#include "myon/imgui.hpp"
#include "myon/window.hpp"
#include "myon/timer.hpp"
#include "myon/cache.hpp"
#include "math/matrix.hpp"
#include <bgfx/bgfx.h>
#include <imgui/imgui_demo.cpp>
#include <imgui/imgui_lua_bindings.cpp>
@shakesoda
shakesoda / kaguya.hpp
Created April 27, 2017 05:23
slightly modified kaguya for lua 5.1 compat
#ifndef KAGUYA_LUABINDING_HPP_INCLUDED
#define KAGUYA_LUABINDING_HPP_INCLUDED
// Copyright satoren
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Copyright satoren
// Distributed under the Boost Software License, Version 1.0. (See
@shakesoda
shakesoda / pecs_lua.cpp
Created April 18, 2017 06:52
basic binding of PECS to lua, using kaguya.
#include <lua.hpp>
#include "kaguya.hpp"
#include "pecs.hpp"
using namespace pecs;
using namespace std;
enum {
// NB: component 0 can't be used.
COMPONENT_NONE = ~0,
@shakesoda
shakesoda / pecs_lua.cpp
Last active April 18, 2017 07:26
basic binding of PECS to lua, using kaguya.
#include <lua.hpp>
#include <cstdint>
#include <vector>
#include "kaguya.hpp"
#include "pecs.hpp"
using namespace std;
using namespace pecs;
#define GENERATE_COMPONENT(ENUM, TYPE, NAME) \
-- Basic ring buffer utility, to spare the hassle.
local ringbuffer = {}
local ringbuffer_mt = {}
local function new(_items)
local t = {
items = _items or {},
current = 1
}
return setmetatable(t, ringbuffer_mt)
--- ...snip...
if not headless then
require "love.system"
require "love.window"
end
local flags = {
width = 1280,
height = 720,
highdpi = true,