2011-04-27 11:58:34 +00:00
|
|
|
/*
|
|
|
|
|
* Parts adapted from Open Shading Language with this license:
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
|
|
|
|
|
* All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Modifications Copyright 2011, Blender Foundation.
|
2018-07-06 10:17:58 +02:00
|
|
|
*
|
2011-04-27 11:58:34 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
|
* met:
|
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
|
* * Neither the name of Sony Pictures Imageworks nor the names of its
|
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2012-06-09 17:22:52 +00:00
|
|
|
*/
|
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 17:59:20 +02:00
|
|
|
#pragma once
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
2013-08-18 14:16:15 +00:00
|
|
|
/* distribute uniform xy on [0,1] over unit disk [-1,1] */
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_device void to_unit_disk(ccl_private float *x, ccl_private float *y)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2013-06-14 14:29:00 +00:00
|
|
|
float phi = M_2PI_F * (*x);
|
2013-06-07 16:06:22 +00:00
|
|
|
float r = sqrtf(*y);
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
*x = r * cosf(phi);
|
|
|
|
|
*y = r * sinf(phi);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-18 14:16:15 +00:00
|
|
|
/* return an orthogonal tangent and bitangent given a normal and tangent that
|
|
|
|
|
* may not be exactly orthogonal */
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_device void make_orthonormals_tangent(const float3 N,
|
|
|
|
|
const float3 T,
|
|
|
|
|
ccl_private float3 *a,
|
|
|
|
|
ccl_private float3 *b)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-10-10 13:02:20 +00:00
|
|
|
*b = normalize(cross(N, T));
|
2011-04-27 11:58:34 +00:00
|
|
|
*a = cross(*b, N);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-18 14:16:15 +00:00
|
|
|
/* sample direction with cosine weighted distributed in hemisphere */
|
2013-11-16 00:17:10 +01:00
|
|
|
ccl_device_inline void sample_cos_hemisphere(
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
const float3 N, float randu, float randv, ccl_private float3 *omega_in, ccl_private float *pdf)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
|
to_unit_disk(&randu, &randv);
|
|
|
|
|
float costheta = sqrtf(max(1.0f - randu * randu - randv * randv, 0.0f));
|
|
|
|
|
float3 T, B;
|
|
|
|
|
make_orthonormals(N, &T, &B);
|
|
|
|
|
*omega_in = randu * T + randv * B + costheta * N;
|
|
|
|
|
*pdf = costheta * M_1_PI_F;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-18 14:16:15 +00:00
|
|
|
/* sample direction uniformly distributed in hemisphere */
|
2013-11-16 00:17:10 +01:00
|
|
|
ccl_device_inline void sample_uniform_hemisphere(
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
const float3 N, float randu, float randv, ccl_private float3 *omega_in, ccl_private float *pdf)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
|
float z = randu;
|
2012-05-05 19:44:35 +00:00
|
|
|
float r = sqrtf(max(0.0f, 1.0f - z * z));
|
2013-05-12 14:13:29 +00:00
|
|
|
float phi = M_2PI_F * randv;
|
2011-04-27 11:58:34 +00:00
|
|
|
float x = r * cosf(phi);
|
|
|
|
|
float y = r * sinf(phi);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
float3 T, B;
|
|
|
|
|
make_orthonormals(N, &T, &B);
|
|
|
|
|
*omega_in = x * T + y * B + z * N;
|
|
|
|
|
*pdf = 0.5f * M_1_PI_F;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-18 14:16:15 +00:00
|
|
|
/* sample direction uniformly distributed in cone */
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_device_inline void sample_uniform_cone(const float3 N,
|
|
|
|
|
float angle,
|
|
|
|
|
float randu,
|
|
|
|
|
float randv,
|
|
|
|
|
ccl_private float3 *omega_in,
|
|
|
|
|
ccl_private float *pdf)
|
2012-12-19 21:17:16 +00:00
|
|
|
{
|
2020-06-06 20:08:48 +02:00
|
|
|
float zMin = cosf(angle);
|
2020-06-10 13:02:43 +02:00
|
|
|
float z = zMin - zMin * randu + randu;
|
2020-06-06 20:08:48 +02:00
|
|
|
float r = safe_sqrtf(1.0f - sqr(z));
|
2013-05-12 14:13:29 +00:00
|
|
|
float phi = M_2PI_F * randv;
|
2012-12-19 21:17:16 +00:00
|
|
|
float x = r * cosf(phi);
|
|
|
|
|
float y = r * sinf(phi);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-19 21:17:16 +00:00
|
|
|
float3 T, B;
|
|
|
|
|
make_orthonormals(N, &T, &B);
|
|
|
|
|
*omega_in = x * T + y * B + z * N;
|
2020-06-06 20:08:48 +02:00
|
|
|
*pdf = M_1_2PI_F / (1.0f - zMin);
|
2012-12-19 21:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
Cycles: Add new Sky Texture method including direct sunlight
This commit adds a new model to the Sky Texture node, which is based on a
method by Nishita et al. and works by basically simulating volumetric
scattering in the atmosphere.
By making some approximations (such as only considering single scattering),
we get a fairly simple and fast simulation code that takes into account
Rayleigh and Mie scattering as well as Ozone absorption.
This code is used to precompute a 512x128 texture which is then looked up
during render time, and is fast enough to allow real-time tweaking in the
viewport.
Due to the nature of the simulation, it exposes several parameters that
allow for lots of flexibility in choosing the look and matching real-world
conditions (such as Air/Dust/Ozone density and altitude).
Additionally, the same volumetric approach can be used to compute absorption
of the direct sunlight, so the model also supports adding direct sunlight.
This makes it significantly easier to set up Sun+Sky illumination where
the direction, intensity and color of the sun actually matches the sky.
In order to support properly sampling the direct sun component, the commit
also adds logic for sampling a specific area to the kernel light sampling
code. This is combined with portal and background map sampling using MIS.
This sampling logic works for the common case of having one Sky texture
going into the Background shader, but if a custom input to the Vector
node is used or if there are multiple Sky textures, it falls back to using
only background map sampling (while automatically setting the resolution to
4096x2048 if auto resolution is used).
More infos and preview can be found here:
https://docs.google.com/document/d/1gQta0ygFWXTrl5Pmvl_nZRgUw0mWg0FJeRuNKS36m08/view
Underlying model, implementation and documentation by Marco (@nacioss).
Improvements, cleanup and sun sampling by @lukasstockner.
Differential Revision: https://developer.blender.org/D7896
2020-06-17 20:27:10 +02:00
|
|
|
ccl_device_inline float pdf_uniform_cone(const float3 N, float3 D, float angle)
|
|
|
|
|
{
|
|
|
|
|
float zMin = cosf(angle);
|
|
|
|
|
float z = dot(N, D);
|
|
|
|
|
if (z > zMin) {
|
|
|
|
|
return M_1_2PI_F / (1.0f - zMin);
|
|
|
|
|
}
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-18 14:16:15 +00:00
|
|
|
/* sample uniform point on the surface of a sphere */
|
2013-11-16 00:17:10 +01:00
|
|
|
ccl_device float3 sample_uniform_sphere(float u1, float u2)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-01-20 17:49:17 +00:00
|
|
|
float z = 1.0f - 2.0f * u1;
|
|
|
|
|
float r = sqrtf(fmaxf(0.0f, 1.0f - z * z));
|
2013-05-21 13:22:11 +00:00
|
|
|
float phi = M_2PI_F * u2;
|
2012-01-20 17:49:17 +00:00
|
|
|
float x = r * cosf(phi);
|
|
|
|
|
float y = r * sinf(phi);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
return make_float3(x, y, z);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-18 14:16:15 +00:00
|
|
|
/* distribute uniform xy on [0,1] over unit disk [-1,1], with concentric mapping
|
|
|
|
|
* to better preserve stratification for some RNG sequences */
|
2013-11-16 00:17:10 +01:00
|
|
|
ccl_device float2 concentric_sample_disk(float u1, float u2)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2013-08-18 14:16:15 +00:00
|
|
|
float phi, r;
|
|
|
|
|
float a = 2.0f * u1 - 1.0f;
|
|
|
|
|
float b = 2.0f * u2 - 1.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-18 14:16:15 +00:00
|
|
|
if (a == 0.0f && b == 0.0f) {
|
2021-02-17 01:47:18 +01:00
|
|
|
return zero_float2();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2013-08-18 14:16:15 +00:00
|
|
|
else if (a * a > b * b) {
|
|
|
|
|
r = a;
|
|
|
|
|
phi = M_PI_4_F * (b / a);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-08-18 14:16:15 +00:00
|
|
|
r = b;
|
|
|
|
|
phi = M_PI_2_F - M_PI_4_F * (a / b);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-18 14:16:15 +00:00
|
|
|
return make_float2(r * cosf(phi), r * sinf(phi));
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-18 14:16:15 +00:00
|
|
|
/* sample point in unit polygon with given number of corners and rotation */
|
2013-11-16 00:17:10 +01:00
|
|
|
ccl_device float2 regular_polygon_sample(float corners, float rotation, float u, float v)
|
2011-09-16 13:14:02 +00:00
|
|
|
{
|
|
|
|
|
/* sample corner number and reuse u */
|
|
|
|
|
float corner = floorf(u * corners);
|
|
|
|
|
u = u * corners - corner;
|
|
|
|
|
|
|
|
|
|
/* uniform sampled triangle weights */
|
|
|
|
|
u = sqrtf(u);
|
|
|
|
|
v = v * u;
|
|
|
|
|
u = 1.0f - u;
|
|
|
|
|
|
|
|
|
|
/* point in triangle */
|
|
|
|
|
float angle = M_PI_F / corners;
|
|
|
|
|
float2 p = make_float2((u + v) * cosf(angle), (u - v) * sinf(angle));
|
|
|
|
|
|
|
|
|
|
/* rotate */
|
|
|
|
|
rotation += corner * 2.0f * angle;
|
|
|
|
|
|
|
|
|
|
float cr = cosf(rotation);
|
|
|
|
|
float sr = sinf(rotation);
|
|
|
|
|
|
|
|
|
|
return make_float2(cr * p.x - sr * p.y, sr * p.x + cr * p.y);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|