2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 02:50:24 +01:00
|
|
|
* limitations under the License.
|
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
|
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "kernel/geom/geom.h"
|
|
|
|
#include "kernel/light/light_background.h"
|
|
|
|
#include "kernel/sample/sample_mapping.h"
|
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
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2013-01-09 21:09:20 +00:00
|
|
|
/* Light Sample result */
|
|
|
|
|
2011-05-20 12:26:01 +00:00
|
|
|
typedef struct LightSample {
|
2013-01-09 21:09:20 +00:00
|
|
|
float3 P; /* position on light, or direction for distant light */
|
|
|
|
float3 Ng; /* normal on light */
|
|
|
|
float3 D; /* direction from shading point to light */
|
|
|
|
float t; /* distance to light (FLT_MAX for distant light) */
|
2014-02-07 15:08:50 +01:00
|
|
|
float u, v; /* parametric coordinate on primitive */
|
2013-01-09 21:09:20 +00:00
|
|
|
float pdf; /* light sampling probability density function */
|
|
|
|
float eval_fac; /* intensity multiplier */
|
|
|
|
int object; /* object id for triangle/curve lights */
|
2014-08-14 16:31:34 +02:00
|
|
|
int prim; /* primitive id for triangle/curve lights */
|
2013-01-09 21:09:20 +00:00
|
|
|
int shader; /* shader id */
|
|
|
|
int lamp; /* lamp id */
|
|
|
|
LightType type; /* type of light */
|
2011-05-20 12:26:01 +00:00
|
|
|
} LightSample;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-01-09 21:09:20 +00:00
|
|
|
/* Regular Light */
|
|
|
|
|
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
|
|
|
template<bool in_volume_segment>
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_inline bool light_sample(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 17:59:20 +02:00
|
|
|
const int lamp,
|
|
|
|
const float randu,
|
|
|
|
const float randv,
|
|
|
|
const float3 P,
|
2021-10-17 20:09:45 +02:00
|
|
|
const uint32_t path_flag,
|
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_private LightSample *ls)
|
2013-01-09 21:09:20 +00:00
|
|
|
{
|
2018-03-08 00:15:41 +01:00
|
|
|
const ccl_global KernelLight *klight = &kernel_tex_fetch(__lights, lamp);
|
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
|
|
|
if (path_flag & PATH_RAY_SHADOW_CATCHER_PASS) {
|
|
|
|
if (klight->shader_id & SHADER_EXCLUDE_SHADOW_CATCHER) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-08 00:15:41 +01:00
|
|
|
LightType type = (LightType)klight->type;
|
2012-01-20 17:49:17 +00:00
|
|
|
ls->type = type;
|
2018-03-08 00:15:41 +01:00
|
|
|
ls->shader = klight->shader_id;
|
2014-03-29 13:03:47 +01:00
|
|
|
ls->object = PRIM_NONE;
|
|
|
|
ls->prim = PRIM_NONE;
|
2013-01-30 15:57:15 +00:00
|
|
|
ls->lamp = lamp;
|
2014-02-07 15:08:50 +01:00
|
|
|
ls->u = randu;
|
|
|
|
ls->v = randv;
|
2019-04-17 06:17:24 +02: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
|
|
|
if (in_volume_segment && (type == LIGHT_DISTANT || type == LIGHT_BACKGROUND)) {
|
|
|
|
/* Distant lights in a volume get a dummy sample, position will not actually
|
|
|
|
* be used in that case. Only when sampling from a specific scatter position
|
|
|
|
* do we actually need to evaluate these. */
|
|
|
|
ls->P = zero_float3();
|
|
|
|
ls->Ng = zero_float3();
|
|
|
|
ls->D = zero_float3();
|
|
|
|
ls->pdf = true;
|
|
|
|
ls->t = FLT_MAX;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-27 20:37:24 +00:00
|
|
|
if (type == LIGHT_DISTANT) {
|
|
|
|
/* distant light */
|
2018-03-08 00:15:41 +01:00
|
|
|
float3 lightD = make_float3(klight->co[0], klight->co[1], klight->co[2]);
|
2013-01-09 21:09:20 +00:00
|
|
|
float3 D = lightD;
|
2018-03-08 00:15:41 +01:00
|
|
|
float radius = klight->distant.radius;
|
|
|
|
float invarea = klight->distant.invarea;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-09 21:09:20 +00:00
|
|
|
if (radius > 0.0f)
|
|
|
|
D = distant_light_sample(D, radius, randu, randv);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-09-27 20:37:24 +00:00
|
|
|
ls->P = D;
|
2011-10-15 23:49:01 +00:00
|
|
|
ls->Ng = D;
|
|
|
|
ls->D = -D;
|
2011-09-27 20:37:24 +00:00
|
|
|
ls->t = FLT_MAX;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-09 21:09:20 +00:00
|
|
|
float costheta = dot(lightD, D);
|
|
|
|
ls->pdf = invarea / (costheta * costheta * costheta);
|
2017-11-07 03:28:10 +01:00
|
|
|
ls->eval_fac = ls->pdf;
|
2011-09-27 20:37:24 +00:00
|
|
|
}
|
2012-01-26 19:45:59 +00:00
|
|
|
#ifdef __BACKGROUND_MIS__
|
2012-01-20 17:49:17 +00:00
|
|
|
else if (type == LIGHT_BACKGROUND) {
|
|
|
|
/* infinite area light (e.g. light dome or env light) */
|
Cycles: Added support for light portals
This patch adds support for light portals: objects that help sampling the
environment light, therefore improving convergence. Using them tor other
lights in a unidirectional pathtracer is virtually useless.
The sampling is done with the area-preserving code already used for area lamps.
MIS is used both for combination of different portals and for combining portal-
and envmap-sampling.
The direction of portals is considered, they aren't used if the sampling point
is behind them.
Reviewers: sergey, dingto, #cycles
Reviewed By: dingto, #cycles
Subscribers: Lapineige, nutel, jtheninja, dsisco11, januz, vitorbalbio, candreacchio, TARDISMaker, lichtwerk, ace_dragon, marcog, mib2berlin, Tunge, lopataasdf, lordodin, sergey, dingto
Differential Revision: https://developer.blender.org/D1133
2015-04-28 00:51:55 +05:00
|
|
|
float3 D = -background_light_sample(kg, P, randu, randv, &ls->pdf);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
ls->P = D;
|
|
|
|
ls->Ng = D;
|
|
|
|
ls->D = -D;
|
|
|
|
ls->t = FLT_MAX;
|
2012-06-04 17:17:10 +00:00
|
|
|
ls->eval_fac = 1.0f;
|
2012-01-20 17:49:17 +00:00
|
|
|
}
|
2012-01-26 19:45:59 +00:00
|
|
|
#endif
|
2011-09-27 20:37:24 +00:00
|
|
|
else {
|
2018-03-08 00:15:41 +01:00
|
|
|
ls->P = make_float3(klight->co[0], klight->co[1], klight->co[2]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-09 21:09:20 +00:00
|
|
|
if (type == LIGHT_POINT || type == LIGHT_SPOT) {
|
2018-03-08 00:15:41 +01:00
|
|
|
float radius = klight->spot.radius;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-09 21:09:20 +00:00
|
|
|
if (radius > 0.0f)
|
|
|
|
/* sphere light */
|
|
|
|
ls->P += sphere_light_sample(P, ls->P, radius, randu, randv);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-06-04 17:20:00 +00:00
|
|
|
ls->D = normalize_len(ls->P - P, &ls->t);
|
2013-01-09 21:09:20 +00:00
|
|
|
ls->Ng = -ls->D;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 00:15:41 +01:00
|
|
|
float invarea = klight->spot.invarea;
|
2013-01-09 21:09:20 +00:00
|
|
|
ls->eval_fac = (0.25f * M_1_PI_F) * invarea;
|
|
|
|
ls->pdf = invarea;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-09 21:09:20 +00:00
|
|
|
if (type == LIGHT_SPOT) {
|
2013-07-17 21:25:44 +00:00
|
|
|
/* spot light attenuation */
|
2018-03-08 00:15:41 +01:00
|
|
|
float3 dir = make_float3(klight->spot.dir[0], klight->spot.dir[1], klight->spot.dir[2]);
|
|
|
|
ls->eval_fac *= spot_light_attenuation(
|
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
|
|
|
dir, klight->spot.spot_angle, klight->spot.spot_smooth, ls->Ng);
|
2016-09-09 15:51:40 +02:00
|
|
|
if (ls->eval_fac == 0.0f) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-04 17:17:10 +00:00
|
|
|
}
|
2016-10-29 18:54:42 +02:00
|
|
|
float2 uv = map_to_sphere(ls->Ng);
|
|
|
|
ls->u = uv.x;
|
|
|
|
ls->v = uv.y;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-10 19:24:12 +06:00
|
|
|
ls->pdf *= lamp_light_pdf(kg, ls->Ng, -ls->D, ls->t);
|
2011-09-27 20:37:24 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* area light */
|
2018-03-08 00:15:41 +01:00
|
|
|
float3 axisu = make_float3(
|
|
|
|
klight->area.axisu[0], klight->area.axisu[1], klight->area.axisu[2]);
|
|
|
|
float3 axisv = make_float3(
|
|
|
|
klight->area.axisv[0], klight->area.axisv[1], klight->area.axisv[2]);
|
2021-03-22 19:27:58 +01:00
|
|
|
float3 Ng = make_float3(klight->area.dir[0], klight->area.dir[1], klight->area.dir[2]);
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 03:50:16 +02:00
|
|
|
float invarea = fabsf(klight->area.invarea);
|
|
|
|
bool is_round = (klight->area.invarea < 0.0f);
|
2019-04-17 06:17:24 +02: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
|
|
|
if (!in_volume_segment) {
|
|
|
|
if (dot(ls->P - P, Ng) > 0.0f) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-09 15:51:40 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 03:50:16 +02:00
|
|
|
float3 inplane;
|
2019-04-17 06:17:24 +02: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
|
|
|
if (is_round || in_volume_segment) {
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 03:50:16 +02:00
|
|
|
inplane = ellipse_sample(axisu * 0.5f, axisv * 0.5f, randu, randv);
|
|
|
|
ls->P += inplane;
|
|
|
|
ls->pdf = invarea;
|
|
|
|
}
|
|
|
|
else {
|
2021-04-12 16:34:50 +02:00
|
|
|
inplane = ls->P;
|
|
|
|
|
2021-03-22 19:27:58 +01:00
|
|
|
float3 sample_axisu = axisu;
|
|
|
|
float3 sample_axisv = axisv;
|
|
|
|
|
|
|
|
if (klight->area.tan_spread > 0.0f) {
|
|
|
|
if (!light_spread_clamp_area_light(
|
|
|
|
P, Ng, &ls->P, &sample_axisu, &sample_axisv, klight->area.tan_spread)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ls->pdf = rect_light_sample(P, &ls->P, sample_axisu, sample_axisv, randu, randv, true);
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 03:50:16 +02:00
|
|
|
inplane = ls->P - inplane;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-10-29 18:54:42 +02:00
|
|
|
ls->u = dot(inplane, axisu) * (1.0f / dot(axisu, axisu)) + 0.5f;
|
|
|
|
ls->v = dot(inplane, axisv) * (1.0f / dot(axisv, axisv)) + 0.5f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-03-22 19:27:58 +01:00
|
|
|
ls->Ng = Ng;
|
2013-06-04 17:20:00 +00:00
|
|
|
ls->D = normalize_len(ls->P - P, &ls->t);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-10 17:37:26 +00:00
|
|
|
ls->eval_fac = 0.25f * invarea;
|
2021-04-01 05:35:56 +02:00
|
|
|
|
|
|
|
if (klight->area.tan_spread > 0.0f) {
|
|
|
|
/* Area Light spread angle attenuation */
|
|
|
|
ls->eval_fac *= light_spread_attenuation(
|
|
|
|
ls->D, ls->Ng, klight->area.tan_spread, klight->area.normalize_spread);
|
|
|
|
}
|
|
|
|
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 03:50:16 +02:00
|
|
|
if (is_round) {
|
2021-03-22 19:27:58 +01:00
|
|
|
ls->pdf *= lamp_light_pdf(kg, Ng, -ls->D, ls->t);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 03:50:16 +02:00
|
|
|
}
|
2013-01-09 21:09:20 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-07 03:28:10 +01:00
|
|
|
ls->pdf *= kernel_data.integrator.pdf_lights;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-09-09 15:51:40 +02:00
|
|
|
return (ls->pdf > 0.0f);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device bool lights_intersect(KernelGlobals kg,
|
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_private const Ray *ccl_restrict ray,
|
|
|
|
ccl_private Intersection *ccl_restrict isect,
|
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
|
|
|
const int last_prim,
|
|
|
|
const int last_object,
|
|
|
|
const int last_type,
|
2021-10-17 20:09:45 +02:00
|
|
|
const uint32_t path_flag)
|
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
|
|
|
for (int lamp = 0; lamp < kernel_data.integrator.num_all_lights; lamp++) {
|
|
|
|
const ccl_global KernelLight *klight = &kernel_tex_fetch(__lights, lamp);
|
2019-04-17 06:17:24 +02: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
|
|
|
if (path_flag & PATH_RAY_CAMERA) {
|
|
|
|
if (klight->shader_id & SHADER_EXCLUDE_CAMERA) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!(klight->shader_id & SHADER_USE_MIS)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02: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
|
|
|
if (path_flag & PATH_RAY_SHADOW_CATCHER_PASS) {
|
|
|
|
if (klight->shader_id & SHADER_EXCLUDE_SHADOW_CATCHER) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02: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
|
|
|
LightType type = (LightType)klight->type;
|
|
|
|
float t = 0.0f, u = 0.0f, v = 0.0f;
|
2019-04-17 06:17:24 +02: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
|
|
|
if (type == LIGHT_POINT || type == LIGHT_SPOT) {
|
|
|
|
/* Sphere light. */
|
|
|
|
const float3 lightP = make_float3(klight->co[0], klight->co[1], klight->co[2]);
|
|
|
|
const float radius = klight->spot.radius;
|
|
|
|
if (radius == 0.0f) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-04-17 06:17:24 +02: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
|
|
|
float3 P;
|
|
|
|
if (!ray_aligned_disk_intersect(ray->P, ray->D, ray->t, lightP, radius, &P, &t)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == LIGHT_AREA) {
|
|
|
|
/* Area light. */
|
|
|
|
const float invarea = fabsf(klight->area.invarea);
|
|
|
|
const bool is_round = (klight->area.invarea < 0.0f);
|
|
|
|
if (invarea == 0.0f) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-04-17 06:17:24 +02: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
|
|
|
const float3 axisu = make_float3(
|
|
|
|
klight->area.axisu[0], klight->area.axisu[1], klight->area.axisu[2]);
|
|
|
|
const float3 axisv = make_float3(
|
|
|
|
klight->area.axisv[0], klight->area.axisv[1], klight->area.axisv[2]);
|
|
|
|
const float3 Ng = make_float3(klight->area.dir[0], klight->area.dir[1], klight->area.dir[2]);
|
2019-04-17 06:17:24 +02: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
|
|
|
/* One sided. */
|
|
|
|
if (dot(ray->D, Ng) >= 0.0f) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-04-17 06:17:24 +02: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
|
|
|
const float3 light_P = make_float3(klight->co[0], klight->co[1], klight->co[2]);
|
|
|
|
|
|
|
|
float3 P;
|
|
|
|
if (!ray_quad_intersect(
|
|
|
|
ray->P, ray->D, 0.0f, ray->t, light_P, axisu, axisv, Ng, &P, &t, &u, &v, is_round)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t < isect->t &&
|
|
|
|
!(last_prim == lamp && last_object == OBJECT_NONE && last_type == PRIMITIVE_LAMP)) {
|
|
|
|
isect->t = t;
|
|
|
|
isect->u = u;
|
|
|
|
isect->v = v;
|
|
|
|
isect->type = PRIMITIVE_LAMP;
|
|
|
|
isect->prim = lamp;
|
|
|
|
isect->object = OBJECT_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return isect->prim != PRIM_NONE;
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device bool light_sample_from_distant_ray(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 17:59:20 +02:00
|
|
|
const float3 ray_D,
|
|
|
|
const int lamp,
|
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_private LightSample *ccl_restrict ls)
|
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
|
|
|
{
|
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_global const KernelLight *klight = &kernel_tex_fetch(__lights, lamp);
|
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
|
|
|
const int shader = klight->shader_id;
|
|
|
|
const float radius = klight->distant.radius;
|
|
|
|
const LightType type = (LightType)klight->type;
|
|
|
|
|
|
|
|
if (type != LIGHT_DISTANT) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!(shader & SHADER_USE_MIS)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (radius == 0.0f) {
|
|
|
|
return false;
|
2013-01-09 21:09:20 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02: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
|
|
|
/* a distant light is infinitely far away, but equivalent to a disk
|
|
|
|
* shaped light exactly 1 unit away from the current shading point.
|
|
|
|
*
|
|
|
|
* radius t^2/cos(theta)
|
|
|
|
* <----------> t = sqrt(1^2 + tan(theta)^2)
|
|
|
|
* tan(th) area = radius*radius*pi
|
|
|
|
* <----->
|
|
|
|
* \ | (1 + tan(theta)^2)/cos(theta)
|
|
|
|
* \ | (1 + tan(acos(cos(theta)))^2)/cos(theta)
|
|
|
|
* t \th| 1 simplifies to
|
|
|
|
* \-| 1/(cos(theta)^3)
|
|
|
|
* \| magic!
|
|
|
|
* P
|
|
|
|
*/
|
|
|
|
|
|
|
|
float3 lightD = make_float3(klight->co[0], klight->co[1], klight->co[2]);
|
|
|
|
float costheta = dot(-lightD, ray_D);
|
|
|
|
float cosangle = klight->distant.cosangle;
|
|
|
|
|
|
|
|
if (costheta < cosangle)
|
|
|
|
return false;
|
2019-04-17 06:17:24 +02: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
|
|
|
ls->type = type;
|
|
|
|
ls->shader = klight->shader_id;
|
|
|
|
ls->object = PRIM_NONE;
|
|
|
|
ls->prim = PRIM_NONE;
|
|
|
|
ls->lamp = lamp;
|
|
|
|
/* todo: missing texture coordinates */
|
|
|
|
ls->u = 0.0f;
|
|
|
|
ls->v = 0.0f;
|
|
|
|
ls->t = FLT_MAX;
|
|
|
|
ls->P = -ray_D;
|
|
|
|
ls->Ng = -ray_D;
|
|
|
|
ls->D = ray_D;
|
|
|
|
|
|
|
|
/* compute pdf */
|
|
|
|
float invarea = klight->distant.invarea;
|
|
|
|
ls->pdf = invarea / (costheta * costheta * costheta);
|
|
|
|
ls->pdf *= kernel_data.integrator.pdf_lights;
|
|
|
|
ls->eval_fac = ls->pdf;
|
2019-04-17 06:17:24 +02: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
|
|
|
return true;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device bool light_sample_from_intersection(KernelGlobals kg,
|
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_private const Intersection *ccl_restrict isect,
|
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
|
|
|
const float3 ray_P,
|
|
|
|
const float3 ray_D,
|
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_private LightSample *ccl_restrict ls)
|
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
|
|
|
{
|
|
|
|
const int lamp = isect->prim;
|
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_global const KernelLight *klight = &kernel_tex_fetch(__lights, lamp);
|
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
|
|
|
LightType type = (LightType)klight->type;
|
|
|
|
ls->type = type;
|
|
|
|
ls->shader = klight->shader_id;
|
|
|
|
ls->object = PRIM_NONE;
|
|
|
|
ls->prim = PRIM_NONE;
|
|
|
|
ls->lamp = lamp;
|
|
|
|
/* todo: missing texture coordinates */
|
|
|
|
ls->t = isect->t;
|
|
|
|
ls->P = ray_P + ray_D * ls->t;
|
|
|
|
ls->D = ray_D;
|
|
|
|
|
|
|
|
if (type == LIGHT_POINT || type == LIGHT_SPOT) {
|
|
|
|
ls->Ng = -ray_D;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 00:15:41 +01:00
|
|
|
float invarea = klight->spot.invarea;
|
2013-01-09 21:09:20 +00:00
|
|
|
ls->eval_fac = (0.25f * M_1_PI_F) * invarea;
|
|
|
|
ls->pdf = invarea;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-09 21:09:20 +00:00
|
|
|
if (type == LIGHT_SPOT) {
|
2013-08-03 21:45:57 +00:00
|
|
|
/* spot light attenuation */
|
2018-03-08 00:15:41 +01:00
|
|
|
float3 dir = make_float3(klight->spot.dir[0], klight->spot.dir[1], klight->spot.dir[2]);
|
|
|
|
ls->eval_fac *= spot_light_attenuation(
|
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
|
|
|
dir, klight->spot.spot_angle, klight->spot.spot_smooth, ls->Ng);
|
2019-04-17 06:17:24 +02: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
|
|
|
if (ls->eval_fac == 0.0f) {
|
2013-01-09 21:09:20 +00:00
|
|
|
return false;
|
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
|
|
|
}
|
2013-01-09 21:09:20 +00:00
|
|
|
}
|
2016-10-29 18:54:42 +02:00
|
|
|
float2 uv = map_to_sphere(ls->Ng);
|
|
|
|
ls->u = uv.x;
|
|
|
|
ls->v = uv.y;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-10 19:24:12 +06:00
|
|
|
/* compute pdf */
|
|
|
|
if (ls->t != FLT_MAX)
|
|
|
|
ls->pdf *= lamp_light_pdf(kg, ls->Ng, -ls->D, ls->t);
|
2013-01-09 21:09:20 +00:00
|
|
|
}
|
|
|
|
else if (type == LIGHT_AREA) {
|
|
|
|
/* area light */
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 03:50:16 +02:00
|
|
|
float invarea = fabsf(klight->area.invarea);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 00:15:41 +01:00
|
|
|
float3 axisu = make_float3(
|
|
|
|
klight->area.axisu[0], klight->area.axisu[1], klight->area.axisu[2]);
|
|
|
|
float3 axisv = make_float3(
|
|
|
|
klight->area.axisv[0], klight->area.axisv[1], klight->area.axisv[2]);
|
|
|
|
float3 Ng = make_float3(klight->area.dir[0], klight->area.dir[1], klight->area.dir[2]);
|
|
|
|
float3 light_P = make_float3(klight->co[0], klight->co[1], klight->co[2]);
|
2019-04-17 06:17:24 +02: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
|
|
|
ls->u = isect->u;
|
|
|
|
ls->v = isect->v;
|
|
|
|
ls->D = ray_D;
|
2013-01-09 21:09:20 +00:00
|
|
|
ls->Ng = Ng;
|
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
|
|
|
|
|
|
|
const bool is_round = (klight->area.invarea < 0.0f);
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 03:50:16 +02:00
|
|
|
if (is_round) {
|
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
|
|
|
ls->pdf = invarea * lamp_light_pdf(kg, Ng, -ray_D, ls->t);
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 03:50:16 +02:00
|
|
|
}
|
|
|
|
else {
|
2021-03-22 19:27:58 +01:00
|
|
|
float3 sample_axisu = axisu;
|
|
|
|
float3 sample_axisv = axisv;
|
|
|
|
|
|
|
|
if (klight->area.tan_spread > 0.0f) {
|
|
|
|
if (!light_spread_clamp_area_light(
|
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
|
|
|
ray_P, Ng, &light_P, &sample_axisu, &sample_axisv, klight->area.tan_spread)) {
|
2021-03-22 19:27:58 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
ls->pdf = rect_light_sample(ray_P, &light_P, sample_axisu, sample_axisv, 0, 0, false);
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 03:50:16 +02:00
|
|
|
}
|
2014-10-10 19:24:12 +06:00
|
|
|
ls->eval_fac = 0.25f * invarea;
|
2021-04-01 05:35:56 +02:00
|
|
|
|
|
|
|
if (klight->area.tan_spread > 0.0f) {
|
|
|
|
/* Area Light spread angle attenuation */
|
|
|
|
ls->eval_fac *= light_spread_attenuation(
|
|
|
|
ls->D, ls->Ng, klight->area.tan_spread, klight->area.normalize_spread);
|
|
|
|
if (ls->eval_fac == 0.0f) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-01-09 21:09:20 +00:00
|
|
|
}
|
2017-11-07 03:28:10 +01:00
|
|
|
else {
|
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
|
|
|
kernel_assert(!"Invalid lamp type in light_sample_from_intersection");
|
2013-01-09 21:09:20 +00:00
|
|
|
return false;
|
2017-11-07 03:28:10 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-07 03:28:10 +01:00
|
|
|
ls->pdf *= kernel_data.integrator.pdf_lights;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-09 21:09:20 +00:00
|
|
|
return true;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Triangle Light */
|
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
/* returns true if the triangle is has motion blur or an instancing transform applied */
|
|
|
|
ccl_device_inline bool triangle_world_space_vertices(
|
2021-10-17 16:10:10 +02:00
|
|
|
KernelGlobals kg, int object, int prim, float time, float3 V[3])
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-08-17 12:44:09 +02:00
|
|
|
bool has_motion = false;
|
|
|
|
const int object_flag = kernel_tex_fetch(__object_flag, object);
|
|
|
|
|
|
|
|
if (object_flag & SD_OBJECT_HAS_VERTEX_MOTION && time >= 0.0f) {
|
|
|
|
motion_triangle_vertices(kg, object, prim, time, V);
|
|
|
|
has_motion = true;
|
2017-09-08 03:21:50 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-08-17 12:44:09 +02:00
|
|
|
triangle_vertices(kg, prim, V);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(object_flag & SD_OBJECT_TRANSFORM_APPLIED)) {
|
2020-02-23 10:15:35 +01:00
|
|
|
#ifdef __OBJECT_MOTION__
|
2018-03-08 04:04:52 +01:00
|
|
|
float object_time = (time >= 0.0f) ? time : 0.5f;
|
|
|
|
Transform tfm = object_fetch_transform_motion_test(kg, object, object_time, NULL);
|
2020-02-23 10:15:35 +01:00
|
|
|
#else
|
2013-01-09 21:09:20 +00:00
|
|
|
Transform tfm = object_fetch_transform(kg, object, OBJECT_TRANSFORM);
|
2020-02-23 10:15:35 +01:00
|
|
|
#endif
|
2017-08-17 12:44:09 +02:00
|
|
|
V[0] = transform_point(&tfm, V[0]);
|
|
|
|
V[1] = transform_point(&tfm, V[1]);
|
|
|
|
V[2] = transform_point(&tfm, V[2]);
|
|
|
|
has_motion = true;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2017-08-17 12:44:09 +02:00
|
|
|
return has_motion;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_inline float triangle_light_pdf_area(KernelGlobals kg,
|
2017-08-17 12:44:09 +02:00
|
|
|
const float3 Ng,
|
|
|
|
const float3 I,
|
|
|
|
float t)
|
2013-01-09 21:09:20 +00:00
|
|
|
{
|
2017-08-17 12:44:09 +02:00
|
|
|
float pdf = kernel_data.integrator.pdf_triangles;
|
|
|
|
float cos_pi = fabsf(dot(Ng, I));
|
2014-02-07 15:08:50 +01:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
if (cos_pi == 0.0f)
|
|
|
|
return 0.0f;
|
2014-02-07 15:08:50 +01:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
return t * t * pdf / cos_pi;
|
|
|
|
}
|
2014-02-07 15:08:50 +01:00
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_forceinline float triangle_light_pdf(KernelGlobals kg,
|
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_private const ShaderData *sd,
|
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
|
|
|
float t)
|
2017-08-17 12:44:09 +02:00
|
|
|
{
|
|
|
|
/* A naive heuristic to decide between costly solid angle sampling
|
|
|
|
* and simple area sampling, comparing the distance to the triangle plane
|
2017-08-30 11:47:33 +02:00
|
|
|
* to the length of the edges of the triangle. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
float3 V[3];
|
|
|
|
bool has_motion = triangle_world_space_vertices(kg, sd->object, sd->prim, sd->time, V);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
const float3 e0 = V[1] - V[0];
|
|
|
|
const float3 e1 = V[2] - V[0];
|
|
|
|
const float3 e2 = V[2] - V[1];
|
|
|
|
const float longest_edge_squared = max(len_squared(e0), max(len_squared(e1), len_squared(e2)));
|
|
|
|
const float3 N = cross(e0, e1);
|
|
|
|
const float distance_to_plane = fabsf(dot(N, sd->I * t)) / dot(N, N);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
if (longest_edge_squared > distance_to_plane * distance_to_plane) {
|
|
|
|
/* sd contains the point on the light source
|
|
|
|
* calculate Px, the point that we're shading */
|
|
|
|
const float3 Px = sd->P + sd->I * t;
|
|
|
|
const float3 v0_p = V[0] - Px;
|
|
|
|
const float3 v1_p = V[1] - Px;
|
|
|
|
const float3 v2_p = V[2] - Px;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
const float3 u01 = safe_normalize(cross(v0_p, v1_p));
|
|
|
|
const float3 u02 = safe_normalize(cross(v0_p, v2_p));
|
|
|
|
const float3 u12 = safe_normalize(cross(v1_p, v2_p));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
const float alpha = fast_acosf(dot(u02, u01));
|
|
|
|
const float beta = fast_acosf(-dot(u01, u12));
|
|
|
|
const float gamma = fast_acosf(dot(u02, u12));
|
|
|
|
const float solid_angle = alpha + beta + gamma - M_PI_F;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
/* pdf_triangles is calculated over triangle area, but we're not sampling over its area */
|
|
|
|
if (UNLIKELY(solid_angle == 0.0f)) {
|
|
|
|
return 0.0f;
|
2017-09-08 03:21:50 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-08-17 12:44:09 +02:00
|
|
|
float area = 1.0f;
|
|
|
|
if (has_motion) {
|
|
|
|
/* get the center frame vertices, this is what the PDF was calculated from */
|
|
|
|
triangle_world_space_vertices(kg, sd->object, sd->prim, -1.0f, V);
|
|
|
|
area = triangle_area(V[0], V[1], V[2]);
|
2017-09-08 03:21:50 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-08-17 12:44:09 +02:00
|
|
|
area = 0.5f * len(N);
|
|
|
|
}
|
|
|
|
const float pdf = area * kernel_data.integrator.pdf_triangles;
|
|
|
|
return pdf / solid_angle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
float pdf = triangle_light_pdf_area(kg, sd->Ng, sd->I, t);
|
|
|
|
if (has_motion) {
|
|
|
|
const float area = 0.5f * len(N);
|
|
|
|
if (UNLIKELY(area == 0.0f)) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
/* scale the PDF.
|
|
|
|
* area = the area the sample was taken from
|
|
|
|
* area_pre = the are from which pdf_triangles was calculated from */
|
|
|
|
triangle_world_space_vertices(kg, sd->object, sd->prim, -1.0f, V);
|
|
|
|
const float area_pre = triangle_area(V[0], V[1], V[2]);
|
|
|
|
pdf = pdf * area_pre / area;
|
|
|
|
}
|
|
|
|
return pdf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
template<bool in_volume_segment>
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_forceinline void triangle_light_sample(KernelGlobals kg,
|
2017-08-17 12:44:09 +02:00
|
|
|
int prim,
|
|
|
|
int object,
|
|
|
|
float randu,
|
|
|
|
float randv,
|
|
|
|
float time,
|
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_private LightSample *ls,
|
2017-08-17 12:44:09 +02:00
|
|
|
const float3 P)
|
|
|
|
{
|
|
|
|
/* A naive heuristic to decide between costly solid angle sampling
|
|
|
|
* and simple area sampling, comparing the distance to the triangle plane
|
2017-08-30 11:47:33 +02:00
|
|
|
* to the length of the edges of the triangle. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
float3 V[3];
|
|
|
|
bool has_motion = triangle_world_space_vertices(kg, object, prim, time, V);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
const float3 e0 = V[1] - V[0];
|
|
|
|
const float3 e1 = V[2] - V[0];
|
|
|
|
const float3 e2 = V[2] - V[1];
|
|
|
|
const float longest_edge_squared = max(len_squared(e0), max(len_squared(e1), len_squared(e2)));
|
|
|
|
const float3 N0 = cross(e0, e1);
|
|
|
|
float Nl = 0.0f;
|
|
|
|
ls->Ng = safe_normalize_len(N0, &Nl);
|
|
|
|
float area = 0.5f * Nl;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
/* flip normal if necessary */
|
|
|
|
const int object_flag = kernel_tex_fetch(__object_flag, object);
|
2017-09-06 13:46:27 +02:00
|
|
|
if (object_flag & SD_OBJECT_NEGATIVE_SCALE_APPLIED) {
|
2017-08-17 12:44:09 +02:00
|
|
|
ls->Ng = -ls->Ng;
|
|
|
|
}
|
|
|
|
ls->eval_fac = 1.0f;
|
|
|
|
ls->shader = kernel_tex_fetch(__tri_shader, prim);
|
2013-01-09 21:09:20 +00:00
|
|
|
ls->object = object;
|
|
|
|
ls->prim = prim;
|
2014-03-29 13:03:47 +01:00
|
|
|
ls->lamp = LAMP_NONE;
|
2013-01-30 15:57:15 +00:00
|
|
|
ls->shader |= SHADER_USE_MIS;
|
2013-02-11 22:41:11 +00:00
|
|
|
ls->type = LIGHT_TRIANGLE;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
float distance_to_plane = fabsf(dot(N0, V[0] - P) / dot(N0, N0));
|
2019-04-17 06:17:24 +02: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
|
|
|
if (!in_volume_segment && (longest_edge_squared > distance_to_plane * distance_to_plane)) {
|
2017-08-17 12:44:09 +02:00
|
|
|
/* see James Arvo, "Stratified Sampling of Spherical Triangles"
|
|
|
|
* http://www.graphics.cornell.edu/pubs/1995/Arv95c.pdf */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
/* project the triangle to the unit sphere
|
|
|
|
* and calculate its edges and angles */
|
|
|
|
const float3 v0_p = V[0] - P;
|
|
|
|
const float3 v1_p = V[1] - P;
|
|
|
|
const float3 v2_p = V[2] - P;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
const float3 u01 = safe_normalize(cross(v0_p, v1_p));
|
|
|
|
const float3 u02 = safe_normalize(cross(v0_p, v2_p));
|
|
|
|
const float3 u12 = safe_normalize(cross(v1_p, v2_p));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
const float3 A = safe_normalize(v0_p);
|
|
|
|
const float3 B = safe_normalize(v1_p);
|
|
|
|
const float3 C = safe_normalize(v2_p);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
const float cos_alpha = dot(u02, u01);
|
|
|
|
const float cos_beta = -dot(u01, u12);
|
|
|
|
const float cos_gamma = dot(u02, u12);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
/* calculate dihedral angles */
|
|
|
|
const float alpha = fast_acosf(cos_alpha);
|
|
|
|
const float beta = fast_acosf(cos_beta);
|
|
|
|
const float gamma = fast_acosf(cos_gamma);
|
|
|
|
/* the area of the unit spherical triangle = solid angle */
|
|
|
|
const float solid_angle = alpha + beta + gamma - M_PI_F;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
/* precompute a few things
|
|
|
|
* these could be re-used to take several samples
|
|
|
|
* as they are independent of randu/randv */
|
|
|
|
const float cos_c = dot(A, B);
|
|
|
|
const float sin_alpha = fast_sinf(alpha);
|
|
|
|
const float product = sin_alpha * cos_c;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
/* Select a random sub-area of the spherical triangle
|
|
|
|
* and calculate the third vertex C_ of that new triangle */
|
|
|
|
const float phi = randu * solid_angle - alpha;
|
|
|
|
float s, t;
|
|
|
|
fast_sincosf(phi, &s, &t);
|
|
|
|
const float u = t - cos_alpha;
|
|
|
|
const float v = s + product;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
const float3 U = safe_normalize(C - dot(C, A) * A);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 15:05:48 +02:00
|
|
|
float q = 1.0f;
|
|
|
|
const float det = ((v * s + u * t) * sin_alpha);
|
|
|
|
if (det != 0.0f) {
|
|
|
|
q = ((v * t - u * s) * cos_alpha - v) / det;
|
|
|
|
}
|
2017-08-17 12:44:09 +02:00
|
|
|
const float temp = max(1.0f - q * q, 0.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
const float3 C_ = safe_normalize(q * A + sqrtf(temp) * U);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-31 14:47:49 +02:00
|
|
|
/* Finally, select a random point along the edge of the new triangle
|
2017-08-17 12:44:09 +02:00
|
|
|
* That point on the spherical triangle is the sampled ray direction */
|
|
|
|
const float z = 1.0f - randv * (1.0f - dot(C_, B));
|
|
|
|
ls->D = z * B + safe_sqrtf(1.0f - z * z) * safe_normalize(C_ - dot(C_, B) * B);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-30 11:47:33 +02:00
|
|
|
/* calculate intersection with the planar triangle */
|
2017-09-08 03:21:50 +02:00
|
|
|
if (!ray_triangle_intersect(P,
|
|
|
|
ls->D,
|
|
|
|
FLT_MAX,
|
2017-08-30 11:47:33 +02:00
|
|
|
#if defined(__KERNEL_SSE2__) && defined(__KERNEL_SSE__)
|
2017-09-08 03:21:50 +02:00
|
|
|
(ssef *)V,
|
2017-08-30 11:47:33 +02:00
|
|
|
#else
|
2017-09-08 03:21:50 +02:00
|
|
|
V[0],
|
|
|
|
V[1],
|
|
|
|
V[2],
|
2017-08-30 11:47:33 +02:00
|
|
|
#endif
|
2017-09-08 03:21:50 +02:00
|
|
|
&ls->u,
|
|
|
|
&ls->v,
|
|
|
|
&ls->t)) {
|
|
|
|
ls->pdf = 0.0f;
|
|
|
|
return;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
ls->P = P + ls->D * ls->t;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
/* pdf_triangles is calculated over triangle area, but we're sampling over solid angle */
|
|
|
|
if (UNLIKELY(solid_angle == 0.0f)) {
|
|
|
|
ls->pdf = 0.0f;
|
2017-09-08 03:21:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
2017-08-17 12:44:09 +02:00
|
|
|
if (has_motion) {
|
|
|
|
/* get the center frame vertices, this is what the PDF was calculated from */
|
|
|
|
triangle_world_space_vertices(kg, object, prim, -1.0f, V);
|
|
|
|
area = triangle_area(V[0], V[1], V[2]);
|
|
|
|
}
|
|
|
|
const float pdf = area * kernel_data.integrator.pdf_triangles;
|
|
|
|
ls->pdf = pdf / solid_angle;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2017-08-17 12:44:09 +02:00
|
|
|
else {
|
2020-05-23 14:21:49 +02:00
|
|
|
/* compute random point in triangle. From Eric Heitz's "A Low-Distortion Map Between Triangle
|
|
|
|
* and Square" */
|
|
|
|
float u = randu;
|
|
|
|
float v = randv;
|
|
|
|
if (v > u) {
|
|
|
|
u *= 0.5f;
|
|
|
|
v -= u;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
v *= 0.5f;
|
|
|
|
u -= v;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-17 12:44:09 +02:00
|
|
|
const float t = 1.0f - u - v;
|
|
|
|
ls->P = u * V[0] + v * V[1] + t * V[2];
|
|
|
|
/* compute incoming direction, distance and pdf */
|
|
|
|
ls->D = normalize_len(ls->P - P, &ls->t);
|
|
|
|
ls->pdf = triangle_light_pdf_area(kg, ls->Ng, -ls->D, ls->t);
|
|
|
|
if (has_motion && area != 0.0f) {
|
|
|
|
/* scale the PDF.
|
|
|
|
* area = the area the sample was taken from
|
|
|
|
* area_pre = the are from which pdf_triangles was calculated from */
|
|
|
|
triangle_world_space_vertices(kg, object, prim, -1.0f, V);
|
|
|
|
const float area_pre = triangle_area(V[0], V[1], V[2]);
|
|
|
|
ls->pdf = ls->pdf * area_pre / area;
|
|
|
|
}
|
|
|
|
ls->u = u;
|
|
|
|
ls->v = v;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Light Distribution */
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device int light_distribution_sample(KernelGlobals kg, ccl_private float *randu)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-11-20 11:39:03 +11:00
|
|
|
/* This is basically std::upper_bound as used by PBRT, to find a point light or
|
2012-06-09 17:22:52 +00:00
|
|
|
* triangle to emit from, proportional to area. a good improvement would be to
|
|
|
|
* also sample proportional to power, though it's not so well defined with
|
Cycles: improve sample stratification on area lights for path tracing.
Previously we used a 1D sequence to select a light, and another 2D sequence
to sample a point on the light. For multiple lights this meant each light
would get a random subset of a 2D stratified sequence, which is not
guaranteed to be stratified anymore.
Now we use only a 2D sequence, split into segments along the X axis, one for
each light. The samples that fall within a segment then each are a stratified
sequence, at least in the limit. So for example for two lights, we split up
the unit square into two segments [0,0.5[ x [0,1[ and [0.5,1[ x [0,1[.
This doesn't make much difference in most scenes, mainly helps if you have a
few large area lights or some types of HDR backgrounds.
2017-09-08 01:42:14 +02:00
|
|
|
* arbitrary shaders. */
|
2011-04-27 11:58:34 +00:00
|
|
|
int first = 0;
|
|
|
|
int len = kernel_data.integrator.num_distribution + 1;
|
Cycles: improve sample stratification on area lights for path tracing.
Previously we used a 1D sequence to select a light, and another 2D sequence
to sample a point on the light. For multiple lights this meant each light
would get a random subset of a 2D stratified sequence, which is not
guaranteed to be stratified anymore.
Now we use only a 2D sequence, split into segments along the X axis, one for
each light. The samples that fall within a segment then each are a stratified
sequence, at least in the limit. So for example for two lights, we split up
the unit square into two segments [0,0.5[ x [0,1[ and [0.5,1[ x [0,1[.
This doesn't make much difference in most scenes, mainly helps if you have a
few large area lights or some types of HDR backgrounds.
2017-09-08 01:42:14 +02:00
|
|
|
float r = *randu;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-25 18:11:41 +02:00
|
|
|
do {
|
2011-04-27 11:58:34 +00:00
|
|
|
int half_len = len >> 1;
|
|
|
|
int middle = first + half_len;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 00:15:41 +01:00
|
|
|
if (r < kernel_tex_fetch(__light_distribution, middle).totarea) {
|
2011-04-27 11:58:34 +00:00
|
|
|
len = half_len;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
first = middle + 1;
|
|
|
|
len = len - half_len - 1;
|
|
|
|
}
|
2019-08-25 18:11:41 +02:00
|
|
|
} while (len > 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: improve sample stratification on area lights for path tracing.
Previously we used a 1D sequence to select a light, and another 2D sequence
to sample a point on the light. For multiple lights this meant each light
would get a random subset of a 2D stratified sequence, which is not
guaranteed to be stratified anymore.
Now we use only a 2D sequence, split into segments along the X axis, one for
each light. The samples that fall within a segment then each are a stratified
sequence, at least in the limit. So for example for two lights, we split up
the unit square into two segments [0,0.5[ x [0,1[ and [0.5,1[ x [0,1[.
This doesn't make much difference in most scenes, mainly helps if you have a
few large area lights or some types of HDR backgrounds.
2017-09-08 01:42:14 +02:00
|
|
|
/* Clamping should not be needed but float rounding errors seem to
|
|
|
|
* make this fail on rare occasions. */
|
|
|
|
int index = clamp(first - 1, 0, kernel_data.integrator.num_distribution - 1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: improve sample stratification on area lights for path tracing.
Previously we used a 1D sequence to select a light, and another 2D sequence
to sample a point on the light. For multiple lights this meant each light
would get a random subset of a 2D stratified sequence, which is not
guaranteed to be stratified anymore.
Now we use only a 2D sequence, split into segments along the X axis, one for
each light. The samples that fall within a segment then each are a stratified
sequence, at least in the limit. So for example for two lights, we split up
the unit square into two segments [0,0.5[ x [0,1[ and [0.5,1[ x [0,1[.
This doesn't make much difference in most scenes, mainly helps if you have a
few large area lights or some types of HDR backgrounds.
2017-09-08 01:42:14 +02:00
|
|
|
/* Rescale to reuse random number. this helps the 2D samples within
|
|
|
|
* each area light be stratified as well. */
|
2018-03-08 00:15:41 +01:00
|
|
|
float distr_min = kernel_tex_fetch(__light_distribution, index).totarea;
|
|
|
|
float distr_max = kernel_tex_fetch(__light_distribution, index + 1).totarea;
|
Cycles: improve sample stratification on area lights for path tracing.
Previously we used a 1D sequence to select a light, and another 2D sequence
to sample a point on the light. For multiple lights this meant each light
would get a random subset of a 2D stratified sequence, which is not
guaranteed to be stratified anymore.
Now we use only a 2D sequence, split into segments along the X axis, one for
each light. The samples that fall within a segment then each are a stratified
sequence, at least in the limit. So for example for two lights, we split up
the unit square into two segments [0,0.5[ x [0,1[ and [0.5,1[ x [0,1[.
This doesn't make much difference in most scenes, mainly helps if you have a
few large area lights or some types of HDR backgrounds.
2017-09-08 01:42:14 +02:00
|
|
|
*randu = (r - distr_min) / (distr_max - distr_min);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: improve sample stratification on area lights for path tracing.
Previously we used a 1D sequence to select a light, and another 2D sequence
to sample a point on the light. For multiple lights this meant each light
would get a random subset of a 2D stratified sequence, which is not
guaranteed to be stratified anymore.
Now we use only a 2D sequence, split into segments along the X axis, one for
each light. The samples that fall within a segment then each are a stratified
sequence, at least in the limit. So for example for two lights, we split up
the unit square into two segments [0,0.5[ x [0,1[ and [0.5,1[ x [0,1[.
This doesn't make much difference in most scenes, mainly helps if you have a
few large area lights or some types of HDR backgrounds.
2017-09-08 01:42:14 +02:00
|
|
|
return index;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Generic Light */
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_inline bool light_select_reached_max_bounces(KernelGlobals kg, int index, int bounce)
|
2014-11-05 22:48:45 +01:00
|
|
|
{
|
2018-03-08 00:15:41 +01:00
|
|
|
return (bounce > kernel_tex_fetch(__lights, index).max_bounces);
|
2014-11-05 22:48:45 +01: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
|
|
|
template<bool in_volume_segment>
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_noinline bool light_distribution_sample(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 17:59:20 +02:00
|
|
|
float randu,
|
|
|
|
const float randv,
|
|
|
|
const float time,
|
|
|
|
const float3 P,
|
|
|
|
const int bounce,
|
2021-10-17 20:09:45 +02:00
|
|
|
const uint32_t path_flag,
|
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_private LightSample *ls)
|
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
|
|
|
/* Sample light index from distribution. */
|
|
|
|
const int index = light_distribution_sample(kg, &randu);
|
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_global const KernelLightDistribution *kdistribution = &kernel_tex_fetch(__light_distribution,
|
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
|
|
|
index);
|
|
|
|
const int prim = kdistribution->prim;
|
|
|
|
|
|
|
|
if (prim >= 0) {
|
|
|
|
/* Mesh light. */
|
|
|
|
const int object = kdistribution->mesh_light.object_id;
|
|
|
|
|
|
|
|
/* Exclude synthetic meshes from shadow catcher pass. */
|
|
|
|
if ((path_flag & PATH_RAY_SHADOW_CATCHER_PASS) &&
|
|
|
|
!(kernel_tex_fetch(__object_flag, object) & SD_OBJECT_SHADOW_CATCHER)) {
|
|
|
|
return false;
|
2019-08-25 18:11:41 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02: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
|
|
|
const int shader_flag = kdistribution->mesh_light.shader_flag;
|
|
|
|
triangle_light_sample<in_volume_segment>(kg, prim, object, randu, randv, time, ls, P);
|
|
|
|
ls->shader |= shader_flag;
|
|
|
|
return (ls->pdf > 0.0f);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02: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
|
|
|
const int lamp = -prim - 1;
|
|
|
|
|
2019-08-25 18:11:41 +02:00
|
|
|
if (UNLIKELY(light_select_reached_max_bounces(kg, lamp, bounce))) {
|
|
|
|
return false;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-08-25 18:11:41 +02: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
|
|
|
return light_sample<in_volume_segment>(kg, lamp, randu, randv, P, path_flag, ls);
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_inline bool light_distribution_sample_from_volume_segment(KernelGlobals kg,
|
|
|
|
float randu,
|
|
|
|
const float randv,
|
|
|
|
const float time,
|
|
|
|
const float3 P,
|
|
|
|
const int bounce,
|
2021-10-17 20:09:45 +02:00
|
|
|
const uint32_t path_flag,
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_private LightSample *ls)
|
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
|
|
|
{
|
|
|
|
return light_distribution_sample<true>(kg, randu, randv, time, P, bounce, path_flag, ls);
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_inline bool light_distribution_sample_from_position(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 17:59:20 +02:00
|
|
|
float randu,
|
|
|
|
const float randv,
|
|
|
|
const float time,
|
|
|
|
const float3 P,
|
|
|
|
const int bounce,
|
2021-10-17 20:09:45 +02:00
|
|
|
const uint32_t path_flag,
|
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_private LightSample *ls)
|
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
|
|
|
{
|
|
|
|
return light_distribution_sample<false>(kg, randu, randv, time, P, bounce, path_flag, ls);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_inline bool light_distribution_sample_new_position(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 17:59:20 +02:00
|
|
|
const float randu,
|
|
|
|
const float randv,
|
|
|
|
const float time,
|
|
|
|
const float3 P,
|
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_private LightSample *ls)
|
2012-06-13 11:44:48 +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
|
|
|
/* Sample a new position on the same light, for volume sampling. */
|
|
|
|
if (ls->type == LIGHT_TRIANGLE) {
|
|
|
|
triangle_light_sample<false>(kg, ls->prim, ls->object, randu, randv, time, ls, P);
|
|
|
|
return (ls->pdf > 0.0f);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return light_sample<false>(kg, ls->lamp, randu, randv, P, 0, ls);
|
|
|
|
}
|
2012-06-13 11:44:48 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|