2023-08-24 10:54:59 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2023-08-03 15:32:06 +02:00
|
|
|
|
2024-10-04 15:48:22 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2025-09-25 10:57:02 +02:00
|
|
|
#include "infos/eevee_common_infos.hh"
|
2024-12-02 21:26:15 +01:00
|
|
|
|
2023-08-03 15:32:06 +02:00
|
|
|
/**
|
|
|
|
|
* BxDF evaluation functions.
|
2023-08-19 17:13:05 +10:00
|
|
|
*/
|
2023-08-03 15:32:06 +02:00
|
|
|
|
2024-05-25 23:40:12 +02:00
|
|
|
struct BsdfSample {
|
2024-11-12 12:58:58 +01:00
|
|
|
packed_float3 direction;
|
2024-05-25 23:40:12 +02:00
|
|
|
float pdf;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct BsdfEval {
|
|
|
|
|
float throughput;
|
|
|
|
|
float pdf;
|
2024-10-10 00:07:32 +02:00
|
|
|
/* `throughput / pdf`. */
|
|
|
|
|
float weight;
|
2024-05-25 23:40:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ClosureLight {
|
|
|
|
|
/* LTC matrix. */
|
2024-11-12 12:58:58 +01:00
|
|
|
packed_float4 ltc_mat;
|
2024-05-25 23:40:12 +02:00
|
|
|
/* Shading normal. */
|
2024-11-12 12:58:58 +01:00
|
|
|
packed_float3 N;
|
2024-05-25 23:40:12 +02:00
|
|
|
/* Enum used as index to fetch which light intensity to use [0..3]. */
|
|
|
|
|
LightingType type;
|
|
|
|
|
/* Output both shadowed and unshadowed for shadow denoising. */
|
2024-11-12 12:58:58 +01:00
|
|
|
packed_float3 light_shadowed;
|
|
|
|
|
packed_float3 light_unshadowed;
|
2025-09-12 14:09:35 +02:00
|
|
|
|
|
|
|
|
METAL_CONSTRUCTOR_5(ClosureLight,
|
|
|
|
|
packed_float4,
|
|
|
|
|
ltc_mat,
|
|
|
|
|
packed_float3,
|
|
|
|
|
N,
|
|
|
|
|
LightingType,
|
|
|
|
|
type,
|
|
|
|
|
packed_float3,
|
|
|
|
|
light_shadowed,
|
|
|
|
|
packed_float3,
|
|
|
|
|
light_unshadowed)
|
|
|
|
|
|
|
|
|
|
static ClosureLight zero()
|
|
|
|
|
{
|
|
|
|
|
return ClosureLight(float4(0), float3(0), LIGHT_DIFFUSE, float3(0), float3(0));
|
|
|
|
|
}
|
2024-05-25 23:40:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Represent an approximation of a bunch of rays from a BSDF. */
|
|
|
|
|
struct LightProbeRay {
|
|
|
|
|
/* Average direction of sampled rays or its approximation.
|
2024-05-27 12:07:03 +10:00
|
|
|
* Magnitude will reduce directionality of spherical harmonic evaluation. */
|
2024-11-12 12:58:58 +01:00
|
|
|
packed_float3 dominant_direction;
|
2024-05-25 23:40:12 +02:00
|
|
|
/* Perceptual roughness in [0..1] range.
|
|
|
|
|
* Modulate blur level of spherical probe and blend between sphere probe and spherical harmonic
|
|
|
|
|
* evaluation at higher roughness. */
|
|
|
|
|
float perceptual_roughness;
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-03 13:33:38 +02:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Utils
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
/* Fresnel monochromatic, perfect mirror */
|
|
|
|
|
float F_eta(float eta, float cos_theta)
|
|
|
|
|
{
|
|
|
|
|
/* Compute fresnel reflectance without explicitly computing
|
|
|
|
|
* the refracted direction. */
|
|
|
|
|
float c = abs(cos_theta);
|
2025-04-11 18:28:45 +02:00
|
|
|
float g = eta * eta - 1.0f + c * c;
|
|
|
|
|
if (g > 0.0f) {
|
2023-09-03 13:33:38 +02:00
|
|
|
g = sqrt(g);
|
|
|
|
|
float A = (g - c) / (g + c);
|
2025-04-11 18:28:45 +02:00
|
|
|
float B = (c * (g + c) - 1.0f) / (c * (g - c) + 1.0f);
|
|
|
|
|
return 0.5f * A * A * (1.0f + B * B);
|
2023-09-03 13:33:38 +02:00
|
|
|
}
|
|
|
|
|
/* Total internal reflections. */
|
2025-04-11 18:28:45 +02:00
|
|
|
return 1.0f;
|
2023-09-03 13:33:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|