Skip to content

Instantly share code, notes, and snippets.

@Shell64
Shell64 / TableToXML.lua
Created October 14, 2015 22:10
Convert Lua Table to XML
--(c)2015 Leandro T. Fonseca
local Str = ""
local function TableToXML_(Tab, Key2, Depth, Attributes2)
for Key, Value in Pairs(Tab) do
if Type(Key) == "string" and Type(Value) == "table" then
if Key ~= "_attr" then
if Value[1] then
local Attributes = ""
@Shell64
Shell64 / gist:a430485c5a380613a75c
Created October 18, 2015 14:22
Fresnel for reflections
F = F0 + (max(vec3(1.0 - alpha), F0) - F0) * pow((1.0 - clamp(dot(ViewDirection, Half), 0.0, 1.0)), 5);
@Shell64
Shell64 / gist:5d12f50b4a0cabc08900
Last active October 18, 2015 16:01
Geometric Shadowing term G (Schilik using UE4 roughness)
// Geometric Shadowing term G (Schilik using UE4 roughness)
float k = alpha / 2.0;
float GL = dotNL / (dotNL * (1.0 - k) + k);
float GV = dotNV / (dotNV * (1.0 - k) + k);
float G = GV * GL;
@Shell64
Shell64 / gist:3f7e8308c2499bc43e25
Created October 22, 2015 05:49
LuaWebserver2 simple POST example
function Application.POST(Information, Content)
if Information.Parameter == "MyFuncName" then
return '{"d": "1"}', 200
else
return '{"d": "0"}', 200
end
end
@Shell64
Shell64 / gist:6a5e7d904633e5958efd
Last active November 2, 2015 11:25
Daltonism shader for LOVE
uniform float colorblind_mode = 0.0;
const mat3 protanopia = mat3(0.567, 0.433, 0 , 0.558, 0.442, 0 , 0 , 0.242 ,0.758);
const mat3 protanomaly = mat3(0.817, 0.183, 0 , 0.333, 0.667, 0 , 0 , 0.125 ,0.875);
const mat3 deuteranopia = mat3(0.625, 0.375, 0 , 0.7 , 0.3 , 0 , 0 , 0.3 ,0.7 );
const mat3 deuteranomaly = mat3(0.8 , 0.2 , 0 , 0.258, 0.742, 0 , 0 , 0.142 ,0.858);
const mat3 tritanopia = mat3(0.95 , 0.05 , 0 , 0 , 0.433, 0.567, 0 , 0.475 ,0.525);
const mat3 tritanomaly = mat3(0.967, 0.033, 0 , 0 , 0.733, 0.267, 0 , 0.183 ,0.817);
const mat3 achromatopsia = mat3(0.299, 0.587, 0.114, 0.299, 0.587, 0.114, 0.299, 0.587 ,0.114);
const mat3 achromatomaly = mat3(0.618, 0.320, 0.062, 0.163, 0.775, 0.062, 0.163, 0.320 ,0.516);
@Shell64
Shell64 / stencil.lua
Created November 4, 2015 22:06
love 0.10.0 stencil API abstraction (like 0.9.2) for my engine.
local CurrentStencil = nil
function Graphics.SetStencil(Stencil)
if Stencil then
Graphics.SetStencilTest(true, false)
Graphics.Stencil(Stencil, false)
CurrentStencil = Stencil
else
CurrentStencil = nil
/*
This software is in the public domain. Where that dedication is not recognized,
you are granted a perpetual, irrevokable license to copy and modify this file
as you see fit.
*/
float GetDepth(sampler2D tex_heightmap, vec2 UV ) {
return texture2D(tex_heightmap, UV).r;
}
//Image.cpp:136
throw love::Exception("Image cannot have mipmaps: compressed image data does not have all required mipmap levels.");
//Should be upgraded to:
throw love::Exception("Image cannot have mipmaps: compressed image data does not have all required mipmap levels (expected %d, got %d)", getMipmapCount(width, height), compresseddata[0]->getMipmapCount());
@Shell64
Shell64 / ssr.c
Created April 8, 2017 21:04
SSR Render Loop
for(int Count = 0; Count < 160; Count++)
{
if(CurrentPosition.x < 0.0 || CurrentPosition.x > 1.0 ||
CurrentPosition.y < 0.0 || CurrentPosition.y > 1.0 ||
CurrentPosition.z < 0.0 || CurrentPosition.z > 1.0)
{
return vec4(0.0, 0.0, 0.0, 1.0);
}
//intersections
local MAXVCACHE = 32
local function CalculateScore(Object)
if #Object.Uses > 0 then
Object.Score = 2.0 * ((#Object.Uses) ^ -0.5)
if Object.CacheRank >= 3 then
Object.Score = Object.Score + ((1.0 - (Object.CacheRank - 3) / MAXVCACHE) ^ 1.5)
elseif Object.CacheRank >= 0 then
Object.Score = Object.Score + 0.75
end