Blender V5.3
eevee_lightprobe_plane.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
5#pragma once
6
7#include "eevee_defines.hh"
9
11
13{
14 /* Compute distorted reflection vector based on the distance to the reflected object.
15 * In other words find intersection between reflection vector and the sphere center
16 * around point_on_plane. */
17 float3 proj_ref = reflect(-V, N) * planar.parallax_distance;
18 /* Then reflect around the planar probe normal plane to get the final position on screen. */
19 return P + reflect(proj_ref, planar.normal);
20}
21
22} // namespace eevee::lightprobe::plane
23
24namespace eevee {
25
27 [[uniform(PLANAR_PROBE_BUF_SLOT)]] PlanarProbeData (&probe_planar_buf)[PLANAR_PROBE_MAX];
30
35 {
36 float best_score = 0.0;
37 int best_index = -1;
38
39 for (int index = 0; index < PLANAR_PROBE_MAX; index++) {
40 if (probe_planar_buf[index].layer_id == -1) {
41 /* PlanarProbeData doesn't contain any gap, exit at first item that is invalid. */
42 break;
43 }
44 float score = probe_score(probe_planar_buf[index], P, N);
45 if (score > best_score) {
46 best_score = score;
47 best_index = index;
48 }
49 }
50 return best_index;
51 }
52
53 private:
54 static float distance_score(PlanarProbeData planar, float3 P)
55 {
56 float3 lP = float4(P, 1.0f) * planar.world_to_object_transposed;
57 /* TODO: Transition in Z. Dither? */
58 return float(all(lessThan(abs(lP), float3(1.0f))));
59 }
60
61 static float probe_score(PlanarProbeData planar, float3 P, float3 N)
62 {
63 return saturate(dot(N, planar.normal)) * distance_score(planar, P);
64 }
65};
66
67} // namespace eevee
#define PLANAR_PROBE_DEPTH_TEX_SLOT
#define PLANAR_PROBE_RADIANCE_TEX_SLOT
#define PLANAR_PROBE_BUF_SLOT
#define uniform(slot)
#define index(i)
#define sampler(slot)
VecBase< T, D > reflect(VecOp< T, D >, VecOp< T, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
#define abs
bool all(VecOp< bool, D >) RET
VecBase< bool, D > lessThan(VecOp< T, D >, VecOp< T, D >) RET
SamplerBase< float, 2, false, true, false, true > sampler2DArrayDepth
SamplerBase< float, 2, false, true > sampler2DArray
#define N
float3 parallax(PlanarProbeData planar, float3 P, float3 N, float3 V)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define saturate(a)
Definition smaa.cc:319
PlanarProbeData(& probe_planar_buf)[PLANAR_PROBE_MAX]
int select_probe(float3 P, float3 N) const
CCL_NAMESPACE_BEGIN struct Window V