2023-06-14 06:52:36 +00:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2022-02-11 12:53:21 +00:00
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
#pragma once
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2022-08-18 18:45:09 +00:00
|
|
|
#include "kernel/sample/sobol_burley.h"
|
2022-12-14 15:43:12 +00:00
|
|
|
#include "kernel/sample/tabulated_sobol.h"
|
2021-10-24 12:19:19 +00:00
|
|
|
#include "util/hash.h"
|
2013-06-07 16:06:22 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2017-08-12 21:04:58 +00:00
|
|
|
/* Pseudo random numbers, uncomment this for debugging correlations. Only run
|
2018-01-19 04:34:54 +00:00
|
|
|
* this single threaded on a CPU for repeatable results. */
|
2024-01-02 17:12:54 +00:00
|
|
|
// #define __DEBUG_CORRELATION__
|
2017-08-12 21:04:58 +00:00
|
|
|
|
2023-05-26 09:42:03 +00:00
|
|
|
/*
|
|
|
|
* The `path_rng_*()` functions below use a shuffled scrambled Sobol
|
|
|
|
* sequence to generate their samples. Sobol samplers have a property
|
|
|
|
* that is worth being aware of when choosing how to use the sample
|
|
|
|
* dimensions:
|
|
|
|
*
|
|
|
|
* 1. In general, earlier sets of dimensions are better stratified. So
|
|
|
|
* prefer e.g. x,y over y,z over z,w for the things that are most
|
|
|
|
* important to sample well.
|
|
|
|
* 2. As a rule of thumb, dimensions that are closer to each other are
|
|
|
|
* better stratified than dimensions that are far. So prefer e.g.
|
|
|
|
* x,y over x,z.
|
|
|
|
*/
|
|
|
|
|
2021-10-17 14:10:10 +00:00
|
|
|
ccl_device_forceinline float path_rng_1D(KernelGlobals kg,
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
uint rng_hash,
|
|
|
|
int sample,
|
|
|
|
int dimension)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-08-12 21:04:58 +00:00
|
|
|
#ifdef __DEBUG_CORRELATION__
|
|
|
|
return (float)drand48();
|
|
|
|
#endif
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
|
2022-08-18 18:45:09 +00:00
|
|
|
if (kernel_data.integrator.sampling_pattern == SAMPLING_PATTERN_SOBOL_BURLEY) {
|
2022-12-14 15:43:12 +00:00
|
|
|
const uint index_mask = kernel_data.integrator.sobol_index_mask;
|
|
|
|
return sobol_burley_sample_1D(sample, dimension, rng_hash, index_mask);
|
2022-08-18 18:45:09 +00:00
|
|
|
}
|
2022-08-26 11:14:57 +00:00
|
|
|
else {
|
2022-12-13 18:14:29 +00:00
|
|
|
return tabulated_sobol_sample_1D(kg, sample, rng_hash, dimension);
|
2013-06-11 21:58:48 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 23:28:58 +00:00
|
|
|
ccl_device_forceinline float2 path_rng_2D(KernelGlobals kg,
|
|
|
|
uint rng_hash,
|
|
|
|
int sample,
|
|
|
|
int dimension)
|
2013-06-07 16:06:22 +00:00
|
|
|
{
|
2017-08-12 21:04:58 +00:00
|
|
|
#ifdef __DEBUG_CORRELATION__
|
2022-08-31 23:28:58 +00:00
|
|
|
return make_float2((float)drand48(), (float)drand48());
|
2017-08-12 21:04:58 +00:00
|
|
|
#endif
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
|
2022-08-18 18:45:09 +00:00
|
|
|
if (kernel_data.integrator.sampling_pattern == SAMPLING_PATTERN_SOBOL_BURLEY) {
|
2022-12-14 15:43:12 +00:00
|
|
|
const uint index_mask = kernel_data.integrator.sobol_index_mask;
|
|
|
|
return sobol_burley_sample_2D(sample, dimension, rng_hash, index_mask);
|
2022-08-18 18:45:09 +00:00
|
|
|
}
|
2022-08-26 11:14:57 +00:00
|
|
|
else {
|
2022-12-13 18:14:29 +00:00
|
|
|
return tabulated_sobol_sample_2D(kg, sample, rng_hash, dimension);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ccl_device_forceinline float3 path_rng_3D(KernelGlobals kg,
|
|
|
|
uint rng_hash,
|
|
|
|
int sample,
|
|
|
|
int dimension)
|
|
|
|
{
|
|
|
|
#ifdef __DEBUG_CORRELATION__
|
|
|
|
return make_float3((float)drand48(), (float)drand48(), (float)drand48());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (kernel_data.integrator.sampling_pattern == SAMPLING_PATTERN_SOBOL_BURLEY) {
|
2022-12-14 15:43:12 +00:00
|
|
|
const uint index_mask = kernel_data.integrator.sobol_index_mask;
|
|
|
|
return sobol_burley_sample_3D(sample, dimension, rng_hash, index_mask);
|
2022-12-13 18:14:29 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return tabulated_sobol_sample_3D(kg, sample, rng_hash, dimension);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ccl_device_forceinline float4 path_rng_4D(KernelGlobals kg,
|
|
|
|
uint rng_hash,
|
|
|
|
int sample,
|
|
|
|
int dimension)
|
|
|
|
{
|
|
|
|
#ifdef __DEBUG_CORRELATION__
|
|
|
|
return make_float4((float)drand48(), (float)drand48(), (float)drand48(), (float)drand48());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (kernel_data.integrator.sampling_pattern == SAMPLING_PATTERN_SOBOL_BURLEY) {
|
2022-12-14 15:43:12 +00:00
|
|
|
const uint index_mask = kernel_data.integrator.sobol_index_mask;
|
|
|
|
return sobol_burley_sample_4D(sample, dimension, rng_hash, index_mask);
|
2022-12-13 18:14:29 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return tabulated_sobol_sample_4D(kg, sample, rng_hash, dimension);
|
2013-06-07 16:06:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
/**
|
2021-09-22 04:48:01 +00:00
|
|
|
* 1D hash recommended from "Hash Functions for GPU Rendering" JCGT Vol. 9, No. 3, 2020
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
* See https://www.shadertoy.com/view/4tXyWN and https://www.shadertoy.com/view/XlGcRh
|
|
|
|
* http://www.jcgt.org/published/0009/03/02/paper.pdf
|
|
|
|
*/
|
|
|
|
ccl_device_inline uint hash_iqint1(uint n)
|
|
|
|
{
|
|
|
|
n = (n << 13U) ^ n;
|
|
|
|
n = n * (n * n * 15731U + 789221U) + 1376312589U;
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-09-22 04:48:01 +00:00
|
|
|
* 2D hash recommended from "Hash Functions for GPU Rendering" JCGT Vol. 9, No. 3, 2020
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
* See https://www.shadertoy.com/view/4tXyWN and https://www.shadertoy.com/view/XlGcRh
|
|
|
|
* http://www.jcgt.org/published/0009/03/02/paper.pdf
|
|
|
|
*/
|
|
|
|
ccl_device_inline uint hash_iqnt2d(const uint x, const uint y)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
const uint qx = 1103515245U * ((x >> 1U) ^ (y));
|
|
|
|
const uint qy = 1103515245U * ((y >> 1U) ^ (x));
|
|
|
|
const uint n = 1103515245U * ((qx) ^ (qy >> 3U));
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2021-10-17 14:10:10 +00:00
|
|
|
ccl_device_inline uint path_rng_hash_init(KernelGlobals kg,
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
const int sample,
|
|
|
|
const int x,
|
|
|
|
const int y)
|
|
|
|
{
|
|
|
|
const uint rng_hash = hash_iqnt2d(x, y) ^ kernel_data.integrator.seed;
|
2011-10-29 14:27:24 +00:00
|
|
|
|
2017-08-12 21:04:58 +00:00
|
|
|
#ifdef __DEBUG_CORRELATION__
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
srand48(rng_hash + sample);
|
|
|
|
#else
|
|
|
|
(void)sample;
|
2017-08-12 21:04:58 +00:00
|
|
|
#endif
|
2017-08-06 19:14:58 +00:00
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 15:59:20 +00:00
|
|
|
return rng_hash;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2022-09-02 15:32:34 +00:00
|
|
|
/**
|
|
|
|
* Splits samples into two different classes, A and B, which can be
|
|
|
|
* compared for variance estimation.
|
|
|
|
*/
|
|
|
|
ccl_device_inline bool sample_is_class_A(int pattern, int sample)
|
2020-03-02 14:12:44 +00:00
|
|
|
{
|
2022-09-02 15:32:34 +00:00
|
|
|
#if 0
|
2022-12-13 18:14:29 +00:00
|
|
|
if (!(pattern == SAMPLING_PATTERN_TABULATED_SOBOL || pattern == SAMPLING_PATTERN_SOBOL_BURLEY)) {
|
2022-09-02 15:32:34 +00:00
|
|
|
/* Fallback: assign samples randomly.
|
|
|
|
* This is guaranteed to work "okay" for any sampler, but isn't good.
|
2022-10-10 00:21:53 +00:00
|
|
|
* (NOTE: the seed constant is just a random number to guard against
|
2022-09-02 15:32:34 +00:00
|
|
|
* possible interactions with other uses of the hash. There's nothing
|
|
|
|
* special about it.)
|
|
|
|
*/
|
|
|
|
return hash_hp_seeded_uint(sample, 0xa771f873) & 1;
|
2020-03-02 14:12:44 +00:00
|
|
|
}
|
2022-09-02 16:23:03 +00:00
|
|
|
#else
|
|
|
|
(void)pattern;
|
2022-09-02 15:32:34 +00:00
|
|
|
#endif
|
2020-03-02 14:12:44 +00:00
|
|
|
|
2022-09-02 15:32:34 +00:00
|
|
|
/* This follows the approach from section 10.2.1 of "Progressive
|
|
|
|
* Multi-Jittered Sample Sequences" by Christensen et al., but
|
|
|
|
* implemented with efficient bit-fiddling.
|
|
|
|
*
|
2022-12-13 18:14:29 +00:00
|
|
|
* This approach also turns out to work equally well with Owen
|
|
|
|
* scrambled and shuffled Sobol (see https://developer.blender.org/D15746#429471).
|
2022-09-02 15:32:34 +00:00
|
|
|
*/
|
|
|
|
return popcount(uint(sample) & 0xaaaaaaaa) & 1;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|