Skip to content

Instantly share code, notes, and snippets.

View BeRo1985's full-sized avatar

Benjamin Rosseaux BeRo1985

View GitHub Profile
@BeRo1985
BeRo1985 / gfxapiwrappers.md
Last active January 9, 2024 12:58
GFX API wrappers
@BeRo1985
BeRo1985 / icosphere.glsl
Last active December 11, 2023 10:23
Recursion-free procedural GPU icosphere
// Code (C) by Benjamin 'BeRo' Rosseaux - zlib licensed
// ...
#extension GL_EXT_control_flow_attributes : enable
// ...
uint resolution = pushConstants.resolution;
uint squaredResolution = pushConstants.resolution * pushConstants.resolution;
@BeRo1985
BeRo1985 / better_spherified_cube_sphere.glsl
Last active December 7, 2023 08:47
Better GPU procedural generated Spherified Cube Sphere
// Code (C) by Benjamin 'BeRo' Rosseaux - zlib licensed
// Based on the ideas from Stephen Cameron's https://scaryreasoner.wordpress.com/2016/01/23/thoughts-on-tesselating-a-sphere/ blog post.
// ...
void getCubeSphereNormals(const in int face, in vec4 uv0011, out vec3 vectors[4]){
  const float deltaAngle = 1.5707963267948966; // radians(90.0);
  const float startAngle = 0.7853981633974483; // radians(45.0);
  const vec3 normals[6] = vec3[6](
@BeRo1985
BeRo1985 / octahedralmap_catmullrom.glsl
Created December 3, 2023 12:27
GLSL Octahedral Texture Mapping with Edge Mirroring and Catmull-Rom Interpolation
// GLSL Octahedral Texture Mapping with Edge Mirroring and Catmull-Rom Interpolation (by Benjamin 'BeRo' Rosseaux)
ivec2 wrapOctahedralTexelCoordinates(const in ivec2 texel, const in ivec2 texSize) {
ivec2 wrapped = ((texel % texSize) + texSize) % texSize;
return ((((abs(texel.x / texSize.x) + int(texel.x < 0)) ^ (abs(texel.y / texSize.y) + int(texel.y < 0))) & 1) != 0) ? (texSize - (wrapped + ivec2(1))) : wrapped;
}
vec4 textureCatmullRomCoefficents(const in float v){
float t = v, tt = t * t, ttt = tt * t;
return vec4((tt - (ttt * 0.5)) - (0.5 * t), ((ttt * 1.5) - (tt * 2.5)) + 1.0, ((tt * 2.0) - (ttt * 1.5)) + (t * 0.5), (ttt * 0.5) - (tt * 0.5));
@BeRo1985
BeRo1985 / octahedralmap.glsl
Last active December 3, 2023 05:01
GLSL Octahedral Texture Mapping with Edge Mirroring and Bilinear Interpolation
// GLSL Octahedral Texture Mapping with Edge Mirroring and Bilinear Interpolation (by Benjamin 'BeRo' Rosseaux)
ivec2 wrapOctahedralTexelCoordinates(const in ivec2 texel, const in ivec2 texSize) {
ivec2 wrapped = ((texel % texSize) + texSize) % texSize;
return ((((abs(texel.x / texSize.x) + int(texel.x < 0)) ^ (abs(texel.y / texSize.y) + int(texel.y < 0))) & 1) != 0) ? (texSize - (wrapped + ivec2(1))) : wrapped;
}
vec4 textureOctahedralMap(const in sampler2D tex, vec3 direction) {
direction = normalize(direction); // just for to make sure that it is normalized
vec2 uv = direction.xy / (abs(direction.x) + abs(direction.y) + abs(direction.z));
@BeRo1985
BeRo1985 / PasFastDateUtils.pas
Created October 11, 2023 07:40
PasFastDateUtils - fast date functions for FreePascal and Delphi
// Fast date functions for FreePascal and Delphi - Pascal implementation by Benjamin Rosseaux - benjamin@rosseaux.com - Public Domain
// Based on: https://www.youtube.com/watch?v=J9KijLyP-yg - Implementing Fast Calendar Algorithms: Speeding Date - Cassio Neri - C++ on Sea 2023
unit PasFastDateUtils;
{$ifdef fpc}
{$mode delphi}
{$endif}
interface
uses SysUtils,Math;
@BeRo1985
BeRo1985 / multisampled_font_sdf.glsl
Last active December 19, 2022 14:08
Multisampled SDF for text rendering (4x AA with single texture lookup, 16x with four lookups)
// Multisampled SDF for text rendering (4x AA with single texture lookup, 16x with four lookups)
// It is for SDF text rendering with 16x antialiasing with only four texture lookups, where an
// SDF texture texel in turn also has four individual SDF values in the RGBA color channels in
// a 4-Rook/RGSS sampling pattern.
// Copyright (C) 2022, Benjamin 'BeRo' Rosseaux - License: Unlicense ( http://unlicense.org/ )
const float SQRT_0_DOT_5 = sqrt(0.5);
#if FILLTYPE == FILLTYPE_ATLAS_TEXTURE
@BeRo1985
BeRo1985 / attach_vhd_at_startup_windows_10.md
Created November 11, 2022 23:47 — forked from ianfabs/attach_vhd_at_startup_windows_10.md
How to Automount VHD on windows 10

So here's a pretty neat thing, I use VHD's to organize the space on my computer. You can too!

  • Click Start

  • Type in the search bar "Disk par" =>

  • Click first result =>

  • In the program, click "Action" =>

@BeRo1985
BeRo1985 / MIDIEventIntervalSearch.pas
Created September 3, 2020 10:30
Interval-tree-less interval search on sorted array of linked MIDI events
procedure TEngineMIDIEventList.FindInterval(const aResultList:TEngineMIDIEventDynamicArrayList;const aFromTime,aToTime:TEngineTime);
var Lower,Upper,Mid,Index,StartIndex,MinIndex,MaxIndex,
EventFromIndex,EventToIndex,NextStartIndex,TryIndex:SizeInt;
Event,TemporaryEvent:TEngineMIDIEvent;
FromTime,NextFromTime,EventFromTime,EventToTime,
MinEventTime,MaxEventTime:TEngineTime;
DoAdd:boolean;
begin
if fCount>0 then begin
@BeRo1985
BeRo1985 / compute shader NVIDIA driver 347.09 WHQL slowdown bug
Last active April 11, 2020 04:38
SDSM compute shader NVIDIA driver 347.09 WHQL slowdown bug
With version 347.09 WHQL tooks my SDSM tighting compute shader whole 70 ms per frame instead with the old verson 344.75 under 1ms (circa 0.7ms) on my GTX970.
See sdsm_reduce_tighting.glsl here, the $-stuff is my own preprocessor.
I'ver tracked to the "((lLinearZ >= reduceDataPartitions[lPartitionIndex].x) && (lLinearZ <= reduceDataPartitions[lPartitionIndex].w))" (in sdsm_reduce_tighting.glsl) comparsion down, but really just the comparsion itself, because:
70ms per frame:
if((lLinearZ >= reduceDataPartitions[lPartitionIndex].x) && (lLinearZ <= reduceDataPartitions[lPartitionIndex].w)){
minBoundsSun[lPartitionIndex] = min(minBoundsSun[lPartitionIndex], lSunLightSpaceCoord.xyz);