Skip to content

Instantly share code, notes, and snippets.

@bazhenovc
Created March 16, 2015 19:15
Show Gist options
  • Save bazhenovc/e53295d52e1f4372ca99 to your computer and use it in GitHub Desktop.
Save bazhenovc/e53295d52e1f4372ca99 to your computer and use it in GitHub Desktop.
float CalcMipLevel(float2 inUV)
{
float2 uv = inUV * kAtlasedTextureSize;
float2 du = ddx(uv0);
float2 dv = ddy(uv0);
float d = max(dot(du, du), dot(dv, dv));
const float r = pow(2, (kMipCount - 1) * 2);
d = clamp(d, 1.0, r);
return floor(0.5 * log2(d));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment