Blender V4.5
kernel/bake/bake.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include "kernel/globals.h"
8
12
13#include "kernel/geom/object.h"
15
17
19
22 ccl_global float *output,
23 const int offset)
24{
25 /* Setup shader data. */
26 const KernelShaderEvalInput in = input[offset];
27
28 ShaderData sd;
29 shader_setup_from_displace(kg, &sd, in.object, in.prim, in.u, in.v);
30
31 /* Evaluate displacement shader. */
32 const float3 P = sd.P;
34 float3 D = sd.P - P;
35
37
38#ifdef __KERNEL_DEBUG_NAN__
39 if (!isfinite_safe(D)) {
40 kernel_assert(!"Cycles displacement with non-finite value detected");
41 }
42#endif
43
44 /* Ensure finite displacement, preventing BVH from becoming degenerate and avoiding possible
45 * traversal issues caused by non-finite math. */
46 D = ensure_finite(D);
47
48 /* Write output. */
49 output[offset * 3 + 0] += D.x;
50 output[offset * 3 + 1] += D.y;
51 output[offset * 3 + 2] += D.z;
52}
53
56 ccl_global float *output,
57 const int offset)
58{
59 /* Setup ray */
60 const KernelShaderEvalInput in = input[offset];
61 const float3 ray_P = zero_float3();
62 const float3 ray_D = equirectangular_to_direction(in.u, in.v);
63 const float ray_time = 0.5f;
64
65 /* Setup shader data. */
66 ShaderData sd;
67 shader_setup_from_background(kg, &sd, ray_P, ray_D, ray_time);
68
69 /* Evaluate shader.
70 * This is being evaluated for all BSDFs, so path flag does not contain a specific type.
71 * However, we want to flag the ray visibility to ignore the sun in the background map. */
72 const uint32_t path_flag = PATH_RAY_EMISSION | PATH_RAY_IMPORTANCE_BAKE;
75 kg, INTEGRATOR_STATE_NULL, &sd, nullptr, path_flag);
77
78#ifdef __KERNEL_DEBUG_NAN__
79 if (!isfinite_safe(color)) {
80 kernel_assert(!"Cycles background with non-finite value detected");
81 }
82#endif
83
84 /* Ensure finite color, avoiding possible numerical instabilities in the path tracing kernels. */
85 color = ensure_finite(color);
86
87 const float3 color_rgb = spectrum_to_rgb(color);
88
89 /* Write output. */
90 output[offset * 3 + 0] += color_rgb.x;
91 output[offset * 3 + 1] += color_rgb.y;
92 output[offset * 3 + 2] += color_rgb.z;
93}
94
98 ccl_global float *output,
99 const int offset)
100{
101#ifdef __HAIR__
102 /* Setup shader data. */
103 const KernelShaderEvalInput in = input[offset];
104
105 ShaderData sd;
106 shader_setup_from_curve(kg, &sd, in.object, in.prim, __float_as_int(in.v), in.u);
107
108 /* Evaluate transparency. */
111 kg, INTEGRATOR_STATE_NULL, &sd, nullptr, PATH_RAY_SHADOW);
112
113 /* Write output. */
114 output[offset] = clamp(average(surface_shader_transparency(kg, &sd)), 0.0f, 1.0f);
115#endif
116}
117
#define D
ccl_device float3 equirectangular_to_direction(const float u, const float v)
#define kernel_assert(cond)
#define KERNEL_FEATURE_NODE_MASK_SURFACE_SHADOW
#define ccl_device
const ThreadKernelGlobalsCPU * KernelGlobals
#define KERNEL_FEATURE_NODE_LIGHT_PATH
#define KERNEL_FEATURE_NODE_MASK_SURFACE_LIGHT
#define ccl_global
#define KERNEL_FEATURE_NODE_RAYTRACE
#define CCL_NAMESPACE_END
#define __float_as_int(x)
CCL_NAMESPACE_BEGIN ccl_device void displacement_shader_eval(KernelGlobals kg, ConstIntegratorGenericState state, ccl_private ShaderData *sd)
#define input
#define in
#define output
constexpr T clamp(T, U, U) RET
ccl_device void kernel_curve_shadow_transparency_evaluate(KernelGlobals kg, const ccl_global KernelShaderEvalInput *input, ccl_global float *output, const int offset)
CCL_NAMESPACE_BEGIN ccl_device void kernel_displace_evaluate(KernelGlobals kg, const ccl_global KernelShaderEvalInput *input, ccl_global float *output, const int offset)
ccl_device void kernel_background_evaluate(KernelGlobals kg, const ccl_global KernelShaderEvalInput *input, ccl_global float *output, const int offset)
ccl_device_inline void object_inverse_dir_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private float3 *D)
@ PATH_RAY_SHADOW
@ PATH_RAY_IMPORTANCE_BAKE
@ PATH_RAY_EMISSION
ccl_device_inline float3 spectrum_to_rgb(Spectrum s)
ccl_device_inline float ensure_finite(const float v)
Definition math_base.h:356
ccl_device_inline bool isfinite_safe(const float f)
Definition math_base.h:348
ccl_device_inline float average(const float2 a)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
Definition math_float3.h:15
ccl_device void shader_setup_from_displace(KernelGlobals kg, ccl_private ShaderData *ccl_restrict sd, const int object, const int prim, const float u, const float v)
ccl_device_inline void shader_setup_from_background(KernelGlobals kg, ccl_private ShaderData *ccl_restrict sd, const float3 ray_P, const float3 ray_D, const float ray_time)
#define INTEGRATOR_STATE_NULL
Definition state.h:233
float z
Definition sky_float3.h:27
float y
Definition sky_float3.h:27
float x
Definition sky_float3.h:27
ccl_device void surface_shader_eval(KernelGlobals kg, ConstIntegratorGenericState state, ccl_private ShaderData *ccl_restrict sd, ccl_global float *ccl_restrict buffer, const uint32_t path_flag, bool use_caustics_storage=false)
ccl_device Spectrum surface_shader_transparency(KernelGlobals kg, const ccl_private ShaderData *sd)
ccl_device Spectrum surface_shader_background(const ccl_private ShaderData *sd)
float3 Spectrum