Blender V5.0
init_from_camera.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
8
11
13
16
18
20 const int sample,
21 const int x,
22 const int y,
23 const uint rng_pixel,
24 ccl_private Ray *ray)
25{
26 /* Filter sampling. */
27 const float2 rand_filter = (sample == 0) ? make_float2(0.5f, 0.5f) :
28 path_rng_2D(kg, rng_pixel, sample, PRNG_FILTER);
29
30 /* Motion blur (time) and depth of field (lens) sampling. (time, lens_x, lens_y) */
31 const bool use_motionblur = kernel_data.cam.shuttertime != -1.0f;
32 const bool use_dof = kernel_data.cam.aperturesize > 0.0f;
33 const bool use_custom_cam = kernel_data.cam.type == CAMERA_CUSTOM;
34 const float3 rand_time_lens = (use_motionblur || use_dof || use_custom_cam) ?
35 path_rng_3D(kg, rng_pixel, sample, PRNG_LENS_TIME) :
37
38 /* We use x for time and y,z for lens because in practice with Sobol
39 * sampling this seems to give better convergence when an object is
40 * both motion blurred and out of focus, without significantly harming
41 * convergence for focal blur alone. This is a little surprising,
42 * because one would expect using x,y for lens (the 2d part) would be
43 * best, since x,y are the best stratified. Since it's not entirely
44 * clear why this is, this is probably worth revisiting at some point
45 * to investigate further. */
46 const float rand_time = rand_time_lens.x;
47 const float2 rand_lens = make_float2(rand_time_lens.y, rand_time_lens.z);
48
49 /* Generate camera ray. */
50 return camera_sample(kg, x, y, rand_filter, rand_time, rand_lens, ray);
51}
52
53/* Return false to indicate that this pixel is finished.
54 * Used by CPU implementation to not attempt to sample pixel for multiple samples once its known
55 * that the pixel did converge. */
60 const int x,
61 const int y,
62 const int scheduled_sample)
63{
65
66 /* Initialize path state to give basic buffer access and allow early outputs. */
68
69 /* Check whether the pixel has converged and should not be sampled anymore. */
71 return false;
72 }
73
74 /* Count the sample and get an effective sample for this pixel.
75 *
76 * This logic allows to both count actual number of samples per pixel, and to add samples to this
77 * pixel after it was converged and samples were added somewhere else (in which case the
78 * `scheduled_sample` will be different from actual number of samples in this pixel). */
79 const int sample = film_write_sample(
80 kg, state, render_buffer, scheduled_sample, tile->sample_offset);
81
82 /* Initialize random number seed for path. */
83 const uint rng_pixel = path_rng_pixel_init(kg, sample, x, y);
84
85 /* Generate camera ray. */
86 Ray ray;
87 Spectrum T = integrate_camera_sample(kg, sample, x, y, rng_pixel, &ray);
88 if (is_zero(T)) {
89 return true;
90 }
91
92 /* Write camera ray to state. */
94
95 /* Initialize path state for path integration. */
96 path_state_init_integrator(kg, state, sample, rng_pixel, T);
97
98 /* Continue with intersect_closest kernel, optionally initializing volume
99 * stack before that if the camera may be inside a volume. */
100 if (kernel_data.cam.is_inside_volume) {
102 }
103 else {
105 }
106
107 return true;
108}
109
unsigned int uint
#define kernel_data
#define ccl_restrict
#define ccl_private
const ThreadKernelGlobalsCPU * KernelGlobals
#define ccl_device_inline
#define ccl_global
#define CCL_NAMESPACE_END
CCL_NAMESPACE_BEGIN ccl_device_inline Spectrum integrate_camera_sample(KernelGlobals kg, const int sample, const int x, const int y, const uint rng_pixel, ccl_private Ray *ray)
ccl_device bool integrator_init_from_camera(KernelGlobals kg, IntegratorState state, const ccl_global KernelWorkTile *ccl_restrict tile, ccl_global float *render_buffer, const int x, const int y, const int scheduled_sample)
ccl_device_inline Spectrum camera_sample(KernelGlobals kg, const int x, const int y, const float2 filter_uv, const float time, const float2 lens_uv, ccl_private Ray *ray)
const ccl_global KernelWorkTile * tile
ccl_gpu_kernel_postfix ccl_global KernelWorkTile const int ccl_global float * render_buffer
CCL_NAMESPACE_BEGIN ccl_device_forceinline bool film_need_sample_pixel(KernelGlobals kg, ConstIntegratorState state, ccl_global float *render_buffer)
@ PRNG_LENS_TIME
@ PRNG_FILTER
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_VOLUME_STACK
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_CLOSEST
@ CAMERA_CUSTOM
ccl_device_inline int film_write_sample(KernelGlobals kg, ConstIntegratorState state, ccl_global float *ccl_restrict render_buffer, const int sample, const int sample_offset)
ccl_device_inline bool is_zero(const float2 a)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
Definition math_float3.h:17
static ulong state[N]
#define T
#define PROFILING_INIT(kg, event)
ccl_device_inline void path_state_init_integrator(KernelGlobals kg, IntegratorState state, const int sample, const uint rng_pixel, const Spectrum throughput)
Definition path_state.h:40
ccl_device_inline void path_state_init(IntegratorState state, const ccl_global KernelWorkTile *ccl_restrict tile, const int x, const int y)
Definition path_state.h:27
ccl_device_forceinline float2 path_rng_2D(KernelGlobals kg, const uint rng_pixel, const int sample, const int dimension)
Definition pattern.h:83
ccl_device_inline uint path_rng_pixel_init(KernelGlobals kg, const int, const int x, const int y)
Definition pattern.h:134
ccl_device_forceinline float3 path_rng_3D(KernelGlobals kg, const uint rng_pixel, const int sample, const int dimension)
Definition pattern.h:100
@ PROFILING_RAY_SETUP
Definition profiling.h:17
#define ccl_device
#define make_float2
IntegratorStateCPU * IntegratorState
Definition state.h:228
ccl_device_forceinline void integrator_path_init(IntegratorState state, const DeviceKernel next_kernel)
Definition state_flow.h:180
CCL_NAMESPACE_BEGIN ccl_device_forceinline void integrator_state_write_ray(IntegratorState state, const ccl_private Ray *ccl_restrict ray)
Definition state_util.h:17
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136
float3 Spectrum