Blender V5.3
intersect_mnee.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2026 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
9
11
12#ifdef __MNEE__
13
14/* Sample a light and run the MNEE manifold walk for a caustic receiver. On a successful walk
15 * the result is written to a shadow slot for integrator_shade_surface, otherwise nothing is
16 * written and direct light is sampled there. */
18integrate_surface_mnee(KernelGlobals kg,
20 ccl_private ShaderData *sd,
21 const ccl_private RNGState *rng_state)
22{
23 /* Kernel must only be scheduled for caustic receivers. */
25
26 if (!kernel_data.integrator.use_direct_light) {
27 return SHADER_EVAL_OK;
28 }
29
30 /* Sample position on a light. */
32 {
33 const uint32_t path_flag = INTEGRATOR_STATE(state, path, flag);
34 const uint bounce = INTEGRATOR_STATE(state, path, bounce);
35 const float3 rand_light = path_state_rng_3D(kg, rng_state, PRNG_LIGHT);
36
38 rand_light,
39 sd->time,
40 sd->P,
41 sd->N,
43 sd->runtime_flag,
44 bounce,
45 path_flag,
46 &ls))
47 {
48 return SHADER_EVAL_OK;
49 }
50 }
51
52 kernel_assert(ls.pdf != 0.0f);
53
54 /* The manifold walk connects a caustic light to the receiver across reflection; transmission
55 * caustics and triangle lights are not handled. */
56 if (ls.type == LIGHT_TRIANGLE || dot(ls.D, sd->N) < 0.0f) {
57 return SHADER_EVAL_OK;
58 }
59
60 if (!kernel_data_fetch(lights, ls.prim).use_caustics) {
61 return SHADER_EVAL_OK;
62 }
63
64 ShaderDataCausticsStorage emission_sd_storage;
65 ccl_private ShaderData *emission_sd = AS_SHADER_DATA(&emission_sd_storage);
66
67 Spectrum mnee_throughput = zero_spectrum();
68 float3 mnee_wo = zero_float3();
69 int mnee_vertex_count = 0;
71 kg, state, sd, emission_sd, rng_state, &ls, &mnee_throughput, &mnee_wo, mnee_vertex_count);
72 if (result == SHADER_EVAL_CACHE_MISS) {
74 }
75
76 /* Store MNEE state in a shadow state, to avoid increasing path state size.
77 * This is then turned into an actual shadow ray state in shade_surface, or discarded. */
78 if (mnee_vertex_count > 0) {
80 light_sample_to_surface_shadow_ray(kg, emission_sd, &ls, &ray);
81
84 integrator_state_write_mnee(
85 state, shadow_state, &ls, &ray, mnee_vertex_count, mnee_throughput, mnee_wo);
86 }
87
88 return SHADER_EVAL_OK;
89}
90
91#endif /* __MNEE__ */
92
94{
96
97 ShaderData sd;
99 const int shader = sd.shader & SHADER_MASK;
100
101#ifdef __MNEE__
102 RNGState rng_state;
103 path_state_rng_load(state, &rng_state);
104
105 const ShaderEvalResult result = integrate_surface_mnee(kg, state, &sd, &rng_state);
106 if (result == SHADER_EVAL_CACHE_MISS) {
108 return;
109 }
110#endif
111
113 state,
116 shader);
117}
118
ccl_device_inline void light_sample_to_surface_shadow_ray(KernelGlobals kg, const ccl_private ShaderData *ccl_restrict sd, const ccl_private LightSample *ccl_restrict ls, ccl_private Ray *ray)
ccl_device bool light_sample_from_position(KernelGlobals kg, const float3 rand, const float time, const float3 P, const float3 N, const int object_receiver, const int runtime_flags, const int bounce, const uint32_t path_flag, ccl_private LightSample *ls)
#define kernel_assert(cond)
#define kernel_data
#define ccl_device_forceinline
#define ccl_optional_struct_init
#define kernel_data_fetch(name, index)
#define AS_SHADER_DATA(shader_data_tiny_storage)
#define zero_spectrum
#define ccl_private
#define CCL_NAMESPACE_END
float dot(VecOp< float, D >, VecOp< float, D >) RET
CCL_NAMESPACE_BEGIN ccl_device void integrator_intersect_mnee(KernelGlobals kg, IntegratorState state)
const int state
ccl_device_inline int light_link_receiver_nee(KernelGlobals kg, const ccl_private ShaderData *sd)
ShaderEvalResult
@ SHADER_EVAL_CACHE_MISS
@ SHADER_EVAL_OK
@ PRNG_LIGHT
@ SD_OBJECT_CAUSTICS_RECEIVER
@ SHADER_MASK
ShaderData ShaderDataCausticsStorage
@ LIGHT_TRIANGLE
@ DEVICE_KERNEL_INTEGRATOR_SHADE_SURFACE
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_MNEE
@ DEVICE_KERNEL_INTEGRATOR_SHADOW_PATH_MNEE_PENDING
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
Definition math_float3.h:17
#define PROFILING_INIT(kg, event)
ccl_device_inline ShaderEvalResult kernel_path_mnee_sample(KernelGlobals kg, IntegratorState state, ccl_private ShaderData *sd, ccl_private ShaderData *sd_mnee, const ccl_private RNGState *rng_state, ccl_private LightSample *ls, ccl_private Spectrum *throughput, ccl_private float3 *r_receiver_wo, ccl_private int &r_vertex_count)
Definition mnee.h:945
unsigned int uint
Definition BKE_text.h:55
unsigned int uint32_t
Definition BKE_text.h:81
ccl_device_inline void path_state_rng_load(ConstIntegratorState state, ccl_private RNGState *rng_state)
Definition path_state.h:337
ccl_device_inline float3 path_state_rng_3D(KernelGlobals kg, const ccl_private RNGState *rng_state, const int dimension)
Definition path_state.h:377
@ PROFILING_SHADE_SURFACE_DIRECT_LIGHT
Definition profiling.h:27
#define ccl_device
CCL_NAMESPACE_BEGIN ccl_device_forceinline void integrate_surface_shader_setup(KernelGlobals kg, ConstIntegratorState state, ccl_private ShaderData *sd)
IntegratorShadowStateCPU * IntegratorShadowState
Definition state.h:229
#define INTEGRATOR_STATE(state, nested_struct, member)
Definition state.h:234
IntegratorStateCPU * IntegratorState
Definition state.h:227
ccl_device_forceinline void integrator_path_next_sorted(KernelGlobals, IntegratorState state, const DeviceKernel current_kernel, const DeviceKernel next_kernel, const uint32_t key)
Definition state_flow.h:250
ccl_device_forceinline void integrator_path_cache_miss(IntegratorState, const DeviceKernel)
Definition state_flow.h:238
ccl_device_forceinline IntegratorShadowState integrator_shadow_path_init(ccl_attr_maybe_unused KernelGlobals kg, IntegratorState state, const DeviceKernel next_kernel, const bool is_ao)
Definition state_flow.h:262
float3 Spectrum