Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gpu_shader_compositor_texture_utilities.glsl « library « compositor « shaders « gpu « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 128fc6aeaf5d7eb3141b89c49b5ba16a6c844038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* A shorthand for 1D textureSize with a zero LOD. */
int texture_size(sampler1D sampler)
{
  return textureSize(sampler, 0);
}

/* A shorthand for 1D texelFetch with zero LOD and bounded access clamped to border. */
vec4 texture_load(sampler1D sampler, int x)
{
  const int texture_bound = texture_size(sampler) - 1;
  return texelFetch(sampler, clamp(x, 0, texture_bound), 0);
}

/* A shorthand for 2D textureSize with a zero LOD. */
ivec2 texture_size(sampler2D sampler)
{
  return textureSize(sampler, 0);
}

/* A shorthand for 2D texelFetch with zero LOD and bounded access clamped to border. */
vec4 texture_load(sampler2D sampler, ivec2 texel)
{
  const ivec2 texture_bounds = texture_size(sampler) - ivec2(1);
  return texelFetch(sampler, clamp(texel, ivec2(0), texture_bounds), 0);
}

/* A shorthand for 2D texelFetch with zero LOD and a fallback value for out-of-bound access. */
vec4 texture_load(sampler2D sampler, ivec2 texel, vec4 fallback)
{
  const ivec2 texture_bounds = texture_size(sampler) - ivec2(1);
  if (any(lessThan(texel, ivec2(0))) || any(greaterThan(texel, texture_bounds))) {
    return fallback;
  }
  return texelFetch(sampler, texel, 0);
}