Blender V4.3
volume_fournier_forand.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2024 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
8
10
11/* FOURNIER-FORAND CLOSURE */
12
13typedef struct FournierForandVolume {
15
16 /* Precomputed coefficients, based on B and IOR */
17 float c1, c2, c3;
19static_assert(sizeof(ShaderVolumeClosure) >= sizeof(FournierForandVolume),
20 "FournierForandVolume is too large!");
21
23 float B,
24 float IOR)
25{
27
28 /* clamp backscatter fraction to avoid delta function */
29 B = min(fabsf(B), 0.5f - 1e-3f);
30 IOR = max(IOR, 1.0f + 1e-3f);
32 volume->c1 = coeffs.x;
33 volume->c2 = coeffs.y;
34 volume->c3 = coeffs.z;
35
36 return SD_SCATTER;
37}
38
41 float3 wo,
42 ccl_private float *pdf)
43{
45 const float3 coeffs = make_float3(volume->c1, volume->c2, volume->c3);
46
47 /* note that wi points towards the viewer */
48 float cos_theta = dot(-sd->wi, wo);
49 *pdf = phase_fournier_forand(cos_theta, coeffs);
50
51 return make_spectrum(*pdf);
52}
53
56 float2 rand,
59 ccl_private float *pdf)
60{
62 const float3 coeffs = make_float3(volume->c1, volume->c2, volume->c3);
63
64 /* note that wi points towards the viewer and so is used negated */
65 *wo = phase_fournier_forand_sample(-sd->wi, coeffs, rand, pdf);
66 *eval = make_spectrum(*pdf); /* perfect importance sampling */
67
69}
70
ccl_device_inline float cos_theta(const float3 w)
additional_info("compositor_sum_squared_difference_float_shared") .push_constant(Type output_img float dot(value.rgb, luminance_coefficients)") .define("LOAD(value)"
#define ccl_device
#define ccl_private
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
#define fabsf(x)
@ CLOSURE_VOLUME_FOURNIER_FORAND_ID
@ SD_SCATTER
struct ShaderVolumeClosure ShaderVolumeClosure
ShaderData
@ LABEL_VOLUME_SCATTER
#define B
#define min(a, b)
Definition sort.c:32
float z
Definition sky_float3.h:27
float y
Definition sky_float3.h:27
float x
Definition sky_float3.h:27
float max
#define make_spectrum(f)
SPECTRUM_DATA_TYPE Spectrum
CCL_NAMESPACE_BEGIN struct FournierForandVolume FournierForandVolume
ccl_device int volume_fournier_forand_sample(ccl_private const ShaderData *sd, ccl_private const ShaderVolumeClosure *svc, float2 rand, ccl_private Spectrum *eval, ccl_private float3 *wo, ccl_private float *pdf)
ccl_device Spectrum volume_fournier_forand_eval(ccl_private const ShaderData *sd, ccl_private const ShaderVolumeClosure *svc, float3 wo, ccl_private float *pdf)
ccl_device int volume_fournier_forand_setup(ccl_private FournierForandVolume *volume, float B, float IOR)
ccl_device float3 phase_fournier_forand_sample(float3 D, float3 coeffs, float2 rand, ccl_private float *pdf)
ccl_device_inline float3 phase_fournier_forand_coeffs(float B, float IOR)
ccl_device float phase_fournier_forand(float cos_theta, float3 coeffs)