Blender V5.3
workbench_image.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8
9namespace workbench::color {
10
19
20/* TODO(fclem): deduplicate code. */
22{
23 float2 tile_pos = floor(co.xy);
24
25 if (tile_pos.x < 0 || tile_pos.y < 0 || tile_pos.x >= 10) {
26 return false;
27 }
28
29 float tile = 10.0f * tile_pos.y + tile_pos.x;
30 if (tile >= textureSize(map, 0).x) {
31 return false;
32 }
33
34 /* Fetch tile information. */
35 float tile_layer = texelFetch(map, int2(int(tile), 0), 0).x;
36 if (tile_layer < 0.0f) {
37 return false;
38 }
39
40 float4 tile_info = texelFetch(map, int2(int(tile), 1), 0);
41
42 co = float3(((co.xy - tile_pos) * tile_info.zw) + tile_info.xy, tile_layer);
43 return true;
44}
45
47{
49
50 float3 co = float3(uvs, 0.0f);
51 if (srt.is_image_tile) {
52 if (tile_lookup(co, srt.imageTileData)) {
53 color = texture(srt.imageTileArray, co);
54 }
55 else {
56 color = float4(1.0f, 0.0f, 1.0f, 1.0f);
57 }
58 }
59 else {
60 color = texture(srt.imageTexture, uvs);
61 }
62
63 /* Un-pre-multiply if stored multiplied, since straight alpha is expected by shaders. */
64 if (srt.image_premult && !(color.a == 0.0f || color.a == 1.0f)) {
65 color.rgb /= color.a;
66 }
67
68 if (color.a < srt.image_transparency_cutoff) {
70 }
71
72 return color.rgb;
73}
74
75} // namespace workbench::color
#define push_constant
#define resource_table
#define sampler(slot)
void gpu_discard_fragment()
#define floor
SamplerBase< float, 1, false, true > sampler1DArray
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) RET
SamplerBase< float, 2, false, true > sampler2DArray
SamplerBase< float, 2 > sampler2D
TEX_TEMPLATE SizeVec textureSize(T, int) RET
const ccl_global KernelWorkTile * tile
float3 image_color(Texture &srt, float2 uvs)
bool tile_lookup(float3 &co, sampler1DArray map)
float x
float y
#define WB_TEXTURE_SLOT
#define WB_TILE_DATA_SLOT
#define WB_TILE_ARRAY_SLOT