diff options
author | Michael Kowalski <makowalski@nvidia.com> | 2022-11-08 03:37:51 +0300 |
---|---|---|
committer | Michael Kowalski <makowalski@nvidia.com> | 2022-11-08 03:37:51 +0300 |
commit | a400935d29f54b9bd821d093873eb4643a279e59 (patch) | |
tree | 5dbd37ed111ee47c0dbe5696b834c3a16e96435c /source/blender/compositor/realtime_compositor/shaders/library/gpu_shader_compositor_texture_utilities.glsl | |
parent | 036e10e5462b95ec6a12e9dd4a900ba7ff05032c (diff) | |
parent | d8dab1ba978e32af9af581fbd4c4bc0682278703 (diff) |
Merge branch 'tmp-vfx-platform-2023' into tmp-dynamic-usdtmp-dynamic-usd
Diffstat (limited to 'source/blender/compositor/realtime_compositor/shaders/library/gpu_shader_compositor_texture_utilities.glsl')
-rw-r--r-- | source/blender/compositor/realtime_compositor/shaders/library/gpu_shader_compositor_texture_utilities.glsl | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/source/blender/compositor/realtime_compositor/shaders/library/gpu_shader_compositor_texture_utilities.glsl b/source/blender/compositor/realtime_compositor/shaders/library/gpu_shader_compositor_texture_utilities.glsl new file mode 100644 index 00000000000..128fc6aeaf5 --- /dev/null +++ b/source/blender/compositor/realtime_compositor/shaders/library/gpu_shader_compositor_texture_utilities.glsl @@ -0,0 +1,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); +} |