36 uint
index = global_id.x;
37 if (
index >= uint(srt.resource_len)) {
53 for (
int i = 0; i < 8; i++) {
54 local_min =
min(local_min, box.
corners[i].xyz);
55 local_max =
max(local_max, box.
corners[i].xyz);
83 int closest_surfel = -1;
84 float closest_distance_sqr = 1e10f;
85 for (
int surfel_id = surfel_first; surfel_id > -1;
93 if (surfel_dist_sqr > search_radius_sqr) {
97 if (closest_distance_sqr > surfel_dist_sqr) {
98 closest_distance_sqr = surfel_dist_sqr;
99 closest_surfel = surfel_id;
102 return closest_surfel;
112 return surfel_distance - ((surfel_distance > 0.0f) ?
124 return surfel_distance + ((surfel_distance > 0.0f) ?
141 float surfel_distance_pos = +1e10f;
142 float surfel_distance_neg = -1e10f;
143 for (
int surfel_id = surfel_first; surfel_id > -1;
149 float surf_dist_signed =
dot(offset_direction, probe_to_surfel);
151 if (
abs(surf_dist_signed) > search_radius) {
155 float ray_dist =
distance(surf_dist_signed * offset_direction, probe_to_surfel);
156 if (ray_dist > ray_radius) {
160 if (surf_dist_signed > 0.0f) {
161 if (surfel_distance_pos > surf_dist_signed) {
162 surfel_distance_pos = surf_dist_signed;
163 surfel_pos = surfel_id;
167 if (surfel_distance_neg < surf_dist_signed) {
168 surfel_distance_neg = surf_dist_signed;
169 surfel_neg = surfel_id;
174 bool has_neighbor_pos = surfel_pos != -1;
175 bool has_neighbor_neg = surfel_neg != -1;
177 if (has_neighbor_pos && has_neighbor_neg) {
183 if (is_front_facing_pos && is_front_facing_neg) {
185 if (is_front_facing_pos) {
187 float distance_between_neighbors = surfel_distance_pos - surfel_distance_neg;
191 return (surfel_distance_pos + surfel_distance_neg) / 2.0f;
203 float front_distance = is_front_facing_pos ? surfel_distance_pos : surfel_distance_neg;
204 float back_distance = !is_front_facing_pos ? surfel_distance_pos : surfel_distance_neg;
208 return (
abs(front_offset) <
abs(back_offset)) ? front_offset : back_offset;
211 if (has_neighbor_pos || has_neighbor_neg) {
213 int nearest_surfel_id = has_neighbor_pos ? surfel_pos : surfel_neg;
214 float surfel_distance = has_neighbor_pos ? surfel_distance_pos : surfel_distance_neg;
215 bool is_front_facing =
dot(has_neighbor_pos ? offset_direction : -offset_direction,
217 if (is_front_facing) {
253 int closest_surfel_id = srt.find_closest_surfel(grid_coord,
P);
254 if (closest_surfel_id == -1) {
263 bool is_front_facing =
dot(surfels.
surfel_buf[closest_surfel_id].position -
P,
264 surfels.
surfel_buf[closest_surfel_id].normal) < 0.0f;
265 if (is_front_facing) {
266 offset_direction = -offset_direction;
269 float offset_length = srt.compute_offset_length(grid_coord,
P, offset_direction);
271 float3 virtual_offset = offset_direction * offset_length;
300 irradiance *= 4.0f *
M_PI;
301 visibility *= 4.0f *
M_PI;
313 irradiance_vis += facing ?
surfel.radiance_direct.front :
surfel.radiance_direct.back;
322 irradiance_vis += facing ? surfel_radiance_indirect.front : surfel_radiance_indirect.back;
331 validity +=
float(facing);
342 float visibility = 0.0f;
394 float irradiance_sample_ray_distance;
396 view, srt.list_info_buf.ray_grid_size,
P, irradiance_sample_ray_distance);
399 int surfel_prev = -1;
400 int surfel_next = srt.list_start_buf[list_index];
402 for (
int i = 0; i < 9999; i++) {
403 if (surfel_next <= -1) {
407 if (surfels.
surfel_buf[surfel_next].ray_distance < irradiance_sample_ray_distance) {
410 surfel_prev = surfel_next;
411 surfel_next = surfels.
surfel_buf[surfel_next].next;
412 assert(surfel_prev != surfel_next);
422 float validity =
imageLoadFast(srt.validity_img, grid_coord).r;
426 sh.
L0.M0 *= weight_captured;
427 sh.
L1.Mn1 *= weight_captured;
428 sh.
L1.M0 *= weight_captured;
429 sh.
L1.Mp1 *= weight_captured;
430 validity *= weight_captured;
432 if (surfel_next > -1) {
434 srt.irradiance_capture_surfel(
surfel,
P, sh);
435 srt.validity_capture_surfel(
surfel,
P, validity);
441 srt.irradiance_capture_world(-sky_L, sh);
442 srt.validity_capture_world(-sky_L, validity);
448 if (surfel_prev > -1) {
450 srt.irradiance_capture_surfel(
surfel,
P, sh);
451 srt.validity_capture_surfel(
surfel,
P, validity);
457 srt.irradiance_capture_world(sky_L, sh);
458 srt.validity_capture_world(sky_L, validity);
465 weight_captured += 2.0f;
466 sh.
L0.M0 /= weight_captured;
467 sh.
L1.Mn1 /= weight_captured;
468 sh.
L1.M0 /= weight_captured;
469 sh.
L1.Mp1 /= weight_captured;
470 validity /= weight_captured;
void drw_debug_line(uint &vertid, float3 v1, float3 v2, uint v_color, uint lifetime)
IsectBox isect_box_setup(Box shape)
bool drw_bounds_are_valid(ObjectBounds bounds)
#define IRRADIANCE_BOUNDS_GROUP_SIZE
#define IRRADIANCE_GRID_BRICK_SIZE
#define IRRADIANCE_GRID_GROUP_SIZE
PipelineCompute eevee_lightprobe_volume_ray(eevee::lightprobe::volume::ray_capture)
PipelineCompute eevee_lightprobe_volume_offset(eevee::lightprobe::volume::volume_offset)
PipelineCompute eevee_lightprobe_volume_bounds(eevee::lightprobe::volume::scene_bounds)
#define assert(assertion)
#define storage(slot, qualifiers)
#define image(slot, qualifiers, format)
#define global_invocation_id
int atomicMin(int &, int) RET
VecBase< bool, D > greaterThanEqual(VecOp< T, D >, VecOp< T, D >) RET
bool any(VecOp< bool, D >) RET
int atomicMax(int &, int) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
float distance(float, float) RET
ImageBase< int, 3, false, true > iimage3DAtomic
IMG_TEMPLATE DataVec imageLoad(const T &, IntCoord) RET
ImageBase< float, 3 > image3D
float length_squared(VecT a)
float reduce_max(float2 a)
VecT safe_normalize(VecT vector)
int floatBitsToOrderedInt(float value)
void ray_capture(RayCapture &srt, const draw::View &views, const uint3 global_id)
void volume_offset(VolumeOffset &srt, const uint3 global_id)
void scene_bounds(SceneBound &srt, const uint3 global_id)
float3 grid_sample_position(float4x4 grid_local_to_world_mat, int3 grid_res, int3 cell_coord)
int list_index_get(const ViewMatrices view, int2 ray_grid_size, float3 P, float &r_ray_distance)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
float4 bounding_corners[4]
spherical_harmonics::BandL1< T > L1
spherical_harmonics::BandL0< T > L0
void encode_signal_sample(float3 direction, T amplitude)
const CaptureInfoData & capture_info_buf
float3 world_incident_vector(float3 P) const
float4 sample_probe(float3 L, float lod, SphereProbeUvArea uv_area) const
image3D irradiance_L1_c_img
image3D irradiance_L0_img
const SurfelListInfoData & list_info_buf
void irradiance_capture_surfel(Surfel surfel, float3 P, SphericalHarmonicL1< float4 > &sh)
image3D irradiance_L1_a_img
LightprobeSphereRenderData sphere_probes
void validity_capture_world(float3, float &validity)
void irradiance_capture(float3 L, float3 irradiance, float visibility, SphericalHarmonicL1< float4 > &sh)
void irradiance_capture_world(float3 L, SphericalHarmonicL1< float4 > &sh)
const int(& list_start_buf)[]
const image3D virtual_offset_img
void validity_capture_surfel(Surfel surfel, float3 P, float &validity)
image3D irradiance_L1_b_img
CaptureInfoData & capture_info_buf
const ObjectBounds(& bounds_buf)[]
image3D virtual_offset_img
float front_facing_offset(float surfel_distance)
float compute_offset_length(int3 grid_coord, float3 P, float3 offset_direction)
int find_closest_surfel(int3 grid_coord, float3 P)
const iimage3DAtomic cluster_list_img
const int(& list_start_buf)[]
float back_facing_offset(float surfel_distance)
const SurfelListInfoData & list_info_buf