Skip to content

Instantly share code, notes, and snippets.

@partybusiness
Created March 27, 2025 02:48
Show Gist options
  • Save partybusiness/913c41235367edb00eee21aa3840fcbf to your computer and use it in GitHub Desktop.
Save partybusiness/913c41235367edb00eee21aa3840fcbf to your computer and use it in GitHub Desktop.
Gets the size of a texel on-screen in pixels
shader_type spatial;
// quick test for how large a texel in on-screen in pixels
uniform sampler2D test_texture:filter_nearest;
void fragment() {
vec2 uv_per_texel = vec2(1.0, 1.0) / vec2(textureSize(test_texture, 0));
vec2 dfx = dFdx(UV);
vec2 dfy = dFdy(UV);
vec2 uv_per_pixel = vec2(length(vec2(dfx.x, dfy.x)), length(vec2(dfx.y, dfy.y)));
vec2 pixel_per_texel = uv_per_texel / uv_per_pixel;
if (pixel_per_texel.x > 16.0) // if a texel of the texture occupies more than 16 pixels on-screen
ALBEDO = texture(test_texture, UV).rgb;
else
ALBEDO = 1.0 - texture(test_texture, UV).rgb;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment