Skip to content

Instantly share code, notes, and snippets.

View pema99's full-sized avatar

Pema Malling pema99

View GitHub Profile
@pema99
pema99 / AnisotropicFilteringMipSelection.hlsl
Created May 9, 2025 18:48
Mipmap level selection accounting for anisotropic filtering.
void EllipsoidTransformDerivatives(inout float2 dx, inout float2 dy)
{
bool anyZero = length(dx) == 0 || length(dy) == 0;
bool parallel = (dx.x * dy.y - dx.y * dy.x) == 0;
bool perpendicular = dot(dx, dy) == 0;
bool nonFinite = isinf(dx) || isinf(dy) || isnan(dx) || isnan(dy);
if (!anyZero && !parallel && !perpendicular && !nonFinite)
{
float A = dx.y*dx.y + dy.y*dy.y;
float B = -2.0 * (dx.x * dx.y + dy.x * dy.y);
@pema99
pema99 / CompareMipSelection
Created May 9, 2025 19:28
Compares SW and HW mipmap selection
Shader "Unlit/CompareMipSelection"
{
Properties
{
_MainTex ("Main color texture", 2D) = "white" {}
_MipTexture ("Texture with different color mips", 2D) = "white" {}
_AnisoLevel ("Aniso Level (must set manually to match texture)", Range(0, 16)) = 0
[ToggleUI] _VisualizeMipLevels ("Visualize Mip Levels", Integer) = 0
}
SubShader