Blender V4.3
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
10
11#include "kernel/geom/geom.h"
12
13#include "kernel/util/color.h"
14
16
19 ccl_global float *output,
20 const int offset)
21{
22 /* Setup shader data. */
23 const KernelShaderEvalInput in = input[offset];
24
25 ShaderData sd;
26 shader_setup_from_displace(kg, &sd, in.object, in.prim, in.u, in.v);
27
28 /* Evaluate displacement shader. */
29 const float3 P = sd.P;
31 float3 D = sd.P - P;
32
34
35#ifdef __KERNEL_DEBUG_NAN__
36 if (!isfinite_safe(D)) {
37 kernel_assert(!"Cycles displacement with non-finite value detected");
38 }
39#endif
40
41 /* Ensure finite displacement, preventing BVH from becoming degenerate and avoiding possible
42 * traversal issues caused by non-finite math. */
43 D = ensure_finite(D);
44
45 /* Write output. */
46 output[offset * 3 + 0] += D.x;
47 output[offset * 3 + 1] += D.y;
48 output[offset * 3 + 2] += D.z;
49}
50
53 ccl_global float *output,
54 const int offset)
55{
56 /* Setup ray */
57 const KernelShaderEvalInput in = input[offset];
58 const float3 ray_P = zero_float3();
59 const float3 ray_D = equirectangular_to_direction(in.u, in.v);
60 const float ray_time = 0.5f;
61
62 /* Setup shader data. */
63 ShaderData sd;
64 shader_setup_from_background(kg, &sd, ray_P, ray_D, ray_time);
65
66 /* Evaluate shader.
67 * This is being evaluated for all BSDFs, so path flag does not contain a specific type.
68 * However, we want to flag the ray visibility to ignore the sun in the background map. */
72 kg, INTEGRATOR_STATE_NULL, &sd, NULL, path_flag);
74
75#ifdef __KERNEL_DEBUG_NAN__
76 if (!isfinite_safe(color)) {
77 kernel_assert(!"Cycles background with non-finite value detected");
78 }
79#endif
80
81 /* Ensure finite color, avoiding possible numerical instabilities in the path tracing kernels. */
83
84 float3 color_rgb = spectrum_to_rgb(color);
85
86 /* Write output. */
87 output[offset * 3 + 0] += color_rgb.x;
88 output[offset * 3 + 1] += color_rgb.y;
89 output[offset * 3 + 2] += color_rgb.z;
90}
91
95 ccl_global float *output,
96 const int offset)
97{
98#ifdef __HAIR__
99 /* Setup shader data. */
100 const KernelShaderEvalInput in = input[offset];
101
102 ShaderData sd;
103 shader_setup_from_curve(kg, &sd, in.object, in.prim, __float_as_int(in.v), in.u);
104
105 /* Evaluate transparency. */
109
110 /* Write output. */
111 output[offset] = clamp(average(surface_shader_transparency(kg, &sd)), 0.0f, 1.0f);
112#endif
113}
114
#define D
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a color
#define output
ccl_device float3 equirectangular_to_direction(float u, float v)
#define kernel_assert(cond)
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define ccl_device
#define ccl_global
#define CCL_NAMESPACE_END
#define NULL
#define __float_as_int(x)
CCL_NAMESPACE_BEGIN ccl_device void displacement_shader_eval(KernelGlobals kg, ConstIntegratorGenericState state, ccl_private ShaderData *sd)
CCL_NAMESPACE_BEGIN ccl_device void kernel_displace_evaluate(KernelGlobals kg, ccl_global const KernelShaderEvalInput *input, ccl_global float *output, const int offset)
ccl_device void kernel_curve_shadow_transparency_evaluate(KernelGlobals kg, ccl_global const KernelShaderEvalInput *input, ccl_global float *output, const int offset)
ccl_device void kernel_background_evaluate(KernelGlobals kg, ccl_global const KernelShaderEvalInput *input, ccl_global float *output, const int offset)
ccl_device_inline void object_inverse_dir_transform(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float3 *D)
#define KERNEL_FEATURE_NODE_MASK_SURFACE_SHADOW
@ PATH_RAY_SHADOW
@ PATH_RAY_IMPORTANCE_BAKE
@ PATH_RAY_EMISSION
ShaderData
#define KERNEL_FEATURE_NODE_LIGHT_PATH
#define KERNEL_FEATURE_NODE_MASK_SURFACE_LIGHT
#define KERNEL_FEATURE_NODE_RAYTRACE
ccl_device_inline float3 spectrum_to_rgb(Spectrum s)
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, int object, int prim, float u, 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
unsigned int uint32_t
Definition stdint.h:80
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, uint32_t path_flag, bool use_caustics_storage=false)
ccl_device Spectrum surface_shader_transparency(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device Spectrum surface_shader_background(ccl_private const ShaderData *sd)
SPECTRUM_DATA_TYPE Spectrum
ccl_device_inline float ensure_finite(float v)
Definition util/math.h:373
ccl_device_inline bool isfinite_safe(float f)
Definition util/math.h:365
ccl_device_inline int clamp(int a, int mn, int mx)
Definition util/math.h:379