2023-10-08 00:29:06 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
|
|
2024-10-04 15:48:22 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2023-10-08 00:29:06 +02:00
|
|
|
/**
|
|
|
|
|
* Various utilities related to object subsurface light transport.
|
|
|
|
|
*
|
|
|
|
|
* Required resources:
|
|
|
|
|
* - utility_tx
|
|
|
|
|
*/
|
|
|
|
|
|
2025-09-25 10:57:02 +02:00
|
|
|
#include "infos/eevee_common_infos.hh"
|
2024-12-02 21:26:15 +01:00
|
|
|
|
2025-09-12 14:09:35 +02:00
|
|
|
#include "eevee_utility_tx_lib.glsl"
|
|
|
|
|
#include "gpu_shader_utildefines_lib.glsl"
|
2024-05-08 20:09:50 +02:00
|
|
|
|
2023-10-08 00:29:06 +02:00
|
|
|
float subsurface_transmittance_profile(float u)
|
|
|
|
|
{
|
2025-09-12 14:09:35 +02:00
|
|
|
auto &utility_tx = sampler_get(eevee_utility_texture, utility_tx);
|
2025-04-14 13:46:41 +02:00
|
|
|
return utility_tx_sample(utility_tx, float2(u, 0.0f), UTIL_SSS_TRANSMITTANCE_PROFILE_LAYER).r;
|
2023-10-08 00:29:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the amount of light that can travels through a uniform medium and exit at the backface.
|
|
|
|
|
*/
|
2025-04-14 13:46:41 +02:00
|
|
|
float3 subsurface_transmission(float3 sss_radii, float thickness)
|
2023-10-08 00:29:06 +02:00
|
|
|
{
|
|
|
|
|
sss_radii *= SSS_TRANSMIT_LUT_RADIUS;
|
2025-04-14 13:46:41 +02:00
|
|
|
float3 channels_co = saturate(thickness / sss_radii) * SSS_TRANSMIT_LUT_SCALE +
|
|
|
|
|
SSS_TRANSMIT_LUT_BIAS;
|
|
|
|
|
float3 translucency;
|
2025-04-11 18:28:45 +02:00
|
|
|
translucency.x = (sss_radii.x > 0.0f) ? subsurface_transmittance_profile(channels_co.x) : 0.0f;
|
|
|
|
|
translucency.y = (sss_radii.y > 0.0f) ? subsurface_transmittance_profile(channels_co.y) : 0.0f;
|
|
|
|
|
translucency.z = (sss_radii.z > 0.0f) ? subsurface_transmittance_profile(channels_co.z) : 0.0f;
|
2023-10-08 00:29:06 +02:00
|
|
|
return translucency;
|
|
|
|
|
}
|