Skip to content

Instantly share code, notes, and snippets.

@tomspilman
Last active September 1, 2016 13:44
Show Gist options
  • Select an option

  • Save tomspilman/616610a717bccb688ec7f674ab24efac to your computer and use it in GitHub Desktop.

Select an option

Save tomspilman/616610a717bccb688ec7f674ab24efac to your computer and use it in GitHub Desktop.
static float k_lut_size = 1.0 / 16.0;
static float k_lut_pixel_size = k_lut_size / 16.0;
static float k_lut_half_pixel_size = k_lut_pixel_size / 2.0f;
float4 tex3D(sampler2D tex, float3 coord)
{
// Clamp the sample to within one 16x16 slice to avoid filtering bleed.
float y = coord.y;
y = max(y - k_lut_half_pixel_size, k_lut_half_pixel_size);
// Offset to the right depth slice now.
y += (coord.z - fmod(coord.z, k_lut_size)) * k_lut_size;
// We skip filtering between slices for performance.
return tex2D(tex, float2(coord.x, y));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment