Skip to content

Instantly share code, notes, and snippets.

@lucasteles
lucasteles / Granblue.gdshader
Created May 13, 2025 23:04
Godot ArcSys Style Shader
// author: @ijiru_masu
shader_type spatial;
uniform float specularThreshold : hint_range(0,1) = 0.5;
uniform float lightThreshold : hint_range(0,1) = 0.1;
uniform sampler2D BASE: source_color;
uniform sampler2D SSS: source_color;
uniform sampler2D ILM;
uniform sampler2D DETAIL: source_color;
@lucasteles
lucasteles / PopCount.cs
Created April 5, 2025 14:23
Calculate span pop count
static class Mem
{
public static int PopCount<T>(in T[] values) where T : unmanaged => PopCount<T>(values.AsSpan());
public static int PopCount<T>(in ReadOnlySpan<T> values) where T : unmanaged
{
#pragma warning disable S907
var count = 0;
var bytes = MemoryMarshal.AsBytes(values);
ref var current = ref MemoryMarshal.GetReference(bytes);
@lucasteles
lucasteles / FpsCounter.cs
Created April 3, 2025 02:22
FPS Counter
using System.Diagnostics;
public sealed class FpsCounter
{
double currentFps;
long lastFrameTime;
const float SmoothFactor = 0.1f;
public FpsCounter() => Reset();
@lucasteles
lucasteles / Easing.cs
Created January 29, 2025 15:16
C# Easing Functions
public static class Easing
{
#pragma warning disable S1121
public static float Linear(float k) => k;
public static class Quadratic
{
public static float In(float k) => k * k;
public static float Out(float k) => k * (2f - k);
@lucasteles
lucasteles / Fixed.cs
Created January 25, 2025 23:13
Fixed point number
public readonly struct Fixed :
IEquatable<Fixed>,
IComparable<Fixed>,
IFormattable, IUtf8SpanFormattable,
IComparisonOperators<Fixed, Fixed, bool>,
IAdditionOperators<Fixed, Fixed, Fixed>,
ISubtractionOperators<Fixed, Fixed, Fixed>,
IIncrementOperators<Fixed>,
IDecrementOperators<Fixed>
{
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
Check(Foo.A | Foo.B | Foo.C, Foo.B);
Check(Foo.A | Foo.B, Foo.C);
Check(Foo.A | Foo.C, Foo.None);
Check(Foo.A | Foo.B | Foo.C, Foo.B | Foo.C);
Check(Foo.A | Foo.B | Foo.D, Foo.B | Foo.C);
@lucasteles
lucasteles / Program.cs
Last active October 29, 2024 20:01
Multi API Request Samples
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Threading;
using System.Threading.Channels;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Diagnostics;
@lucasteles
lucasteles / NativeMemoryManager.cs
Last active September 3, 2024 16:11
Unmanaged Array type
using System.Buffers;
using System.Runtime.CompilerServices;
// ReSharper disable ParameterHidesMember
sealed unsafe class NativeMemoryManager<T> : MemoryManager<T>
where T : unmanaged
{
byte* pointer;
@lucasteles
lucasteles / deferred.cs
Created September 3, 2024 15:07
Deferred execution sample
/// <summary>
/// Disposable static functions
/// </summary>
public static class Disposable
{
/// <inheritdoc />
/// <summary>
/// Create new deferred context
/// </summary>
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
SortedHashSet<int> values = [];
Console.WriteLine("Start");
OSZAR »