Blender V5.3
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 ccl_private int &r_cache_miss)
26{
27 /* Filter sampling. */
28 const float2 rand_filter = (sample == 0) ? make_float2(0.5f, 0.5f) :
29 path_rng_2D(kg, rng_pixel, sample, PRNG_FILTER);
30
31 /* Motion blur (time) and depth of field (lens) sampling. (time, lens_x, lens_y) */
32 const bool use_motionblur = kernel_data.cam.shuttertime != -1.0f;
33 const bool use_dof = kernel_data.cam.aperturesize > 0.0f;
34 const bool use_custom_cam = kernel_data.cam.type == CAMERA_CUSTOM;
35 const float3 rand_time_lens = (use_motionblur || use_dof || use_custom_cam) ?
36 path_rng_3D(kg, rng_pixel, sample, PRNG_LENS_TIME) :
38
39 /* We use x for time and y,z for lens because in practice with Sobol
40 * sampling this seems to give better convergence when an object is
41 * both motion blurred and out of focus, without significantly harming
42 * convergence for focal blur alone. This is a little surprising,
43 * because one would expect using x,y for lens (the 2d part) would be
44 * best, since x,y are the best stratified. Since it's not entirely
45 * clear why this is, this is probably worth revisiting at some point
46 * to investigate further. */
47 const float rand_time = rand_time_lens.x;
48 const float2 rand_lens = make_float2(rand_time_lens.y, rand_time_lens.z);
49
50 /* Generate camera ray. */
51 return camera_sample(kg, x, y, rand_filter, rand_time, rand_lens, ray, r_cache_miss);
52}
53
54/* Return false to indicate that this pixel is finished.
55 * Used by CPU implementation to not attempt to sample pixel for multiple samples once its known
56 * that the pixel did converge. */
61 const int x_,
62 const int y_,
63 const int scheduled_sample)
64{
66
67 int x, y, sample;
68
69 if (tile == nullptr) {
70 /* Restart from miss. Reconstruct x, y, sample from state. */
71 const uint pixel_index = INTEGRATOR_STATE(state, path, render_pixel_index);
72 x = pixel_index % (int)kernel_data.cam.width;
73 y = pixel_index / (int)kernel_data.cam.width;
75 }
76 else {
77 x = x_;
78 y = y_;
79
80 /* Initialize path state to give basic buffer access and allow early outputs. */
82
83 /* Check whether the pixel has converged and should not be sampled anymore. */
85 return false;
86 }
87
88 /* Count the sample and get an effective sample for this pixel. */
89 sample = film_write_sample(kg, state, render_buffer, scheduled_sample, tile->sample_offset);
90 }
91
92 /* Initialize random number seed for path. */
93 const uint rng_pixel = path_rng_pixel_init(kg, sample, x, y);
94
95 /* Generate camera ray. */
96 Ray ray;
97 int cache_miss = 0;
98 Spectrum T = integrate_camera_sample(kg, sample, x, y, rng_pixel, &ray, cache_miss);
99 if (cache_miss) {
100 if (tile != nullptr) {
103 }
105 return true;
106 }
107
108 if (is_zero(T)) {
109 if (tile == nullptr) {
112 }
113 return true;
114 }
115
116 /* Write camera ray to state. */
118
119 if (tile == nullptr) {
120 /* Re-initialize path state for path integration. */
121 path_state_init_integrator(kg, state, sample, rng_pixel, T);
124 kernel_data.cam.is_inside_volume ?
127 }
128 else {
129 /* Initialize path state for path integration. */
130 path_state_init_integrator(kg, state, sample, rng_pixel, T);
131
132 /* Continue with intersect_closest kernel, optionally initializing volume
133 * stack before that if the camera may be inside a volume. */
134 if (kernel_data.cam.is_inside_volume) {
136 }
137 else {
139 }
140 }
141
142 return true;
143}
144
#define kernel_data
#define ccl_restrict
#define ccl_private
#define ccl_device_inline
#define ccl_global
#define CCL_NAMESPACE_END
bool is_zero(float3x3 a)
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_private int &r_cache_miss)
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, ccl_private int &r_cache_miss)
const int state
ccl_gpu_kernel_postfix ccl_global KernelWorkTile const int ccl_global float * render_buffer
const ccl_global KernelWorkTile * tile
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_INIT_FROM_CAMERA
@ 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_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
Definition math_float3.h:17
#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:42
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:29
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
#define INTEGRATOR_STATE_WRITE(state, nested_struct, member)
Definition state.h:235
#define INTEGRATOR_STATE(state, nested_struct, member)
Definition state.h:234
IntegratorStateCPU * IntegratorState
Definition state.h:227
ccl_device_forceinline void integrator_path_init(IntegratorState state, const DeviceKernel next_kernel)
Definition state_flow.h:204
ccl_device_forceinline void integrator_path_cache_miss(IntegratorState, const DeviceKernel)
Definition state_flow.h:238
ccl_device_forceinline void integrator_path_next(IntegratorState state, const DeviceKernel current_kernel, const DeviceKernel next_kernel)
Definition state_flow.h:219
ccl_device_forceinline void integrator_path_terminate(KernelGlobals kg, IntegratorState state, ccl_global float *ccl_restrict render_buffer, const DeviceKernel current_kernel)
Definition state_flow.h:227
CCL_NAMESPACE_BEGIN ccl_device_forceinline void integrator_state_write_ray(IntegratorState state, const ccl_private Ray *ccl_restrict ray)
Definition state_util.h:25
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136
float3 Spectrum