2017-08-18 18:37:05 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2011-2013 Blender Foundation
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#pragma once
|
|
|
|
|
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
|
|
|
#include "kernel/bvh/bvh.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "kernel/sample/mapping.h"
|
|
|
|
#include "kernel/sample/pattern.h"
|
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
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2019-08-21 12:04:40 +02:00
|
|
|
#ifdef __SHADER_RAYTRACE__
|
|
|
|
|
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
|
|
|
/* Planar Cubic BSSRDF falloff, reused for bevel.
|
|
|
|
*
|
|
|
|
* This is basically (Rm - x)^3, with some factors to normalize it. For sampling
|
|
|
|
* we integrate 2*pi*x * (Rm - x)^3, which gives us a quintic equation that as
|
|
|
|
* far as I can tell has no closed form solution. So we get an iterative solution
|
|
|
|
* instead with newton-raphson. */
|
|
|
|
|
|
|
|
ccl_device float svm_bevel_cubic_eval(const float radius, float r)
|
|
|
|
{
|
|
|
|
const float Rm = radius;
|
|
|
|
|
|
|
|
if (r >= Rm)
|
|
|
|
return 0.0f;
|
|
|
|
|
|
|
|
/* integrate (2*pi*r * 10*(R - r)^3)/(pi * R^5) from 0 to R = 1 */
|
|
|
|
const float Rm5 = (Rm * Rm) * (Rm * Rm) * Rm;
|
|
|
|
const float f = Rm - r;
|
|
|
|
const float num = f * f * f;
|
|
|
|
|
|
|
|
return (10.0f * num) / (Rm5 * M_PI_F);
|
|
|
|
}
|
|
|
|
|
|
|
|
ccl_device float svm_bevel_cubic_pdf(const float radius, float r)
|
|
|
|
{
|
|
|
|
return svm_bevel_cubic_eval(radius, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* solve 10x^2 - 20x^3 + 15x^4 - 4x^5 - xi == 0 */
|
|
|
|
ccl_device_forceinline float svm_bevel_cubic_quintic_root_find(float xi)
|
|
|
|
{
|
|
|
|
/* newton-raphson iteration, usually succeeds in 2-4 iterations, except
|
|
|
|
* outside 0.02 ... 0.98 where it can go up to 10, so overall performance
|
|
|
|
* should not be too bad */
|
|
|
|
const float tolerance = 1e-6f;
|
|
|
|
const int max_iteration_count = 10;
|
|
|
|
float x = 0.25f;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < max_iteration_count; i++) {
|
|
|
|
float x2 = x * x;
|
|
|
|
float x3 = x2 * x;
|
|
|
|
float nx = (1.0f - x);
|
|
|
|
|
|
|
|
float f = 10.0f * x2 - 20.0f * x3 + 15.0f * x2 * x2 - 4.0f * x2 * x3 - xi;
|
|
|
|
float f_ = 20.0f * (x * nx) * (nx * nx);
|
|
|
|
|
|
|
|
if (fabsf(f) < tolerance || f_ == 0.0f)
|
|
|
|
break;
|
|
|
|
|
2021-10-27 13:28:13 +02:00
|
|
|
x = saturatef(x - f / f_);
|
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 x;
|
|
|
|
}
|
|
|
|
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_device void svm_bevel_cubic_sample(const float radius,
|
|
|
|
float xi,
|
|
|
|
ccl_private float *r,
|
|
|
|
ccl_private float *h)
|
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 Rm = radius;
|
|
|
|
float r_ = svm_bevel_cubic_quintic_root_find(xi);
|
|
|
|
|
|
|
|
r_ *= Rm;
|
|
|
|
*r = r_;
|
|
|
|
|
|
|
|
/* h^2 + r^2 = Rm^2 */
|
|
|
|
*h = safe_sqrtf(Rm * Rm - r_ * r_);
|
|
|
|
}
|
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Bevel shader averaging normals from nearby surfaces.
|
|
|
|
*
|
|
|
|
* Sampling strategy from: BSSRDF Importance Sampling, SIGGRAPH 2013
|
|
|
|
* http://library.imageworks.com/pdfs/imageworks-library-BSSRDF-sampling.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
|
|
|
# ifdef __KERNEL_OPTIX__
|
2021-10-17 16:22:20 +02:00
|
|
|
extern "C" __device__ float3 __direct_callable__svm_node_bevel(
|
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
|
|
|
# else
|
2021-10-17 16:22:20 +02:00
|
|
|
ccl_device float3 svm_bevel(
|
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
|
|
|
# endif
|
2021-10-17 16:22:20 +02:00
|
|
|
KernelGlobals kg,
|
|
|
|
ConstIntegratorState state,
|
|
|
|
ccl_private ShaderData *sd,
|
|
|
|
float radius,
|
|
|
|
int num_samples)
|
2017-08-18 18:37:05 +02:00
|
|
|
{
|
|
|
|
/* Early out if no sampling needed. */
|
|
|
|
if (radius <= 0.0f || num_samples < 1 || sd->object == OBJECT_NONE) {
|
|
|
|
return sd->N;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-06 19:50:05 +01:00
|
|
|
/* Can't raytrace from shaders like displacement, before BVH exists. */
|
|
|
|
if (kernel_data.bvh.bvh_layout == BVH_LAYOUT_NONE) {
|
|
|
|
return sd->N;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Don't bevel for blurry indirect rays. */
|
2021-10-17 16:10:10 +02:00
|
|
|
if (INTEGRATOR_STATE(state, path, min_ray_pdf) < 8.0f) {
|
2017-08-18 18:37:05 +02:00
|
|
|
return sd->N;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Setup for multi intersection. */
|
|
|
|
LocalIntersection isect;
|
2021-10-17 16:10:10 +02:00
|
|
|
uint lcg_state = lcg_state_init(INTEGRATOR_STATE(state, path, rng_hash),
|
|
|
|
INTEGRATOR_STATE(state, path, rng_offset),
|
|
|
|
INTEGRATOR_STATE(state, path, sample),
|
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
|
|
|
0x64c6a40e);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Sample normals from surrounding points on surface. */
|
|
|
|
float3 sum_N = make_float3(0.0f, 0.0f, 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
|
|
|
/* TODO: support ray-tracing in shadow shader evaluation? */
|
|
|
|
RNGState rng_state;
|
2021-10-17 16:10:10 +02:00
|
|
|
path_state_rng_load(state, &rng_state);
|
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
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
for (int sample = 0; sample < num_samples; sample++) {
|
2019-12-05 19:17:01 +01:00
|
|
|
float disk_u, disk_v;
|
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
|
|
|
path_branched_rng_2D(kg, &rng_state, sample, num_samples, PRNG_BEVEL_U, &disk_u, &disk_v);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Pick random axis in local frame and point on disk. */
|
|
|
|
float3 disk_N, disk_T, disk_B;
|
|
|
|
float pick_pdf_N, pick_pdf_T, pick_pdf_B;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
disk_N = sd->Ng;
|
|
|
|
make_orthonormals(disk_N, &disk_T, &disk_B);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
float axisu = disk_u;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
if (axisu < 0.5f) {
|
|
|
|
pick_pdf_N = 0.5f;
|
|
|
|
pick_pdf_T = 0.25f;
|
|
|
|
pick_pdf_B = 0.25f;
|
|
|
|
disk_u *= 2.0f;
|
|
|
|
}
|
|
|
|
else if (axisu < 0.75f) {
|
|
|
|
float3 tmp = disk_N;
|
|
|
|
disk_N = disk_T;
|
|
|
|
disk_T = tmp;
|
|
|
|
pick_pdf_N = 0.25f;
|
|
|
|
pick_pdf_T = 0.5f;
|
|
|
|
pick_pdf_B = 0.25f;
|
|
|
|
disk_u = (disk_u - 0.5f) * 4.0f;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
float3 tmp = disk_N;
|
|
|
|
disk_N = disk_B;
|
|
|
|
disk_B = tmp;
|
|
|
|
pick_pdf_N = 0.25f;
|
|
|
|
pick_pdf_T = 0.25f;
|
|
|
|
pick_pdf_B = 0.5f;
|
|
|
|
disk_u = (disk_u - 0.75f) * 4.0f;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Sample point on disk. */
|
|
|
|
float phi = M_2PI_F * disk_u;
|
|
|
|
float disk_r = disk_v;
|
|
|
|
float disk_height;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Perhaps find something better than Cubic BSSRDF, but happens to work well. */
|
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
|
|
|
svm_bevel_cubic_sample(radius, disk_r, &disk_r, &disk_height);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
float3 disk_P = (disk_r * cosf(phi)) * disk_T + (disk_r * sinf(phi)) * disk_B;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Create ray. */
|
2021-10-07 17:05:25 +02:00
|
|
|
Ray ray ccl_optional_struct_init;
|
|
|
|
ray.P = sd->P + disk_N * disk_height + disk_P;
|
|
|
|
ray.D = -disk_N;
|
|
|
|
ray.t = 2.0f * disk_height;
|
|
|
|
ray.dP = differential_zero_compact();
|
|
|
|
ray.dD = differential_zero_compact();
|
|
|
|
ray.time = sd->time;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Intersect with the same object. if multiple intersections are found it
|
|
|
|
* will use at most LOCAL_MAX_HITS hits, a random subset of all hits. */
|
2021-10-07 17:05:25 +02:00
|
|
|
scene_intersect_local(kg, &ray, &isect, sd->object, &lcg_state, LOCAL_MAX_HITS);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
int num_eval_hits = min(isect.num_hits, LOCAL_MAX_HITS);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
for (int hit = 0; hit < num_eval_hits; hit++) {
|
|
|
|
/* Quickly retrieve P and Ng without setting up ShaderData. */
|
|
|
|
float3 hit_P;
|
2021-12-20 02:52:56 +01:00
|
|
|
if (sd->type == PRIMITIVE_TRIANGLE) {
|
2022-01-13 17:12:03 +01:00
|
|
|
hit_P = triangle_point_from_uv(kg,
|
|
|
|
sd,
|
|
|
|
isect.hits[hit].object,
|
|
|
|
isect.hits[hit].prim,
|
|
|
|
isect.hits[hit].u,
|
|
|
|
isect.hits[hit].v);
|
2017-08-18 18:37:05 +02:00
|
|
|
}
|
2019-08-21 12:04:40 +02:00
|
|
|
# ifdef __OBJECT_MOTION__
|
2021-12-20 02:52:56 +01:00
|
|
|
else if (sd->type == PRIMITIVE_MOTION_TRIANGLE) {
|
2017-08-18 18:37:05 +02:00
|
|
|
float3 verts[3];
|
2021-02-28 23:23:24 +01:00
|
|
|
motion_triangle_vertices(kg, sd->object, isect.hits[hit].prim, sd->time, verts);
|
2022-01-13 17:12:03 +01:00
|
|
|
hit_P = motion_triangle_point_from_uv(kg,
|
|
|
|
sd,
|
|
|
|
isect.hits[hit].object,
|
|
|
|
isect.hits[hit].prim,
|
|
|
|
isect.hits[hit].u,
|
|
|
|
isect.hits[hit].v,
|
|
|
|
verts);
|
2017-08-18 18:37:05 +02:00
|
|
|
}
|
2019-08-21 12:04:40 +02:00
|
|
|
# endif /* __OBJECT_MOTION__ */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-11 10:20:31 +01:00
|
|
|
/* Get geometric normal. */
|
2017-08-18 18:37:05 +02:00
|
|
|
float3 hit_Ng = isect.Ng[hit];
|
2021-02-28 23:23:24 +01:00
|
|
|
int object = isect.hits[hit].object;
|
2019-03-11 10:20:31 +01:00
|
|
|
int object_flag = kernel_tex_fetch(__object_flag, object);
|
|
|
|
if (object_flag & SD_OBJECT_NEGATIVE_SCALE_APPLIED) {
|
|
|
|
hit_Ng = -hit_Ng;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Compute smooth normal. */
|
|
|
|
float3 N = hit_Ng;
|
2021-02-28 23:23:24 +01:00
|
|
|
int prim = isect.hits[hit].prim;
|
2017-08-18 18:37:05 +02:00
|
|
|
int shader = kernel_tex_fetch(__tri_shader, prim);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-24 14:36:18 +02:00
|
|
|
if (shader & SHADER_SMOOTH_NORMAL) {
|
2017-08-18 18:37:05 +02:00
|
|
|
float u = isect.hits[hit].u;
|
|
|
|
float v = isect.hits[hit].v;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-20 02:52:56 +01:00
|
|
|
if (sd->type == PRIMITIVE_TRIANGLE) {
|
2017-08-18 18:37:05 +02:00
|
|
|
N = triangle_smooth_normal(kg, N, prim, u, v);
|
|
|
|
}
|
2019-08-21 12:04:40 +02:00
|
|
|
# ifdef __OBJECT_MOTION__
|
2021-12-20 02:52:56 +01:00
|
|
|
else if (sd->type == PRIMITIVE_MOTION_TRIANGLE) {
|
2017-08-18 18:37:05 +02:00
|
|
|
N = motion_triangle_smooth_normal(kg, N, sd->object, prim, u, v, sd->time);
|
|
|
|
}
|
2019-08-21 12:04:40 +02:00
|
|
|
# endif /* __OBJECT_MOTION__ */
|
2017-08-18 18:37:05 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Transform normals to world space. */
|
2019-03-11 10:20:31 +01:00
|
|
|
if (!(object_flag & SD_OBJECT_TRANSFORM_APPLIED)) {
|
2017-08-18 18:37:05 +02:00
|
|
|
object_normal_transform(kg, sd, &N);
|
|
|
|
object_normal_transform(kg, sd, &hit_Ng);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Probability densities for local frame axes. */
|
|
|
|
float pdf_N = pick_pdf_N * fabsf(dot(disk_N, hit_Ng));
|
|
|
|
float pdf_T = pick_pdf_T * fabsf(dot(disk_T, hit_Ng));
|
|
|
|
float pdf_B = pick_pdf_B * fabsf(dot(disk_B, hit_Ng));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Multiple importance sample between 3 axes, power heuristic
|
2018-01-11 22:25:40 +01:00
|
|
|
* found to be slightly better than balance heuristic. pdf_N
|
2021-09-22 14:48:01 +10:00
|
|
|
* in the MIS weight and denominator canceled out. */
|
2018-01-11 22:25:40 +01:00
|
|
|
float w = pdf_N / (sqr(pdf_N) + sqr(pdf_T) + sqr(pdf_B));
|
|
|
|
if (isect.num_hits > LOCAL_MAX_HITS) {
|
|
|
|
w *= isect.num_hits / (float)LOCAL_MAX_HITS;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Real distance to sampled point. */
|
|
|
|
float r = len(hit_P - sd->P);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Compute weight. */
|
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 pdf = svm_bevel_cubic_pdf(radius, r);
|
|
|
|
float disk_pdf = svm_bevel_cubic_pdf(radius, disk_r);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
w *= pdf / disk_pdf;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Sum normal and weight. */
|
|
|
|
sum_N += w * N;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
/* Normalize. */
|
|
|
|
float3 N = safe_normalize(sum_N);
|
2017-11-22 00:49:12 +01:00
|
|
|
return is_zero(N) ? sd->N : (sd->flag & SD_BACKFACING) ? -N : N;
|
2017-08-18 18:37:05 +02:00
|
|
|
}
|
|
|
|
|
2021-10-17 16:22:20 +02:00
|
|
|
template<uint node_feature_mask, typename ConstIntegratorGenericState>
|
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 defined(__KERNEL_OPTIX__)
|
|
|
|
ccl_device_inline
|
|
|
|
# else
|
|
|
|
ccl_device_noinline
|
|
|
|
# endif
|
|
|
|
void
|
2021-10-17 16:10:10 +02:00
|
|
|
svm_node_bevel(KernelGlobals kg,
|
2021-10-17 16:22:20 +02:00
|
|
|
ConstIntegratorGenericState state,
|
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 ShaderData *sd,
|
|
|
|
ccl_private float *stack,
|
|
|
|
uint4 node)
|
2017-08-18 18:37:05 +02:00
|
|
|
{
|
|
|
|
uint num_samples, radius_offset, normal_offset, out_offset;
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar4(node.y, &num_samples, &radius_offset, &normal_offset, &out_offset);
|
2017-08-18 18:37:05 +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 bevel_N = sd->N;
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
IF_KERNEL_NODES_FEATURE(RAYTRACE)
|
|
|
|
{
|
2021-10-19 12:17:58 +02:00
|
|
|
float radius = stack_load_float(stack, radius_offset);
|
|
|
|
|
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
|
|
|
# ifdef __KERNEL_OPTIX__
|
2021-10-17 16:10:10 +02:00
|
|
|
bevel_N = optixDirectCall<float3>(1, kg, state, sd, radius, num_samples);
|
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
|
|
|
# else
|
2021-10-17 16:10:10 +02:00
|
|
|
bevel_N = svm_bevel(kg, state, sd, radius, num_samples);
|
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
|
|
|
# endif
|
|
|
|
|
|
|
|
if (stack_valid(normal_offset)) {
|
|
|
|
/* Preserve input normal. */
|
|
|
|
float3 ref_N = stack_load_float3(stack, normal_offset);
|
|
|
|
bevel_N = normalize(ref_N + (bevel_N - sd->N));
|
|
|
|
}
|
2017-08-18 18:37:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
stack_store_float3(stack, out_offset, bevel_N);
|
|
|
|
}
|
|
|
|
|
2019-08-21 12:04:40 +02:00
|
|
|
#endif /* __SHADER_RAYTRACE__ */
|
|
|
|
|
2017-08-18 18:37:05 +02:00
|
|
|
CCL_NAMESPACE_END
|