Skip to content

Instantly share code, notes, and snippets.

@mateuszwojt
mateuszwojt / disney_brdf.glsl
Created August 13, 2019 01:51
Disney Principled BRDF GLSL shader implementation
// Principled PBR Path tracer. Except where otherwise noted:
// Copyright © 2019 Markus Moenig Distributed under The MIT License.
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
@Themaister
Themaister / Setup.md
Last active January 10, 2019 20:32
Android Gradle basic setup for Vulkan

settings.gradle

include ':android' // Will pull in android/ folder as a subproject. I think you need this file even if you only have one project.

build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
@Erkaman
Erkaman / taa.frag
Last active August 10, 2025 02:11
rudimentary temporal anti-aliasing solution, that is good as a starting point for more advanced TAA techniques.
/*
The MIT License (MIT)
Copyright (c) 2018 Eric Arnebäck
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@vurtun
vurtun / _GJK.md
Last active October 13, 2025 01:37
3D Gilbert–Johnson–Keerthi (GJK) distance algorithm

Gilbert–Johnson–Keerthi (GJK) 3D distance algorithm

The Gilbert–Johnson–Keerthi (GJK) distance algorithm is a method of determining the minimum distance between two convex sets. The algorithm's stability, speed which operates in near-constant time, and small storage footprint make it popular for realtime collision detection.

Unlike many other distance algorithms, it has no requirments on geometry data to be stored in any specific format, but instead relies solely on a support function to iteratively generate closer simplices to the correct answer using the Minkowski sum (CSO) of two convex shapes.

@vurtun
vurtun / col.md
Last active September 26, 2025 08:22

screen0 screen1

@romainguy
romainguy / sh.glsl
Last active April 22, 2024 10:36
Spherical Harmonics lighting
// Uniform array of 4 vec3 for SH environment lighting
// Computed from "Ditch River" (http://www.hdrlabs.com/sibl/archive.html)
static const vec3 sphericalHarmonics[4] = {
{ 0.754554516862612, 0.748542953903366, 0.790921515418539 },
{ -0.083856548007422, 0.092533500963210, 0.322764661032516 },
{ 0.308152705331738, 0.366796330467391, 0.466698181299906 },
{ -0.188884931542396, -0.277402551592231, -0.377844212327557 }
};
// Fragment shader, "n" is the normal at the shading point
@Flix01
Flix01 / edtaa3func.h
Last active May 26, 2024 19:21
A Signed Distance Font Builder for Dear ImGui
/*
* edtaa3()
*
* Sweep-and-update Euclidean distance transform of an
* image. Positive pixels are treated as object pixels,
* zero or negative pixels are treated as background.
* An attempt is made to treat antialiased edges correctly.
* The input image must have pixels in the range [0,1],
* and the antialiased image should be a box-filter
* sampling of the ideal, crisp edge.
@TheRealMJP
TheRealMJP / Tex2DCatmullRom.hlsl
Last active August 23, 2025 09:05
An HLSL function for sampling a 2D texture with Catmull-Rom filtering, using 9 texture samples instead of 16
// The following code is licensed under the MIT license: https://gist.github.com/TheRealMJP/bc503b0b87b643d3505d41eab8b332ae
// Samples a texture with Catmull-Rom filtering, using 9 texture fetches instead of 16.
// See http://vec3.ca/bicubic-filtering-in-fewer-taps/ for more details
float4 SampleTextureCatmullRom(in Texture2D<float4> tex, in SamplerState linearSampler, in float2 uv, in float2 texSize)
{
// We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding
// down the sample location to get the exact center of our "starting" texel. The starting texel will be at
// location [1, 1] in the grid, where [0, 0] is the top left corner.
float2 samplePos = uv * texSize;
static void
Quat_FromEulerXYZ(float *euler_quat, float x, float y, float z)
{
float sx = (float)sin((double)(x * 0.5f));
float sy = (float)sin((double)(y * 0.5f));
float sz = (float)sin((double)(z * 0.5f));
float cx = (float)cos((double)(x * 0.5f));
float cy = (float)cos((double)(y * 0.5f));
float cz = (float)cos((double)(z * 0.5f));
@vicrucann
vicrucann / bezier.frag
Last active February 24, 2024 23:00
GLSL shader that allows to draw smooth and thick Bezier lines in 3D; added fog effect; using OpenSceneGraph for visualization
#version 330
in VertexData{
vec4 mColor;
} VertexIn;
void main(void)
{
gl_FragColor = VertexIn.mColor;
}