Skip to content

Instantly share code, notes, and snippets.

@vertver
vertver / faithful_ntsc.fx
Last active September 10, 2026 19:41
Faithful NTSC HLSL filter
/***************************************************************************************
* Copyright (C) Anton Kovalev (vertver), 2026. All rights reserved.
* HLSL single-pass NTSC filter
* MIT License
***************************************************************************************
* shout out to LMP88959, which implemented an awesome NTSC emulation (fixed-point).
* https://github.com/LMP88959/NTSC-CRT
***************************************************************************************/
//Original: https://gist.github.com/vertver/670a85babb52f20ba6b5e08e5f02f08e
/*
* Thread-local cache for meshoptimizer allocations. Planned for inclusion into future meshoptimizer versions.
*
* Copyright (C) 2016-2025, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
* This code is distributed under the MIT License.
*/
// reconfigure thread cache for meshopt_ allocations for N threads x M bytes per thread
// can't be called concurrently with meshopt_ or clod functions
void clodUseThreadCache(size_t thread_count, size_t size_per_thread)
@Ipotrick
Ipotrick / Efficient GPU Work Expansion.md
Last active October 25, 2026 19:36
Efficient GPU Work Expansion

What is "Work Expansion"

In a GPU-driven renderer, "work expansion" is a commonly occurring problem. "Work Expansion" means that a single item of work spawns N following work items. Typically one work item will be executed by one shader thread/invocation.

An example for work expansion is gpu driven meshlet culling following mesh culling. In this example a "work item" is culling a mesh, where each mesh cull work item spawns N following meshlet cull work items.

There are many diverse cases of this problem and many solutions. Some are trivial to solve, for example, when N (how many work items are spawned) is fixed.

@Mugen87
Mugen87 / packing.js
Last active June 30, 2026 13:09
Packing/unpacking routines for RGB9E5 usage in WebGL/WebGPU.
// reference https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_shared_exponent.txt
const RGB9E5_MANTISSA_BITS = 9;
const RGB9E5_EXP_BIAS = 15;
const RGB9E5_MAX_VALID_BIASED_EXP = 31;
const MAX_RGB9E5_EXP = ( RGB9E5_MAX_VALID_BIASED_EXP - RGB9E5_EXP_BIAS );
const RGB9E5_MANTISSA_VALUES = ( 1 << RGB9E5_MANTISSA_BITS );
const MAX_RGB9E5_MANTISSA = ( RGB9E5_MANTISSA_VALUES - 1 );
const MAX_RGB9E5 = ( ( MAX_RGB9E5_MANTISSA ) / RGB9E5_MANTISSA_VALUES * ( 1 << MAX_RGB9E5_EXP ) );
@bazhenovc
bazhenovc / the_sane_rendering_manifesto.md
Last active October 26, 2026 16:50
The Sane Rendering Manifesto

The Sane Rendering Manifesto

The goal of this manifesto is to provide an easy to follow and reasonable rules that realtime and video game renderers can follow.

These rules highly prioritize image clarity/stability and pleasant gameplay experience over photorealism and excess graphics fidelity.

Keep in mind that shipping a game has priority over everything else and it is allowed to break the rules of the manifesto when there are no other good options in order to ship the game.

Do not use dynamic resolution.

Shader "Pristine Grid"
{
Properties
{
[KeywordEnum(MeshUV, WorldX, WorldY, WorldZ)] _UVMode ("UV Mode", Float) = 2.0
_GridScale ("Grid Scale", Float) = 1.0
_LineWidthX ("Line Width X", Range(0,1.0)) = 0.01
_LineWidthY ("Line Width Y", Range(0,1.0)) = 0.01
@futureengine2
futureengine2 / gi.c
Last active June 30, 2026 04:11
Radiance Cascades 2d GI implementation
static void gi_on_gpu(u8* in_bitmap, int w, int h) {
#define num_cascades 7
static bool initialized;
static gpu_bindgroup_t texture_bindgroup[2];
static gpu_bindgroup_t cascade_uniform_bindgroup[num_cascades];
static gpu_bindgroup_t render_uniform_bindgroup;
static gpu_buffer_t vertex_buffer;
static gpu_buffer_t uniform_buffer;
static gpu_pipeline_t pipeline;

code

@zeux
zeux / bounds-frag.glsl
Last active April 3, 2025 14:19
Shader code used in "Approximate projected bounds" article, used for profiling with offline cycle estimation tools.
#version 450
// 2D Polyhedral Bounds of a Clipped, Perspective-Projected 3D Sphere. Michael Mara, Morgan McGuire. 2013
bool projectSphereView(vec3 c, float r, float znear, float P00, float P11, out vec4 aabb)
{
if (c.z < r + znear) return false;
vec3 cr = c * r;
float czr2 = c.z * c.z - r * r;
@h3r2tic
h3r2tic / raymarch.hlsl
Last active October 31, 2026 01:22
Depth buffer raymarching for contact shadows, SSGI, SSR, etc.
// Copyright (c) 2023 Tomasz Stachowiak
//
// This contribution is dual licensed under EITHER OF
//
// Apache License, Version 2.0, (http://www.apache.org/licenses/LICENSE-2.0)
// MIT license (http://opensource.org/licenses/MIT)
//
// at your option.
#include "/inc/frame_constants.hlsl"