Blender  V3.3
kernel/bake/bake.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #pragma once
5 
8 
9 #include "kernel/geom/geom.h"
10 
12 
15  ccl_global float *output,
16  const int offset)
17 {
18  /* Setup shader data. */
20 
21  ShaderData sd;
22  shader_setup_from_displace(kg, &sd, in.object, in.prim, in.u, in.v);
23 
24  /* Evaluate displacement shader. */
25  const float3 P = sd.P;
27  float3 D = sd.P - P;
28 
30 
31 #ifdef __KERNEL_DEBUG_NAN__
32  if (!isfinite_safe(D)) {
33  kernel_assert(!"Cycles displacement with non-finite value detected");
34  }
35 #endif
36 
37  /* Ensure finite displacement, preventing BVH from becoming degenerate and avoiding possible
38  * traversal issues caused by non-finite math. */
39  D = ensure_finite(D);
40 
41  /* Write output. */
42  output[offset * 3 + 0] += D.x;
43  output[offset * 3 + 1] += D.y;
44  output[offset * 3 + 2] += D.z;
45 }
46 
49  ccl_global float *output,
50  const int offset)
51 {
52  /* Setup ray */
54  const float3 ray_P = zero_float3();
55  const float3 ray_D = equirectangular_to_direction(in.u, in.v);
56  const float ray_time = 0.5f;
57 
58  /* Setup shader data. */
59  ShaderData sd;
60  shader_setup_from_background(kg, &sd, ray_P, ray_D, ray_time);
61 
62  /* Evaluate shader.
63  * This is being evaluated for all BSDFs, so path flag does not contain a specific type. */
64  const uint32_t path_flag = PATH_RAY_EMISSION;
67  kg, INTEGRATOR_STATE_NULL, &sd, NULL, path_flag);
69 
70 #ifdef __KERNEL_DEBUG_NAN__
71  if (!isfinite_safe(color)) {
72  kernel_assert(!"Cycles background with non-finite value detected");
73  }
74 #endif
75 
76  /* Ensure finite color, avoiding possible numerical instabilities in the path tracing kernels. */
78 
79  /* Write output. */
80  output[offset * 3 + 0] += color.x;
81  output[offset * 3 + 1] += color.y;
82  output[offset * 3 + 2] += color.z;
83 }
84 
86  KernelGlobals kg,
88  ccl_global float *output,
89  const int offset)
90 {
91  /* Setup shader data. */
93 
94  ShaderData sd;
95  shader_setup_from_curve(kg, &sd, in.object, in.prim, __float_as_int(in.v), in.u);
96 
97  /* Evaluate transparency. */
101 
102  /* Write output. */
103  output[offset] = clamp(average(shader_bsdf_transparency(kg, &sd)), 0.0f, 1.0f);
104 }
105 
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 Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input 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 a color
#define kernel_assert(cond)
Definition: cpu/compat.h:34
#define ccl_device
Definition: cuda/compat.h:32
#define ccl_global
Definition: cuda/compat.h:43
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
ccl_device float3 equirectangular_to_direction(float u, float v)
const KernelGlobalsCPU *ccl_restrict KernelGlobals
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_global KernelShaderEvalInput ccl_global float * output
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
ccl_global KernelShaderEvalInput * input
ccl_device_inline void object_inverse_dir_transform(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float3 *D)
ccl_device void shader_eval_displacement(KernelGlobals kg, ConstIntegratorGenericState state, ccl_private ShaderData *sd)
ccl_device void shader_eval_surface(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 float3 shader_bsdf_transparency(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device float3 shader_background_eval(ccl_private const ShaderData *sd)
#define KERNEL_FEATURE_NODE_MASK_SURFACE_SHADOW
@ PATH_RAY_SHADOW
Definition: kernel/types.h:206
@ PATH_RAY_EMISSION
Definition: kernel/types.h:255
@ KERNEL_FEATURE_NODE_LIGHT_PATH
@ KERNEL_FEATURE_NODE_RAYTRACE
ShaderData
Definition: kernel/types.h:925
#define KERNEL_FEATURE_NODE_MASK_SURFACE_LIGHT
ccl_device_inline float average(const float2 &a)
Definition: math_float2.h:170
ccl_device_inline float3 zero_float3()
Definition: math_float3.h:80
static float P(float k)
Definition: math_interp.c:25
T clamp(const T &a, const T &min, const T &max)
ccl_device void shader_setup_from_displace(KernelGlobals kg, ccl_private ShaderData *ccl_restrict sd, int object, int prim, float u, float v)
Definition: shader_data.h:252
ccl_device void shader_setup_from_curve(KernelGlobals kg, ccl_private ShaderData *ccl_restrict sd, int object, int prim, int segment, float u)
Definition: shader_data.h:285
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)
Definition: shader_data.h:360
#define INTEGRATOR_STATE_NULL
Definition: state.h:152
unsigned int uint32_t
Definition: stdint.h:80
ccl_device_inline float ensure_finite(float v)
Definition: util/math.h:361
ccl_device_inline int __float_as_int(float f)
Definition: util/math.h:243
ccl_device_inline bool isfinite_safe(float f)
Definition: util/math.h:353
BLI_INLINE float D(const float *data, const int res[3], int x, int y, int z)
Definition: voxel.c:13