Blender V5.3
eevee_fast_gi.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
15
16#pragma once
17
18#include "draw_view.bsl.hh"
19#include "eevee_closure.bsl.hh"
21#include "eevee_filter.bsl.hh"
23#include "eevee_hiz.bsl.hh"
28#include "eevee_uniform.bsl.hh"
34
35namespace eevee {
36
37namespace fast_gi {
38
44{
45 constexpr int bitmask_len = 32;
46 /* Algorithm 1, line 18. Re-ordered to make sure to clamp to the hemisphere range. */
47 float2 ratio = saturate(theta * M_1_PI + 0.5f);
48 uint a = uint(floor(float(bitmask_len) * ratio.x));
49 /* The paper is wrong here. The additional half Pi is not needed. */
50 uint b = uint(ceil(float(bitmask_len) * (ratio.y - ratio.x)));
51 /* Algorithm 1, line 19. */
52 return (((b < 32u) ? 1u << b : 0u) - 1u) << a;
53}
54
56{
57 constexpr int bitmask_len = 32;
58 /* Algorithm 1, line 26. */
59 return float(bitCount(bitmask)) / float(bitmask_len);
60}
61
67{
68 /* Occlusion is the opposite of visibility. */
69 return 1.0f - bitmask_to_visibility_uniform(bitmask);
70}
71
76float bitmask_to_occlusion_cosine(uint bitmask)
77{
78 /* This is not described in the paper. Another solution would be to change the sector
79 * distribution in `angles_to_bitmask()` but that requires more computation per
80 * samples. The quality difference does not justify it currently. */
81#if 0 /* Reference. */
82 constexpr int bitmask_len = 32;
83 float visibility = 0.0f;
84 for (int bit = 0; bit < bitmask_len; bit++) {
85 float angle = (((float(bit) + 0.5f) / float(bitmask_len)) - 0.5f) * M_PI;
86 /* Integrating over the hemisphere. */
87 if (((bitmask >> bit) & 1u) == 0u) {
88 visibility += cos(angle) * M_PI_2 / float(bitmask_len);
89 }
90 }
91 return visibility;
92#else
93 /* The precomputed weights are the accumulated weights from the reference loop for each of the
94 * samples in the mask. The weight is distributed evenly for each sample inside a mask.
95 * This is like a 4 piecewise linear approximation of the cosine lobe. */
96 constexpr float4 weights = float4(0.0095061f, 0.0270951f, 0.0405571f, 0.0478421f);
97 constexpr uint4 masks = uint4(0xF000000Fu, 0x0F0000F0u, 0x00F00F00u, 0x000FF000u);
98 return saturate(1.0f - dot(float4(bitCount(uint4(bitmask) & masks)), weights));
99#endif
100}
101
108 float3 N, float3 V, float3 T, float3 B, float &N_proj_len, float &N_angle)
109{
110 /* Projected view normal onto the integration plane. */
111 float3 N_proj = normalize_and_get_length(N - B * dot(N, B), N_proj_len);
112
113 float N_sin = dot(N_proj, T);
114 float N_cos = dot(N_proj, V);
115 /* Angle between normalized projected normal and view vector. */
116 N_angle = sign(N_sin) * acos_fast(N_cos);
117}
118
119/* -------------------------------------------------------------------- */
122
123template<typename T>
124float3 sample_radiance(sampler2D /*screen_radiance_tx*/, float2 /*uv*/, float /*lod*/)
125{
126 return float3(0.0f);
127}
128template<typename T>
129float3 sample_normal(sampler2D /*screen_normal_tx*/, float2 /*uv*/, float /*lod*/)
130{
131 return float3(0.0f);
132}
133template<typename T> T select_result(float /*occlusion*/, SphericalHarmonicL1<float4> /*sh*/)
134{
135 return T(0.0f);
136}
137
138/* AO only implementation. */
139template float3 sample_radiance<float>(sampler2D screen_radiance_tx, float2 uv, float lod);
140template float3 sample_normal<float>(sampler2D screen_normal_tx, float2 uv, float lod);
141template<> float select_result<float>(float occlusion, SphericalHarmonicL1<float4> /*sh*/)
142{
143 return occlusion;
144}
145
146/* GI implementation. */
147template<>
149 float2 uv,
150 float lod)
151{
152 return textureLod(screen_radiance_tx, uv, lod).rgb;
153}
154template<>
156{
157 return textureLod(screen_normal_tx, uv, lod).rgb * 2.0f - 1.0f;
158}
159template<>
161 float /*occlusion*/, SphericalHarmonicL1<float4> sh)
162{
163 return sh;
164}
165
167
168/* -------------------------------------------------------------------- */
171
177template<typename ResultT>
178ResultT eval(const Uniform &uni,
179 const ViewMatrices view,
180 ScreenThicknessParameters thickness_params,
181 sampler2D hiz_tx,
182 sampler2D screen_radiance_tx,
183 sampler2D screen_normal_tx,
184 float3 vP,
185 float3 vN,
187 float2 pixel_size,
188 float search_distance,
189 float angle_bias,
190 const int slice_count,
191 const int sample_count,
192 const bool reversed,
193 const bool ao_only)
194{
195 float3 vV = view.view_incident_vector(vP);
196
197 float2 v_dir;
198 if (slice_count <= 2) {
199 /* We cover half the circle because we trace in both directions. */
200 v_dir = sample_circle(noise.x / float(2 * slice_count));
201 }
202
203 float weight_accum = 0.0f;
204 float occlusion_accum = 0.0f;
205 SphericalHarmonicL1<float4> sh_accum = {};
206
207#if defined(GPU_METAL)
208/* NOTE: Full loop unroll hint increases performance on Apple Silicon. */
209# pragma clang loop unroll(full)
210#endif
211 for (int slice = 0; slice < slice_count; slice++) {
212 if (slice_count > 2) {
213 /* We cover half the circle because we trace in both directions. */
214 v_dir = sample_circle(((float(slice) + noise.x) / float(2 * slice_count)));
215 }
216
217 /* Setup integration domain around V. */
218 float3 vB = normalize(cross(vV, float3(v_dir, 0.0f)));
219 float3 vT = cross(vB, vV);
220
221 /* Bitmask representing the occluded sectors on the slice. */
222 uint slice_bitmask = 0u;
223
224 /* Angle between vN and the horizon slice plane. */
225 float vN_angle;
226 /* Length of vN projected onto the horizon slice plane. */
227 float vN_length;
228
229 projected_normal_to_plane_angle_and_length(vN, vV, vT, vB, vN_length, vN_angle);
230
231 /* Jitter slice integration domain to avoid banding due to the bitmask. */
232 vN_angle += (noise.z - 0.5f) * (M_PI / 32.0f) * angle_bias;
233
234 SphericalHarmonicL1<float4> sh_slice = {};
235 /* The 4th component contains visibility. Set visibility to 1 for the upper hemisphere. */
236 sh_slice.encode_signal_sample(vN, float4(0.0f, 0.0f, 0.0f, 1.0f));
237
238 /* For both sides of the view vector. */
239 for (int side = 0; side < 2; side++) {
240 Ray ray;
241 ray.origin = vP;
242 ray.direction = float3((side == 0) ? v_dir : -v_dir, 0.0f);
243 ray.max_time = search_distance;
244
245 /* TODO(fclem): Could save some computation here by computing entry and exit point on the
246 * screen at once and just scan through. */
247 ScreenSpaceRay ssray = ScreenSpaceRay::create(view, ray, pixel_size);
248
250
251#if defined(GPU_METAL) && defined(GPU_APPLE)
252/* NOTE: Full loop unroll hint increases performance on Apple Silicon. */
253# pragma clang loop unroll(full)
254#endif
255 for (int j = 0; j < sample_count; j++) {
256 /* Always cross at least one pixel. */
257 float time = 1.0f + square((float(j) + noise.y) / float(sample_count)) * ssray.max_time;
258
259 if (reversed) {
260 /* We need to cross at least 2 pixels to avoid artifacts form the HiZ storing only the
261 * max depth. The HiZ would need to contain the min depth instead to avoid this. */
262 time += 1.0f;
263 }
264
265 const float lod = log2(time * uni.uniform_buf.ao.lod_factor);
266
267 const float2 sample_uv = ssray.origin.xy + ssray.direction.xy * time;
268 float sample_depth =
269 textureLod(hiz_tx, sample_uv * uni.uniform_buf.hiz.uv_scale, floor(noise.w + lod)).r;
270
271 if (sample_depth == 1.0f && !reversed) {
272 /* Skip background. Avoids making shadow on the geometry near the far plane. */
273 continue;
274 }
275
276 float sample_view_z = view.depth_screen_to_view(sample_depth);
277 float sample_ndc_min_thickness = thickness_params.pixel_depth_thickness_at(sample_view_z);
278
279 float sample_thickness = thickness_estimator.thickness(
280 sample_depth, time, sample_ndc_min_thickness);
281
282 /* Bias depth a bit to avoid self shadowing issues. */
283 constexpr float bias = 2.0f * 2.4e-7f;
284 const float sample_depth_front = sample_depth + (reversed ? -bias : bias);
285 const float sample_depth_back = sample_depth + (reversed ? 0.0 : sample_thickness);
286
287 float3 vP_sample_front = view.point_screen_to_view(float3(sample_uv, sample_depth_front));
288 float3 vP_sample_back = view.point_screen_to_view(float3(sample_uv, sample_depth_back));
289
290 /* Mimic a sphere intersection check + clipping of the intersecting ray.
291 * Assumes the ray is aligned with the view Z axis.
292 * While this is exact for orthographic cameras it can distort the AO look with high FOV
293 * angle. However it is cheaper than a full sphere clipping. */
294 float3 ls_P_front = (vP_sample_front - vP) / search_distance;
295 float3 ls_P_back = (vP_sample_back - vP) / search_distance;
296 /* Simplification of `sin_from_cos(length(ls_P_front.xy))`. */
297 float max_dist = sqrt_fast(saturate(1.0f - length_squared(ls_P_front.xy)));
298 if (!reversed) {
299 ls_P_front.z = clamp(ls_P_front.z, -max_dist, max_dist);
300 ls_P_back.z = clamp(ls_P_back.z, -max_dist, max_dist);
301 if (ls_P_front.z == ls_P_back.z) {
302 continue;
303 }
304 }
305
306 float3 vL_front = normalize(ls_P_front);
307 float3 vL_back = normalize(ls_P_back);
308
309 float LV_front = dot(vL_front, vV);
310 float LV_back = dot(vL_back, vV);
311 if (reversed) {
312 /* In reverse mode we revert back to horizon scanning.
313 * Occlude everything in front of this sample. */
314 LV_front = 1.0f;
315 /* If hitting the background consider the sample infinitely far away. */
316 if (sample_depth == 1.0f) {
317 LV_back = -1.0f;
318 }
319 }
320 /* Ordered pair of angle. Minimum in X, Maximum in Y.
321 * Front will always have the smallest angle here since it is the closest to the view. */
322 float2 theta = acos_fast(float2(LV_front, LV_back));
323 theta.y = max(theta.x, theta.y);
324 if (reversed) {
325 /* This is the main part of the reversed AO.
326 * Rotate the angles 180 degrees to align with the front facing normal. */
327 theta -= M_PI;
328 }
329 /* If we are tracing backward, the angles are negative. Swizzle to keep correct order. */
330 theta = (side == 0) ? theta.xy : -theta.yx;
331
332 const float2 sample_uv_data = sample_uv * uni.raytrace_buf.fast_gi_uv_scale;
333 /* Need to account for LOD0 of radiance texture being the tracing resolution. */
334 float lod_data = lod - uni.raytrace_buf.fast_gi_lod_bias;
335
336 float3 radiance = sample_radiance<ResultT>(screen_radiance_tx, sample_uv_data, lod_data);
337 /* Take emitter surface normal into consideration. */
338 float3 normal = sample_normal<ResultT>(screen_normal_tx, sample_uv_data, lod_data);
339 if (ao_only) {
340 radiance = float3(0);
341 }
342 /* Discard back-facing samples. */
343 float facing = dot(normal, -vL_front);
344 if (facing < 0.0f) {
345 radiance *= uni.raytrace_buf.backface_hit_scale;
346 }
347 float facing_weight = abs(facing);
348
349 /* Angular bias shrinks the visibility bitmask around the projected normal. */
350 float2 biased_theta = (theta - vN_angle) * angle_bias;
351 uint sample_bitmask = angles_to_bitmask(biased_theta);
352 float weight_bitmask = bitmask_to_visibility_uniform(sample_bitmask & ~slice_bitmask);
353
354 radiance *= facing_weight * weight_bitmask;
355 sh_slice.encode_signal_sample(vL_front, float4(radiance, -weight_bitmask));
356
357 slice_bitmask |= sample_bitmask;
358 }
359 }
360
361 float occlusion_slice = bitmask_to_occlusion_cosine(slice_bitmask);
362 /* Correct normal not on plane (Eq. 8 of GTAO paper). */
363 occlusion_accum += occlusion_slice * vN_length;
364
365 /* Use uniform visibility since this is what we use for near field lighting. */
366 sh_accum = spherical_harmonics::madd(sh_slice, vN_length, sh_accum);
367
368 weight_accum += vN_length;
369
370 /* Rotate 90 degrees. */
371 v_dir = orthogonal(v_dir);
372 }
373
374 float weight_rcp = safe_rcp(weight_accum);
375
376 /* Weight by area of the sphere. This is expected for correct SH evaluation. */
377 float sphere_weight = 2.0f * M_TAU;
378
379 /* We store the energy for the whole sphere but we weighted G.I. from a biased cone (angle_bias).
380 * So we need to normalize by the actual cone we weighted with.
381 * `angle_bias` has range [1..2] */
382 // float biased_solid_angle = M_TAU * (1.0f - cos(angle_bias * M_PI_2));
383 // float hemisphere_solid_angle = M_TAU;
384 // float gi_weight_factor = sphere_weight / (hemisphere_solid_angle + biased_solid_angle);
385 /* The above simplifies to this. */
386 float gi_weight_factor = 1.0f / ((3.0f / 2.0f) - cos(angle_bias * M_PI_2));
387
388 sphere_weight = weight_rcp * sphere_weight;
389 /* For some unknown reason, the GI and visibility do not need the same weighting. */
390 float4 sh_weight = float4(float3(sphere_weight * gi_weight_factor), sphere_weight);
391
392 sh_accum = spherical_harmonics::mul(sh_accum, sh_weight);
393 occlusion_accum *= weight_rcp;
394 return select_result<ResultT>(occlusion_accum, sh_accum);
395}
396
397template float eval<float>(const Uniform &,
398 const ViewMatrices,
399 ScreenThicknessParameters,
400 sampler2D,
401 sampler2D,
402 sampler2D,
403 float3,
404 float3,
405 float4,
406 float2,
407 float,
408 float,
409 int,
410 int,
411 bool,
412 bool);
414 const ViewMatrices,
415 ScreenThicknessParameters,
416 sampler2D,
417 sampler2D,
418 sampler2D,
419 float3,
420 float3,
421 float4,
422 float2,
423 float,
424 float,
425 int,
426 int,
427 bool,
428 bool);
429
431
432/* -------------------------------------------------------------------- */
435
438 /* utility_tx reserves slot 2. */
439 /* hiz reserves slot 3. */
442 /* lightprobe reserves slot 6-7. */
446
447 float3 sample_normal_get(const draw::View &views, int2 texel, bool &is_processed) const
448 {
449 float4 normal = texelFetch(screen_normal_tx, texel, 0);
450 is_processed = (normal.w != 0.0f);
451 return views.get(0).normal_view_to_world(normal.xyz * 2.0f - 1.0f);
452 }
453
454 /* Used for denoise. */
455 float sample_weight_get(const Uniform &uni,
456 const draw::View &views,
457 sampler2D hiz_tx,
458 float3 center_N,
459 float3 center_P,
460 int2 sample_texel,
461 float2 sample_uv,
462 int2 sample_offset) const
463 {
464 int2 sample_texel_fullres = sample_texel * uni.raytrace_buf.fast_gi_resolution_scale +
465 uni.raytrace_buf.fast_gi_resolution_bias;
466 float sample_depth = texelFetch(hiz_tx, sample_texel_fullres, 0).r;
467
468 bool is_valid;
469 float3 sample_N = sample_normal_get(views, sample_texel, is_valid);
470 float3 sample_P = views.get(0).point_screen_to_world(float3(sample_uv, sample_depth));
471
472 if (!is_valid) {
473 return 0.0f;
474 }
475
476 float gauss = filters::gaussian_factor(1.5f, 1.5f);
477
478 /* TODO(fclem): Scene parameter. 100.0f is dependent on scene scale. */
479 float depth_weight = filters::planar_weight(center_N, center_P, sample_P, 100.0f);
480 float spatial_weight = filters::gaussian_weight(gauss, length_squared(float2(sample_offset)));
481 float normal_weight = filters::angle_weight(center_N, sample_N);
482
483 return max(1e-6f, depth_weight * spatial_weight * normal_weight);
484 }
485
486 /* Used for resolve. */
487 float sample_weight_get(const Uniform &uni,
488 const draw::View &views,
489 float3 center_N,
490 float3 center_P,
491 int2 center_texel,
492 int2 sample_offset) const
493 {
494 int2 sample_texel = center_texel + sample_offset;
495 int2 sample_texel_fullres = sample_texel * uni.raytrace_buf.fast_gi_resolution_scale +
496 uni.raytrace_buf.fast_gi_resolution_bias;
497 float2 sample_uv = (float2(sample_texel_fullres) + 0.5f) *
498 uni.raytrace_buf.full_resolution_inv;
499
500 float sample_depth = reverse_z::read(texelFetch(depth_tx, sample_texel_fullres, 0).r);
501
502 bool is_valid;
503 float3 sample_N = sample_normal_get(views, sample_texel, is_valid);
504 float3 sample_P = views.get(0).point_screen_to_world(float3(sample_uv, sample_depth));
505
506 if (!is_valid) {
507 return 0.0f;
508 }
509
510 /* TODO(fclem): Scene parameter. 10000.0f is dependent on scene scale. */
511 float depth_weight = filters::planar_weight(center_N, center_P, sample_P, 10000.0f);
512 float normal_weight = filters::angle_weight(center_N, sample_N);
513 /* Some pixels might have no correct weight (depth & normal weights being very small).
514 * To avoid them have invalid energy (because of float precision),
515 * we weight all valid samples by a very small amount. */
516 float epsilon_weight = 1e-4f;
517
518 return max(epsilon_weight, depth_weight * normal_weight);
519 }
520
522 {
524 sh.L0.M0 = texelFetch(fast_gi_radiance_0_tx, texel, 0);
525 sh.L1.Mn1 = texelFetch(fast_gi_radiance_1_tx, texel, 0);
526 sh.L1.M0 = texelFetch(fast_gi_radiance_2_tx, texel, 0);
527 sh.L1.Mp1 = texelFetch(fast_gi_radiance_3_tx, texel, 0);
529 return sh;
530 }
531
532 SphericalHarmonicL1<float4> load_sh(int2 texel, bool valid) const
533 {
534 if (!valid) {
535 /* We need to avoid sampling if there no weight as the texture values could be undefined
536 * (is_valid is false). */
537 return {};
538 }
539 return load_sh(texel);
540 }
541};
542
548
550 {
551 result = spherical_harmonics::compress(result);
552 imageStore(sh_0_img, texel, result.L0.M0);
553 imageStore(sh_1_img, texel, result.L1.Mn1);
554 imageStore(sh_2_img, texel, result.L1.M0);
555 imageStore(sh_3_img, texel, result.L1.Mp1);
556 }
557};
558
559struct Tiles {
560 [[storage(7, read)]] const uint (&tiles_coord_buf)[];
561};
562
564
565/* -------------------------------------------------------------------- */
568
584
585[[compute, local_size(RAYTRACE_GROUP_SIZE, RAYTRACE_GROUP_SIZE)]]
586void setup([[global_invocation_id]] const uint3 global_id,
587 [[local_invocation_id]] const uint3 local_id,
588 [[resource_table]] const gbuffer::Reader &reader,
589 [[resource_table]] const Uniform &uni,
590 [[resource_table]] const draw::View &views,
591 [[resource_table]] Setup &srt)
592{
593 int2 texel = int2(global_id.xy);
594 int2 texel_fullres = texel * uni.raytrace_buf.fast_gi_resolution_scale +
595 uni.raytrace_buf.fast_gi_resolution_bias;
596
597 /* Avoid loading texels outside texture range. */
598 int2 extent = textureSize(reader.gbuf_header_tx, 0).xy;
599 texel_fullres = min(texel_fullres, extent - 1);
600
601 /* Load Gbuffer. */
602 const gbuffer::Layers gbuf = reader.read_layers(texel_fullres);
603
604 /* Tag processed pixel in the normal buffer for denoising speed. */
605 bool is_processed = !gbuf.header.is_empty();
606
607 const ViewMatrices view = views.get(0);
608
609 /* Export normal. */
610 /* FIXME: This is zero for opaque layer when we are processing the refraction layer.
611 * This is because the GBuffer header was cleared in between the layers. The refraction layer
612 * currently have incorrect fast GI coming from opaque layer. */
613 float3 vN = view.normal_world_to_view(gbuf.surface_N());
614
615 if (!is_processed) {
616 vN = float3(0.0f, 0.0f, 1.0f);
617 }
618
619 /* Compress as the format is unsigned. */
620 float3 vN_unit = vN * 0.5f + 0.5f;
621 imageStoreFast(srt.out_normal_mip0, texel, float4(vN_unit, float(is_processed)));
622
623 srt.neigbhor_data[local_id.y][local_id.x] = vN_unit;
624 barrier();
625
626 /* Downsample mip0 to the 3 other mips. */
627 /* Note we have to manually unroll the loop because of lack of image array.
628 * Using a macro isn't compatible with BSL processing. */
629 {
630 constexpr uint lod = 1u;
631 if (all(equal(local_id.xy & ((1u << lod) - 1u), uint2(0)))) {
632 uint stride = (1u << (lod - 1u));
633 float3 normal_avg = (srt.neigbhor_data[local_id.y][local_id.x] +
634 srt.neigbhor_data[local_id.y + stride][local_id.x] +
635 srt.neigbhor_data[local_id.y][local_id.x + stride] +
636 srt.neigbhor_data[local_id.y + stride][local_id.x + stride]) *
637 0.25f;
638 imageStoreFast(srt.out_normal_mip1, texel >> lod, float4(normal_avg, 0.0));
639 srt.neigbhor_data[local_id.y][local_id.x] = normal_avg;
640 }
641 }
642 barrier();
643 {
644 constexpr uint lod = 2u;
645 if (all(equal(local_id.xy & ((1u << lod) - 1u), uint2(0)))) {
646 uint stride = (1u << (lod - 1u));
647 float3 normal_avg = (srt.neigbhor_data[local_id.y][local_id.x] +
648 srt.neigbhor_data[local_id.y + stride][local_id.x] +
649 srt.neigbhor_data[local_id.y][local_id.x + stride] +
650 srt.neigbhor_data[local_id.y + stride][local_id.x + stride]) *
651 0.25f;
652 imageStoreFast(srt.out_normal_mip2, texel >> lod, float4(normal_avg, 0.0));
653 srt.neigbhor_data[local_id.y][local_id.x] = normal_avg;
654 }
655 }
656 barrier();
657 {
658 constexpr uint lod = 3u;
659 if (all(equal(local_id.xy & ((1u << lod) - 1u), uint2(0)))) {
660 uint stride = (1u << (lod - 1u));
661 float3 normal_avg = (srt.neigbhor_data[local_id.y][local_id.x] +
662 srt.neigbhor_data[local_id.y + stride][local_id.x] +
663 srt.neigbhor_data[local_id.y][local_id.x + stride] +
664 srt.neigbhor_data[local_id.y + stride][local_id.x + stride]) *
665 0.25f;
666 imageStoreFast(srt.out_normal_mip3, texel >> lod, float4(normal_avg, 0.0));
667 }
668 }
669 barrier();
670
671 /* Re-project radiance. */
672 float2 uv = (float2(texel_fullres) + 0.5f) / float2(textureSize(srt.depth_tx, 0).xy);
673 float depth = reverse_z::read(texelFetch(srt.depth_tx, texel_fullres, 0).r);
674 float3 P = view.point_screen_to_world(float3(uv, depth));
675
676 float3 ssP_prev = view.ndc_to_screen(project_point(uni.raytrace_buf.history_persmat, P));
677
678 float4 radiance = textureLod(srt.in_radiance_tx, ssP_prev.xy, 0.0f);
679 radiance = colorspace::brightness_clamp_max(radiance, uni.uniform_buf.clamp.surface_indirect);
680 imageStoreFast(srt.out_radiance_mip0, texel, radiance);
681
682 srt.neigbhor_data[local_id.y][local_id.x] = radiance.rgb;
683 barrier();
684
685 /* Downsample mip0 to the 3 other mips. */
686 {
687 constexpr uint lod = 1u;
688 if (all(equal(local_id.xy & ((1u << lod) - 1u), uint2(0)))) {
689 uint stride = (1u << (lod - 1u));
690 float3 radiance_avg = (srt.neigbhor_data[local_id.y][local_id.x] +
691 srt.neigbhor_data[local_id.y + stride][local_id.x] +
692 srt.neigbhor_data[local_id.y][local_id.x + stride] +
693 srt.neigbhor_data[local_id.y + stride][local_id.x + stride]) *
694 0.25f;
695 imageStoreFast(srt.out_radiance_mip1, texel >> lod, float4(radiance_avg, 0.0));
696 srt.neigbhor_data[local_id.y][local_id.x] = radiance_avg;
697 }
698 }
699 barrier();
700 {
701 constexpr uint lod = 2u;
702 if (all(equal(local_id.xy & ((1u << lod) - 1u), uint2(0)))) {
703 uint stride = (1u << (lod - 1u));
704 float3 radiance_avg = (srt.neigbhor_data[local_id.y][local_id.x] +
705 srt.neigbhor_data[local_id.y + stride][local_id.x] +
706 srt.neigbhor_data[local_id.y][local_id.x + stride] +
707 srt.neigbhor_data[local_id.y + stride][local_id.x + stride]) *
708 0.25f;
709 imageStoreFast(srt.out_radiance_mip2, texel >> lod, float4(radiance_avg, 0.0));
710 srt.neigbhor_data[local_id.y][local_id.x] = radiance_avg;
711 }
712 }
713 barrier();
714 {
715 constexpr uint lod = 3u;
716 if (all(equal(local_id.xy & ((1u << lod) - 1u), uint2(0)))) {
717 uint stride = (1u << (lod - 1u));
718 float3 radiance_avg = (srt.neigbhor_data[local_id.y][local_id.x] +
719 srt.neigbhor_data[local_id.y + stride][local_id.x] +
720 srt.neigbhor_data[local_id.y][local_id.x + stride] +
721 srt.neigbhor_data[local_id.y + stride][local_id.x + stride]) *
722 0.25f;
723 imageStoreFast(srt.out_radiance_mip3, texel >> lod, float4(radiance_avg, 0.0));
724 }
725 }
726}
727
729
730/* -------------------------------------------------------------------- */
733
739
744
745[[metal_max_total_threads_per_threadgroup(400)]] /* Tweak performance on metal. */
746[[compute]] [[local_size(RAYTRACE_GROUP_SIZE, RAYTRACE_GROUP_SIZE)]]
747void scan([[work_group_id]] const uint3 group_id,
748 [[local_invocation_id]] const uint3 local_id,
749 [[resource_table]] Scan &srt,
750 [[resource_table]] const Tiles &tiles,
751 [[resource_table]] const Sampling &sampling,
752 [[resource_table]] const UtilityTexture &util_tx,
753 [[resource_table]] const HiZ &hiz,
754 [[resource_table]] const gbuffer::Reader &reader,
755 [[resource_table]] const Uniform &uni,
756 [[resource_table]] const draw::View &views,
757 [[resource_table]] SampleOutput &sh_out,
758 [[resource_table]] Constants &constants)
759{
760 constexpr uint tile_size = uint(RAYTRACE_GROUP_SIZE);
761 uint2 tile_coord = unpackUvec2x16(tiles.tiles_coord_buf[group_id.x]);
762 int2 texel = int2(local_id.xy + tile_coord * tile_size);
763
764 int2 texel_fullres = texel * uni.raytrace_buf.fast_gi_resolution_scale +
765 uni.raytrace_buf.fast_gi_resolution_bias;
766
767 /* Avoid tracing the outside border if dispatch is too big. */
768 int2 extent = textureSize(reader.gbuf_header_tx, 0).xy;
769
770 /* Avoid loading texels outside texture range.
771 * This can happen even after the check above in non-power-of-2 textures. */
772 texel_fullres = min(texel_fullres, extent - 1);
773
774 /* Do not trace where nothing was rendered. */
775 if (texelFetch(reader.gbuf_header_tx, int3(texel_fullres, 0), 0).r == 0u) {
776#if 0 /* This is not needed as the next stage doesn't do bilinear filtering. */
777 imageStore(fast_gi_radiance_0_img, texel, float4(0.0f));
778 imageStore(fast_gi_radiance_1_img, texel, float4(0.0f));
779 imageStore(fast_gi_radiance_2_img, texel, float4(0.0f));
780 imageStore(fast_gi_radiance_3_img, texel, float4(0.0f));
781#endif
782 return;
783 }
784
785 const ViewMatrices view = views.get(0);
786
787 float2 uv = (float2(texel_fullres) + 0.5f) * uni.raytrace_buf.full_resolution_inv;
788 float depth = texelFetch(hiz.hiz_tx, texel_fullres, 0).r;
789 float3 vP = view.point_screen_to_view(float3(uv, depth));
790 float3 vN = texelFetch(srt.screen_normal_tx, texel, 0).rgb * 2.0f - 1.0f;
791
792 float4 noise = util_tx.fetch(float2(texel), UTIL_BLUE_NOISE_LAYER);
793 noise = fract(noise + sampling.rng_3D_get(SAMPLING_AO_U).xyzx);
794
796 uni,
797 view,
798 uni.raytrace_buf.fast_gi_thickness,
799 hiz.hiz_tx,
800 srt.screen_radiance_tx,
801 srt.screen_normal_tx,
802 vP,
803 vN,
804 noise,
805 uni.uniform_buf.ao.pixel_size,
806 uni.uniform_buf.ao.gi_distance,
807 uni.uniform_buf.ao.angle_bias,
808 constants.slice_count,
809 constants.step_count,
810 false,
811 constants.ao_only);
812
813 sh_out.write(texel, result);
814}
815
817
818/* -------------------------------------------------------------------- */
821
822[[metal_max_total_threads_per_threadgroup(400)]] /* Tweak performance on metal. */
823[[compute]] [[local_size(RAYTRACE_GROUP_SIZE, RAYTRACE_GROUP_SIZE)]]
824void denoise([[work_group_id]] const uint3 group_id,
825 [[local_invocation_id]] const uint3 local_id,
826 [[resource_table]] SampleInput &sh_in,
827 [[resource_table]] SampleOutput &sh_out,
828 [[resource_table]] const HiZ &hiz,
829 [[resource_table]] const Uniform &uni,
830 [[resource_table]] const draw::View &views,
832{
833 constexpr uint tile_size = uint(RAYTRACE_GROUP_SIZE);
834 uint2 tile_coord = unpackUvec2x16(tiles.tiles_coord_buf[group_id.x]);
835 int2 texel = int2(local_id.xy + tile_coord * tile_size);
836
837 float2 texel_size = 1.0f / float2(textureSize(sh_in.fast_gi_radiance_0_tx, 0).xy);
838 int2 texel_fullres = texel * uni.raytrace_buf.fast_gi_resolution_scale +
839 uni.raytrace_buf.fast_gi_resolution_bias;
840
841 bool is_valid;
842 float center_depth = texelFetch(hiz.hiz_tx, texel_fullres, 0).r;
843 float2 center_uv = float2(texel) * texel_size;
844 float3 center_P = views.get(0).point_screen_to_world(float3(center_uv, center_depth));
845 float3 center_N = sh_in.sample_normal_get(views, texel, is_valid);
846
847 if (!is_valid) {
848#if 0 /* This is not needed as the next stage doesn't do bilinear filtering. */
849 imageStore(sh_out.sh_0_img, texel, float4(0.0f));
850 imageStore(sh_out.sh_1_img, texel, float4(0.0f));
851 imageStore(sh_out.sh_2_img, texel, float4(0.0f));
852 imageStore(sh_out.sh_3_img, texel, float4(0.0f));
853#endif
854 return;
855 }
856
857 SphericalHarmonicL1<float4> accum_sh = {};
858 float accum_weight = 0.0f;
859 /* 3x3 filter. */
860 for (int y = -1; y <= 1; y++) {
861 for (int x = -1; x <= 1; x++) {
862 int2 sample_offset = int2(x, y);
863 int2 sample_texel = texel + sample_offset;
864 float2 sample_uv = (float2(sample_texel) + 0.5f) * texel_size;
865 float sample_weight = sh_in.sample_weight_get(
866 uni, views, hiz.hiz_tx, center_N, center_P, sample_texel, sample_uv, sample_offset);
867 /* We need to avoid sampling if there no weight as the texture values could be undefined
868 * (is_valid is false). */
869 if (sample_weight > 0.0f) {
870 SphericalHarmonicL1<float4> sample_sh = sh_in.load_sh(sample_texel);
871 accum_sh = spherical_harmonics::madd(sample_sh, sample_weight, accum_sh);
872 accum_weight += sample_weight;
873 }
874 }
875 }
876 accum_sh = spherical_harmonics::mul(accum_sh, safe_rcp(accum_weight));
877 sh_out.write(texel, accum_sh);
878}
879
881
882/* -------------------------------------------------------------------- */
885
891
892[[metal_max_total_threads_per_threadgroup(400)]] /* Tweak performance on metal. */
893[[compute]] [[local_size(RAYTRACE_GROUP_SIZE, RAYTRACE_GROUP_SIZE)]]
894void resolve([[work_group_id]] const uint3 group_id,
895 [[local_invocation_id]] const uint3 local_id,
896 [[resource_table]] const Tiles &tiles,
897 [[resource_table]] const SampleInput &sh_in,
898 [[resource_table]] Resolve &srt,
899 [[resource_table]] const gbuffer::Reader &reader,
900 [[resource_table]] const Uniform &uni,
901 [[resource_table]] const draw::View &views,
902 [[resource_table]] const LightprobeRenderData &lightprobes)
903{
904 constexpr uint tile_size = uint(RAYTRACE_GROUP_SIZE);
905 uint2 tile_coord = unpackUvec2x16(tiles.tiles_coord_buf[group_id.x]);
906 int2 texel_fullres = int2(local_id.xy + tile_coord * tile_size);
907
908 int2 texel = max(int2(0), texel_fullres - uni.raytrace_buf.fast_gi_resolution_bias) /
909 uni.raytrace_buf.fast_gi_resolution_scale;
910
911 int2 extent = textureSize(reader.gbuf_header_tx, 0).xy;
912 if (any(greaterThanEqual(texel_fullres, extent))) {
913 return;
914 }
915
916 const gbuffer::Layers gbuf = reader.read_layers(texel_fullres);
917
918 if (gbuf.header.is_empty()) {
919 return;
920 }
921 const ViewMatrices view = views.get(0);
922
923 float2 center_uv = (float2(texel_fullres) + 0.5f) * uni.raytrace_buf.full_resolution_inv;
924 float center_depth = reverse_z::read(texelFetch(sh_in.depth_tx, texel_fullres, 0).r);
925 float3 center_P = view.point_screen_to_world(float3(center_uv, center_depth));
926 float3 center_N = gbuf.surface_N();
927
929 if (uni.raytrace_buf.fast_gi_resolution_scale == 1) {
930 accum_sh = sh_in.load_sh(texel, true);
931 }
932 else {
933 float2 interp = float2(texel_fullres - texel * uni.raytrace_buf.fast_gi_resolution_scale -
934 uni.raytrace_buf.fast_gi_resolution_bias) /
935 float2(uni.raytrace_buf.fast_gi_resolution_scale);
936 float4 interp4 = float4(interp, 1.0f - interp);
937 float4 bilinear_weight = interp4.zxzx * interp4.wwyy;
938
939 float4 bilateral_weights;
940 bilateral_weights.x = sh_in.sample_weight_get(
941 uni, views, center_N, center_P, texel, int2(0, 0));
942 bilateral_weights.y = sh_in.sample_weight_get(
943 uni, views, center_N, center_P, texel, int2(1, 0));
944 bilateral_weights.z = sh_in.sample_weight_get(
945 uni, views, center_N, center_P, texel, int2(0, 1));
946 bilateral_weights.w = sh_in.sample_weight_get(
947 uni, views, center_N, center_P, texel, int2(1, 1));
948
949 float4 weights = bilateral_weights * bilinear_weight;
950
951 SphericalHarmonicL1<float4> sh_00 = sh_in.load_sh(texel + int2(0, 0), weights.x > 0.0f);
952 SphericalHarmonicL1<float4> sh_10 = sh_in.load_sh(texel + int2(1, 0), weights.y > 0.0f);
953 SphericalHarmonicL1<float4> sh_01 = sh_in.load_sh(texel + int2(0, 1), weights.z > 0.0f);
954 SphericalHarmonicL1<float4> sh_11 = sh_in.load_sh(texel + int2(1, 1), weights.w > 0.0f);
955
956 /* Avoid another division at the end. Normalize the weights upfront. */
957 weights *= safe_rcp(reduce_add(weights));
958
959 accum_sh = spherical_harmonics::mul(sh_00, weights.x);
960 accum_sh = spherical_harmonics::madd(sh_10, weights.y, accum_sh);
961 accum_sh = spherical_harmonics::madd(sh_01, weights.z, accum_sh);
962 accum_sh = spherical_harmonics::madd(sh_11, weights.w, accum_sh);
963 }
964
965 accum_sh = spherical_harmonics::rotate(to_float3x3(view.viewinv), accum_sh);
966
967 float3 P = center_P;
968 float3 Ng = center_N;
970
971 LightProbeSample samp = lightprobes.load(float2(texel_fullres), P, Ng, V);
972
973 float clamp_indirect = uni.uniform_buf.clamp.surface_indirect;
975 clamp_indirect);
976
977 const uchar closure_count = gbuf.header.closure_len();
978 const uint3 bin_indices = gbuf.header.bin_index_per_layer();
979 const Thickness thickness = reader.read_thickness(gbuf.header, texel_fullres);
980
981 /* Unroll needed for gbuf.layer access. */
982 for (int i = 0; i < 3 /* GBUFFER_LAYER_MAX */; i++) [[unroll]] {
983 if (i < closure_count) {
984 ClosureUndetermined cl = gbuf.layer[i];
985
986 float roughness = closure_apparent_roughness_get(cl);
987
988 float mix_fac = saturate(roughness * uni.raytrace_buf.roughness_mask_scale -
989 uni.raytrace_buf.roughness_mask_bias);
990 bool use_raytrace = mix_fac < 1.0f;
991 bool use_fast_gi = mix_fac > 0.0f;
992
993 if (use_fast_gi) {
995
997
998 /* Evaluate lighting from fast GI scan. */
999 float4 radiance_with_visibility = accum_sh.evaluate_lambert(L);
1000 float3 radiance = radiance_with_visibility.xyz;
1001 /* Evaluate occlusion from fast GI scan. */
1002 /* The energy amount from the visibility factor is supposed to be a pure lambertian
1003 * visibility (which integrate to PI over the hemisphere). However, the tracing step weight
1004 * the incoming radiance by 4 PI (and with it the visibility). So the expected computation
1005 * should be `accum_sh.evaluate(L).w / 4.0f`. But in order to save some complexity, we
1006 * approximate using the `evaluate_lambert` version even if not completely correct (max 3%
1007 * errors). */
1008 float distant_radiance_visibility = saturate(radiance_with_visibility.w / 3.0f);
1009
1010 if (closure_has_transmission(cl.type)) {
1011 /* We only recorded visibility and radiance for the upper hemisphere.
1012 * Discard result for transmission closures. */
1013 distant_radiance_visibility = 1.0f;
1014 radiance = float3(0.0);
1015 }
1016
1017 /* Apply missing distant lighting. */
1018 radiance += distant_radiance_visibility * samp.volume_irradiance.evaluate_lambert(L).rgb;
1019
1020 uchar layer_index = bin_indices[i];
1021
1022 float4 radiance_fast_gi = float4(radiance, 0.0f);
1023 float4 radiance_raytrace = float4(0.0f);
1024 if (use_raytrace) {
1025 /* TODO(fclem): Layered texture. */
1026 if (layer_index == 0u) {
1027 radiance_raytrace = imageLoad(srt.closure0_img, texel_fullres);
1028 }
1029 else if (layer_index == 1u) {
1030 radiance_raytrace = imageLoad(srt.closure1_img, texel_fullres);
1031 }
1032 else if (layer_index == 2u) {
1033 radiance_raytrace = imageLoad(srt.closure2_img, texel_fullres);
1034 }
1035 }
1036 float4 radiance_mixed = mix(radiance_raytrace, radiance_fast_gi, mix_fac);
1037
1038 /* TODO(fclem): Layered texture. */
1039 if (layer_index == 0u) {
1040 imageStore(srt.closure0_img, texel_fullres, radiance_mixed);
1041 }
1042 else if (layer_index == 1u) {
1043 imageStore(srt.closure1_img, texel_fullres, radiance_mixed);
1044 }
1045 else if (layer_index == 2u) {
1046 imageStore(srt.closure2_img, texel_fullres, radiance_mixed);
1047 }
1048 }
1049 }
1050 }
1051}
1052
1053} // namespace fast_gi
1054
1059
1061
1062/* -------------------------------------------------------------------- */
1065
1078
1081 [[resource_table]] const Sampling &sampling,
1082 [[resource_table]] const UtilityTexture &util_tx,
1083 [[resource_table]] const Uniform &uni,
1084 [[resource_table]] const draw::View &views,
1085 [[resource_table]] const HiZ &hiz,
1086 [[resource_table]] AOPass &srt)
1087{
1088 int2 texel = int2(global_id.xy);
1089 int2 extent = imageSize(srt.in_normal_img).xy;
1090 if (any(greaterThanEqual(texel, extent))) {
1091 return;
1092 }
1093
1094 float2 uv = (float2(texel) + float2(0.5f)) / float2(extent);
1095 float depth = texelFetch(hiz.hiz_tx, texel, 0).r;
1096
1097 if (depth == 1.0f) {
1098 /* Do not trace for background */
1099 imageStoreFast(srt.out_ao_img, int3(texel, srt.out_ao_img_layer_index), float4(0.0f));
1100 return;
1101 }
1102
1103 const ViewMatrices view = views.get(0);
1104
1105 float3 vP = view.point_screen_to_view(float3(uv, depth));
1106 float3 N = imageLoad(srt.in_normal_img, int3(texel, srt.in_normal_img_layer_index)).xyz;
1107 float3 vN = view.normal_world_to_view(N);
1108
1109 float4 noise = util_tx.fetch(float2(texel), UTIL_BLUE_NOISE_LAYER);
1110 noise = fract(noise + sampling.rng_3D_get(SAMPLING_AO_U).xyzx);
1111
1112 float result = eevee::fast_gi::eval<float>(uni,
1113 view,
1114 uni.raytrace_buf.fast_gi_thickness,
1115 hiz.hiz_tx,
1116 srt.dummy_tx,
1117 srt.dummy_tx,
1118 vP,
1119 vN,
1120 noise,
1121 uni.uniform_buf.ao.pixel_size,
1122 uni.uniform_buf.ao.distance,
1123 uni.uniform_buf.ao.angle_bias,
1124 srt.ao_slice_count,
1125 srt.ao_step_count,
1126 false,
1127 true);
1128
1130 srt.out_ao_img, int3(texel, srt.out_ao_img_layer_index), float4(saturate(result)));
1131}
1132
1134
1136
1137} // namespace eevee
#define M_1_PI
#define M_PI_2
#define M_TAU
#define M_PI
btScalar max
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
float closure_apparent_roughness_get(ClosureUndetermined cl)
LightProbeRay bxdf_lightprobe_ray(ClosureUndetermined cl, float3, float3 V, Thickness thickness)
#define RAYTRACE_RADIANCE_FORMAT
#define UTIL_BLUE_NOISE_LAYER
#define AMBIENT_OCCLUSION_PASS_TILE_SIZE
float2 sample_circle(float rand)
@ SFLOAT_16_16_16_16
#define shared
#define metal_max_total_threads_per_threadgroup(count)
#define storage(slot, qualifiers)
#define image(slot, qualifiers, format)
#define work_group_id
#define push_constant
#define resource_table
#define sampler(slot)
#define specialization_constant(default_value)
#define global_invocation_id
#define local_invocation_id
#define unroll
#define compute
#define local_size(...)
VecBase< bool, D > greaterThanEqual(VecOp< T, D >, VecOp< T, D >) RET
T fract(T) RET
bool any(VecOp< bool, D >) RET
#define cos
VecBase< float, D > normalize(VecOp< float, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
#define log2
constexpr T sign(T) RET
#define abs
#define floor
#define ceil
bool all(VecOp< bool, D >) RET
VecBase< int, D > bitCount(VecOp< int, D >) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
VecBase< bool, D > equal(VecOp< T, D >, VecOp< T, D >) RET
void barrier()
constexpr T clamp(T, U, U) RET
IMG_TEMPLATE DataVec imageLoad(const T &, IntCoord) RET
ImageBase< float, 2, true > image2DArray
ImageBase< float, 2 > image2D
IMG_TEMPLATE SizeVec imageSize(const T &) RET
#define imageStoreFast
IMG_TEMPLATE void imageStore(T &, IntCoord, DataVec)
TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) RET
TEX_TEMPLATE DataVec textureLod(T, FltCoord, float) RET
SamplerBase< float, 2, false, false, false, true > sampler2DDepth
SamplerBase< float, 2 > sampler2D
TEX_TEMPLATE SizeVec textureSize(T, int) RET
unsigned int uchar
float noise(float p)
float square(float v)
float sqrt_fast(float v)
float acos_fast(float v)
float2 project_point(float3x3 mat, float2 point)
float safe_rcp(float a)
VecT normalize_and_get_length(VecT vector, float &out_length)
float length_squared(VecT a)
VecT orthogonal(VecT v)
float reduce_add(float2 a)
uint2 unpackUvec2x16(uint a)
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
ccl_device_inline float interp(const float a, const float b, const float t)
Definition math_base.h:549
#define N
#define T
#define B
#define L
float3 brightness_clamp_max(float3 color, float limit)
float bitmask_to_occlusion_uniform(uint bitmask)
void resolve(const uint3 group_id, const uint3 local_id, const Tiles &tiles, const SampleInput &sh_in, Resolve &srt, const gbuffer::Reader &reader, const Uniform &uni, const draw::View &views, const LightprobeRenderData &lightprobes)
float3 sample_radiance(sampler2D, float2, float)
float bitmask_to_occlusion_cosine(uint bitmask)
void denoise(const uint3 group_id, const uint3 local_id, SampleInput &sh_in, SampleOutput &sh_out, const HiZ &hiz, const Uniform &uni, const draw::View &views, Tiles &tiles)
uint angles_to_bitmask(float2 theta)
void projected_normal_to_plane_angle_and_length(float3 N, float3 V, float3 T, float3 B, float &N_proj_len, float &N_angle)
float bitmask_to_visibility_uniform(uint bitmask)
template float eval< float >(const Uniform &, const ViewMatrices, ScreenThicknessParameters, sampler2D, sampler2D, sampler2D, float3, float3, float4, float2, float, float, int, int, bool, bool)
void setup(const uint3 global_id, const uint3 local_id, const gbuffer::Reader &reader, const Uniform &uni, const draw::View &views, Setup &srt)
T select_result(float, SphericalHarmonicL1< float4 >)
ResultT eval(const Uniform &uni, const ViewMatrices view, ScreenThicknessParameters thickness_params, sampler2D hiz_tx, sampler2D screen_radiance_tx, sampler2D screen_normal_tx, float3 vP, float3 vN, float4 noise, float2 pixel_size, float search_distance, float angle_bias, const int slice_count, const int sample_count, const bool reversed, const bool ao_only)
void scan(const uint3 group_id, const uint3 local_id, Scan &srt, const Tiles &tiles, const Sampling &sampling, const UtilityTexture &util_tx, const HiZ &hiz, const gbuffer::Reader &reader, const Uniform &uni, const draw::View &views, SampleOutput &sh_out, Constants &constants)
float3 sample_normal(sampler2D, float2, float)
PipelineCompute ambient_occlusion_pass(occlusion_pass)
PipelineCompute fast_gi_setup(fast_gi::setup)
PipelineCompute fast_gi_resolve(fast_gi::resolve)
void occlusion_pass(const uint3 global_id, const Sampling &sampling, const UtilityTexture &util_tx, const Uniform &uni, const draw::View &views, const HiZ &hiz, AOPass &srt)
PipelineCompute fast_gi_denoise(fast_gi::denoise)
PipelineCompute fast_gi_scan(fast_gi::scan)
float gaussian_factor(float linear_distance, float standard_deviation)
float angle_weight(float3 center_N, float3 sample_N)
float gaussian_weight(float factor, float square_distance)
float planar_weight(float3 plane_N, float3 plane_P, float3 P, float scale)
T read(T depth_buffer_value)
SphericalHarmonicL1< float4 > mul(SphericalHarmonicL1< float4 > a, float b)
SphericalHarmonicL1< float4 > clamp_energy(SphericalHarmonicL1< float4 > sh, float clamp_value)
SphericalHarmonicL1< float4 > rotate(float3x3 rotation, SphericalHarmonicL1< float4 > sh)
SphericalHarmonicL1< float4 > compress(SphericalHarmonicL1< float4 > sh)
SphericalHarmonicL1< float4 > madd(SphericalHarmonicL1< float4 > a, float b, SphericalHarmonicL1< float4 > c)
SphericalHarmonicL1< float4 > decompress(SphericalHarmonicL1< float4 > sh)
#define mix
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define saturate(a)
Definition smaa.cc:319
#define min(a, b)
Definition sort.cc:38
packed_float3 dominant_direction
float max_time
packed_float3 direction
packed_float3 origin
static ScreenSpaceRay create(ViewMatrices view, Ray ray, float2 pixel_size)
static ScreenThicknessEstimator init(float start_z)
float thickness(float sample_ss_z, float sample_ss_t, float sample_min_thickness)
spherical_harmonics::BandL1< T > L1
spherical_harmonics::BandL0< T > L0
void encode_signal_sample(float3 direction, T amplitude)
float depth_screen_to_view(float ss_depth) const
T ndc_to_screen(T ndc_P) const
float3 point_screen_to_world(float3 ssP) const
float3 view_incident_vector(float3 vP) const
float3 world_incident_vector(float3 P) const
float3 point_screen_to_view(float3 ssP) const
ViewMatrices get(uint view_id) const
const sampler2D dummy_tx
image2DArray out_ao_img
const int out_ao_img_layer_index
image2DArray in_normal_img
const int in_normal_img_layer_index
SphericalHarmonicL1< float4 > volume_irradiance
const RayTraceData & raytrace_buf
const UniformData & uniform_buf
float3 sample_normal_get(const draw::View &views, int2 texel, bool &is_processed) const
SphericalHarmonicL1< float4 > load_sh(int2 texel) const
float sample_weight_get(const Uniform &uni, const draw::View &views, float3 center_N, float3 center_P, int2 center_texel, int2 sample_offset) const
SphericalHarmonicL1< float4 > load_sh(int2 texel, bool valid) const
float sample_weight_get(const Uniform &uni, const draw::View &views, sampler2D hiz_tx, float3 center_N, float3 center_P, int2 sample_texel, float2 sample_uv, int2 sample_offset) const
void write(int2 texel, SphericalHarmonicL1< float4 > result)
const sampler2D screen_radiance_tx
const sampler2D screen_normal_tx
float3 neigbhor_data[RAYTRACE_GROUP_SIZE][RAYTRACE_GROUP_SIZE]
const sampler2DDepth depth_tx
const sampler2D in_radiance_tx
const uint(& tiles_coord_buf)[]
float x
float y
float z
Definition sky_math.h:136
float y
Definition sky_math.h:225
float z
Definition sky_math.h:225
float x
Definition sky_math.h:225
float w
Definition sky_math.h:225
uint3 bin_index_per_layer() const
ClosureUndetermined layer[GBUFFER_LAYER_MAX]
CCL_NAMESPACE_BEGIN struct Window V