19 SphereProbePixelArea unpacked;
20 unpacked.offset = packed_coord.xy;
21 unpacked.extent = packed_coord.
z;
22 unpacked.layer = packed_coord.
w;
28 SphereProbeUvArea unpacked;
46 sampling_uv = local_texel /
float2(texel_area.extent - 2);
63 int mip_0_res = int(
float(SPHERE_PROBE_ATLAS_RES) * uv_area.scale + 0.5f);
64 float mip_lvl_res =
float(mip_0_res >>
int(mip_lvl));
65 float mip_lvl_res_inv = 1.0f / mip_lvl_res;
70 float scale = (mip_lvl_res - 2.0f) * mip_lvl_res_inv;
71 float offset = 0.5f * mip_lvl_res_inv;
72 return uv *
scale + offset;
78 SphereProbeUvArea uv_area,
88 altas_uv_min = local_uv_min * uv_area.scale + uv_area.offset;
89 altas_uv_max = local_uv_max * uv_area.scale + uv_area.offset;
95 float2 altas_uv_min, altas_uv_max_unused;
102 constexpr float scale = 1.0f /
103 (SPHERE_PROBE_MIX_END_ROUGHNESS - SPHERE_PROBE_MIX_START_ROUGHNESS);
104 constexpr float bias =
scale * SPHERE_PROBE_MIX_START_ROUGHNESS;
112 float ratio =
saturate(roughness / SPHERE_PROBE_MIP_MAX_ROUGHNESS);
115 float mip_ratio =
mix(ratio, ratio_sqrt, 0.4f);
116 return mip_ratio *
float(SPHERE_PROBE_MIPMAP_LEVELS - 1);
123 float mip_ratio = lod /
float(SPHERE_PROBE_MIPMAP_LEVELS - 1);
125 constexpr float b = 0.6f;
126 constexpr float c = 0.4f;
131 float ratio = (-
sqrt(4.0f * a *
b * c2 + c4) + 2.0f * a *
b + c2) / (2.0f * b2);
132 return ratio * SPHERE_PROBE_MIP_MAX_ROUGHNESS;
138 bool is_world = (probe.influence_scale == 0.0f);
143 float3 lP =
float4(
P, 1.0f) * probe.world_to_probe_transposed;
144 float3 lL = (
L * to_float3x3(probe.world_to_probe_transposed)) / probe.parallax_distance;
146 float dist = (probe.parallax_shape == SHAPE_ELLIPSOID) ?
152 float3 L_new =
P +
L * dist - probe.location;
162 ReflectionProbeLowFreqLight result;
163 result.ambient = sh.
L0.M0.r + sh.
L0.M0.g + sh.
L0.M0.b;
165 result.ambient += 1e-6f;
168 L1_per_band[0] = sh.
L1.Mn1;
169 L1_per_band[1] = sh.
L1.M0;
170 L1_per_band[2] = sh.
L1.Mp1;
173 result.direction = L1_per_comp[0] + L1_per_comp[1] + L1_per_comp[2];
179 ReflectionProbeLowFreqLight numerator,
180 ReflectionProbeLowFreqLight denominator)
184 return saturate(numerator.ambient / denominator.ambient);
205 if (probe_data.atlas_coord.layer == -1.0f) {
211 float3 lP =
float4(
P, 1.0f) * probe_data.world_to_probe_transposed;
212 float gradient = (probe_data.influence_shape == SHAPE_ELLIPSOID) ?
215 float score =
saturate(probe_data.influence_bias - gradient * probe_data.influence_scale);
216 if (score > random_probe) {
221 return SPHERE_PROBE_MAX - 1;
226 float lod_min =
floor(lod);
227 float lod_max =
ceil(lod);
228 float mix_fac = lod - lod_min;
230 float2 altas_uv_min, altas_uv_max;
237 return mix(color_min, color_max, mix_fac);
253 L, shading_sh, probe.low_freq_light);
255 return normalization_fac * this->
sample_probe(
L, lod, probe.atlas_coord).rgb;
float line_unit_sphere_intersect_dist(float3 line_origin, float3 line_direction)
float line_unit_box_intersect_dist(float3 line_origin, float3 line_direction)
#define SPHERE_PROBE_TEX_SLOT
#define SPHERE_PROBE_BUF_SLOT
float2 octahedral_uv_from_direction(float3 co)
float3 octahedral_uv_to_direction(float2 co)
VecBase< float, D > intBitsToFloat(VecOp< int, D >) RET
MatBase< R, C > transpose(MatBase< C, R >) RET
float length(VecOp< float, D >) RET
TEX_TEMPLATE DataVec textureLod(T, FltCoord, float) RET
SamplerBase< float, 2, false, true > sampler2DArray
float3x3 scale(float3x3 mat, float2 scale)
MatBase< float, 3, 4 > float3x4
ReflectionProbeLowFreqLight extract_low_freq_lighting(SphericalHarmonicL1< float4 > sh)
float normalization_factor(float3, ReflectionProbeLowFreqLight numerator, ReflectionProbeLowFreqLight denominator)
float lod_to_roughness(float lod)
float3 texel_to_direction(float2 local_texel, SphereProbePixelArea texel_area, float2 &sampling_uv)
float roughness_to_lod(float roughness)
float2 miplvl_scale_bias(float mip_lvl, SphereProbeUvArea uv_area, float2 uv)
float roughness_to_mix_fac(float roughness)
float3 parallax_eval(SphereProbeData probe, float3 P, float3 L)
void direction_to_uv(float3 L, float lod_min, float lod_max, SphereProbeUvArea uv_area, float2 &altas_uv_min, float2 &altas_uv_max)
SphereProbePixelArea reinterpret_as_write_coord(int4 packed_coord)
SphereProbeUvArea reinterpret_as_atlas_coord(int4 packed_coord)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
spherical_harmonics::BandL1< T > L1
spherical_harmonics::BandL0< T > L0
SphericalHarmonicL1< float4 > volume_irradiance
float3 spherical_sample_normalized_with_parallax(LightProbeSample samp, float3 P, float3 L, float lod) const
int select_probe(float3 P, float random_probe) const
float4 sample_probe(float3 L, float lod, SphereProbeUvArea uv_area) const
sampler2DArray lightprobe_spheres_tx
SphereProbeData(& lightprobe_sphere_buf)[SPHERE_PROBE_MAX]