Blender V5.3
eevee_lookdev_copy_world.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
11namespace eevee::lookdev {
12
13struct CopyWorld {
14 [[storage(0, read)]] const SphereProbeHarmonic &in_sh;
15 [[storage(1, write)]] SphereProbeHarmonic &out_sh;
16 /* WORKAROUND: The no_restrict flag is here to workaround an NVidia linker quirk
17 * (see #134239). */
18 [[storage(2, read_no_restrict)]] const LightData &in_sun;
19 [[storage(3, write)]] LightData &out_sun;
33
35 int2 texel,
36 SphereProbeUvArea read_coord,
37 SphereProbePixelArea write_coord,
38 float3x3 rotation_mat)
39 {
40 float3 rotated_ws_direction = lightprobe::sphere::texel_to_direction(float2(texel),
41 write_coord);
42 /* Multiplying with the inverse (which is also the transposed given the rotation matrix is
43 * orthonormal) as we want the reversed transform. */
44 float3 original_ws_direction = transpose(rotation_mat) * rotated_ws_direction;
45 float2 uv = lightprobe::sphere::direction_to_uv(original_ws_direction, float(mip), read_coord);
46 return textureLod(in_sphere_tx, float3(uv, read_coord.layer), float(mip));
47 }
48};
49
55[[compute, local_size(SPHERE_PROBE_REMAP_GROUP_SIZE, SPHERE_PROBE_REMAP_GROUP_SIZE)]]
57 [[global_invocation_id]] const uint3 global_id)
58{
59 float3x3 rotation_mat = to_float3x3(srt.lookdev_rotation);
60 if (all(equal(global_id.xy, uint2(0)))) {
61 {
63 sh.L0.M0 = srt.in_sh.L0_M0;
64 sh.L1.M0 = srt.in_sh.L1_M0;
65 sh.L1.Mn1 = srt.in_sh.L1_Mn1;
66 sh.L1.Mp1 = srt.in_sh.L1_Mp1;
67 sh = spherical_harmonics::rotate(rotation_mat, sh);
68 srt.out_sh.L0_M0 = sh.L0.M0;
69 srt.out_sh.L1_M0 = sh.L1.M0;
70 srt.out_sh.L1_Mn1 = sh.L1.Mn1;
71 srt.out_sh.L1_Mp1 = sh.L1.Mp1;
72 }
73 {
74 LightData sun = srt.in_sun;
75 float3x3 sun_direction = to_float3x3(transform_to_matrix(sun.object_to_world));
76 sun_direction = rotation_mat * sun_direction;
77 sun.object_to_world = transform_from_matrix(to_float4x4(sun_direction));
78 srt.out_sun = sun;
79 }
80 }
81
82 int2 local_texel = int2(global_id.xy);
83 SphereProbeUvArea read_coord = reinterpret_as_atlas_coord(srt.read_coord_packed);
84 SphereProbePixelArea write_coord;
85 /* Exit when pixel being written doesn't fit in the area reserved for the probe. */
86 /* We cannot put the following code in a loop because of the different image accesses.
87 * So we have to manually unroll the loop. */
88 write_coord = reinterpret_as_write_coord(srt.write_coord_mip0_packed);
89 if (any(greaterThanEqual(local_texel, int2(write_coord.extent)))) {
90 return;
91 }
92 imageStore(srt.out_sphere_mip0,
93 int3(local_texel, write_coord.layer),
94 srt.get_mip_data(0, local_texel, read_coord, write_coord, rotation_mat));
95
96 write_coord = reinterpret_as_write_coord(srt.write_coord_mip1_packed);
97 if (any(greaterThanEqual(local_texel, int2(write_coord.extent)))) {
98 return;
99 }
100 imageStore(srt.out_sphere_mip1,
101 int3(local_texel, write_coord.layer),
102 srt.get_mip_data(1, local_texel, read_coord, write_coord, rotation_mat));
103
104 write_coord = reinterpret_as_write_coord(srt.write_coord_mip2_packed);
105 if (any(greaterThanEqual(local_texel, int2(write_coord.extent)))) {
106 return;
107 }
108 imageStore(srt.out_sphere_mip2,
109 int3(local_texel, write_coord.layer),
110 srt.get_mip_data(2, local_texel, read_coord, write_coord, rotation_mat));
111
112 write_coord = reinterpret_as_write_coord(srt.write_coord_mip3_packed);
113 if (any(greaterThanEqual(local_texel, int2(write_coord.extent)))) {
114 return;
115 }
116 imageStore(srt.out_sphere_mip3,
117 int3(local_texel, write_coord.layer),
118 srt.get_mip_data(3, local_texel, read_coord, write_coord, rotation_mat));
119
120 write_coord = reinterpret_as_write_coord(srt.write_coord_mip4_packed);
121 if (any(greaterThanEqual(local_texel, int2(write_coord.extent)))) {
122 return;
123 }
124 imageStore(srt.out_sphere_mip4,
125 int3(local_texel, write_coord.layer),
126 srt.get_mip_data(4, local_texel, read_coord, write_coord, rotation_mat));
127
128#ifdef GLSL_CPP_STUBS
129 /* If this mismatches, manual unroll needs to be updated. */
130 static_assert(SPHERE_PROBE_MIPMAP_LEVELS == 5);
131#endif
132}
133
134} // namespace eevee::lookdev
135
#define SPHERE_PROBE_FORMAT
PipelineCompute eevee_lookdev_copy_world(eevee::lookdev::copy_world_main)
#define storage(slot, qualifiers)
#define image(slot, qualifiers, format)
#define push_constant
#define resource_table
#define sampler(slot)
#define global_invocation_id
#define compute
#define local_size(...)
VecBase< bool, D > greaterThanEqual(VecOp< T, D >, VecOp< T, D >) RET
bool any(VecOp< bool, D >) RET
bool all(VecOp< bool, D >) RET
MatBase< R, C > transpose(MatBase< C, R >) RET
VecBase< bool, D > equal(VecOp< T, D >, VecOp< T, D >) RET
ImageBase< float, 2, true > image2DArray
IMG_TEMPLATE void imageStore(T &, IntCoord, DataVec)
TEX_TEMPLATE DataVec textureLod(T, FltCoord, float) RET
SamplerBase< float, 2, false, true > sampler2DArray
MatBase< float, 4, 4 > float4x4
float3 texel_to_direction(float2 local_texel, SphereProbePixelArea texel_area, float2 &sampling_uv)
void direction_to_uv(float3 L, float lod_min, float lod_max, SphereProbeUvArea uv_area, float2 &altas_uv_min, float2 &altas_uv_max)
void copy_world_main(CopyWorld &srt, const uint3 global_id)
SphereProbePixelArea reinterpret_as_write_coord(int4 packed_coord)
SphereProbeUvArea reinterpret_as_atlas_coord(int4 packed_coord)
SphericalHarmonicL1< float4 > rotate(float3x3 rotation, SphericalHarmonicL1< float4 > sh)
float3 sun_direction(float sun_cos_theta)
Definition sky_math.h:457
spherical_harmonics::BandL1< T > L1
spherical_harmonics::BandL0< T > L0
const SphereProbeHarmonic & in_sh
float4 get_mip_data(int mip, int2 texel, SphereProbeUvArea read_coord, SphereProbePixelArea write_coord, float3x3 rotation_mat)