2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2016-09-29 10:11:40 +02: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-03-29 13:03:45 +01:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
2012-09-05 17:08:56 +00:00
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
/* Triangle Primitive
|
|
|
|
*
|
2014-12-15 21:18:01 +05:00
|
|
|
* Basic triangle with 3 vertices is used to represent mesh surfaces. For BVH
|
|
|
|
* ray intersection we use a precomputed triangle storage to accelerate
|
|
|
|
* intersection at the cost of more memory usage */
|
2014-03-29 13:03:48 +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
|
|
|
#pragma once
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2021-06-24 15:56:58 +10:00
|
|
|
/* Normal on triangle. */
|
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
|
|
|
ccl_device_inline float3 triangle_normal(const KernelGlobals *kg, ShaderData *sd)
|
2014-06-13 21:27:21 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* load triangle vertices */
|
|
|
|
const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
|
2021-02-28 23:23:24 +01:00
|
|
|
const float3 v0 = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex.w + 0));
|
|
|
|
const float3 v1 = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex.w + 1));
|
|
|
|
const float3 v2 = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex.w + 2));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* return normal */
|
|
|
|
if (sd->object_flag & SD_OBJECT_NEGATIVE_SCALE_APPLIED) {
|
|
|
|
return normalize(cross(v2 - v0, v1 - v0));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return normalize(cross(v1 - v0, v2 - v0));
|
|
|
|
}
|
2014-06-13 21:27:21 +02:00
|
|
|
}
|
|
|
|
|
2021-06-24 15:56:58 +10:00
|
|
|
/* Point and normal on triangle. */
|
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
|
|
|
ccl_device_inline void triangle_point_normal(const KernelGlobals *kg,
|
|
|
|
int object,
|
|
|
|
int prim,
|
|
|
|
float u,
|
|
|
|
float v,
|
|
|
|
float3 *P,
|
|
|
|
float3 *Ng,
|
|
|
|
int *shader)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* load triangle vertices */
|
|
|
|
const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim);
|
2021-02-28 23:23:24 +01:00
|
|
|
float3 v0 = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex.w + 0));
|
|
|
|
float3 v1 = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex.w + 1));
|
|
|
|
float3 v2 = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex.w + 2));
|
2019-04-17 06:17:24 +02:00
|
|
|
/* compute point */
|
|
|
|
float t = 1.0f - u - v;
|
|
|
|
*P = (u * v0 + v * v1 + t * v2);
|
|
|
|
/* get object flags */
|
|
|
|
int object_flag = kernel_tex_fetch(__object_flag, object);
|
|
|
|
/* compute normal */
|
|
|
|
if (object_flag & SD_OBJECT_NEGATIVE_SCALE_APPLIED) {
|
|
|
|
*Ng = normalize(cross(v2 - v0, v1 - v0));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*Ng = normalize(cross(v1 - v0, v2 - v0));
|
|
|
|
}
|
|
|
|
/* shader`*/
|
|
|
|
*shader = kernel_tex_fetch(__tri_shader, prim);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
/* Triangle vertex locations */
|
|
|
|
|
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
|
|
|
ccl_device_inline void triangle_vertices(const KernelGlobals *kg, int prim, float3 P[3])
|
2012-11-03 14:32:13 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim);
|
2021-02-28 23:23:24 +01:00
|
|
|
P[0] = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex.w + 0));
|
|
|
|
P[1] = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex.w + 1));
|
|
|
|
P[2] = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex.w + 2));
|
2012-11-03 14:32:13 +00:00
|
|
|
}
|
|
|
|
|
2021-06-28 13:54:18 +02:00
|
|
|
/* Triangle vertex locations and vertex normals */
|
|
|
|
|
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
|
|
|
ccl_device_inline void triangle_vertices_and_normals(const KernelGlobals *kg,
|
2021-06-29 20:13:24 +10:00
|
|
|
int prim,
|
|
|
|
float3 P[3],
|
|
|
|
float3 N[3])
|
2021-06-28 13:54:18 +02:00
|
|
|
{
|
|
|
|
const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim);
|
2021-02-28 23:23:24 +01:00
|
|
|
P[0] = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex.w + 0));
|
|
|
|
P[1] = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex.w + 1));
|
|
|
|
P[2] = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex.w + 2));
|
2021-06-28 13:54:18 +02:00
|
|
|
N[0] = float4_to_float3(kernel_tex_fetch(__tri_vnormal, tri_vindex.x));
|
|
|
|
N[1] = float4_to_float3(kernel_tex_fetch(__tri_vnormal, tri_vindex.y));
|
|
|
|
N[2] = float4_to_float3(kernel_tex_fetch(__tri_vnormal, tri_vindex.z));
|
|
|
|
}
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
/* Interpolate smooth vertex normal from vertices */
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ccl_device_inline float3
|
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
|
|
|
triangle_smooth_normal(const KernelGlobals *kg, float3 Ng, int prim, float u, float v)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* load triangle vertices */
|
|
|
|
const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim);
|
|
|
|
float3 n0 = float4_to_float3(kernel_tex_fetch(__tri_vnormal, tri_vindex.x));
|
|
|
|
float3 n1 = float4_to_float3(kernel_tex_fetch(__tri_vnormal, tri_vindex.y));
|
|
|
|
float3 n2 = float4_to_float3(kernel_tex_fetch(__tri_vnormal, tri_vindex.z));
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
float3 N = safe_normalize((1.0f - u - v) * n2 + u * n0 + v * n1);
|
2017-05-07 14:40:58 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return is_zero(N) ? Ng : N;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2021-08-24 01:42:45 +02:00
|
|
|
ccl_device_inline float3 triangle_smooth_normal_unnormalized(
|
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 KernelGlobals *kg, const ShaderData *sd, float3 Ng, int prim, float u, float v)
|
2021-08-17 23:24:46 +02:00
|
|
|
{
|
|
|
|
/* load triangle vertices */
|
|
|
|
const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim);
|
|
|
|
float3 n0 = float4_to_float3(kernel_tex_fetch(__tri_vnormal, tri_vindex.x));
|
|
|
|
float3 n1 = float4_to_float3(kernel_tex_fetch(__tri_vnormal, tri_vindex.y));
|
|
|
|
float3 n2 = float4_to_float3(kernel_tex_fetch(__tri_vnormal, tri_vindex.z));
|
|
|
|
|
2021-08-24 01:42:45 +02:00
|
|
|
/* ensure that the normals are in object space */
|
|
|
|
if (sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED) {
|
|
|
|
object_inverse_normal_transform(kg, sd, &n0);
|
|
|
|
object_inverse_normal_transform(kg, sd, &n1);
|
|
|
|
object_inverse_normal_transform(kg, sd, &n2);
|
|
|
|
}
|
|
|
|
|
2021-08-17 23:24:46 +02:00
|
|
|
float3 N = (1.0f - u - v) * n2 + u * n0 + v * n1;
|
|
|
|
|
|
|
|
return is_zero(N) ? Ng : N;
|
|
|
|
}
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
/* Ray differentials on triangle */
|
|
|
|
|
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
|
|
|
ccl_device_inline void triangle_dPdudv(const KernelGlobals *kg,
|
2019-04-17 06:17:24 +02:00
|
|
|
int prim,
|
|
|
|
ccl_addr_space float3 *dPdu,
|
|
|
|
ccl_addr_space float3 *dPdv)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* fetch triangle vertex coordinates */
|
|
|
|
const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim);
|
2021-02-28 23:23:24 +01:00
|
|
|
const float3 p0 = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex.w + 0));
|
|
|
|
const float3 p1 = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex.w + 1));
|
|
|
|
const float3 p2 = float4_to_float3(kernel_tex_fetch(__tri_verts, tri_vindex.w + 2));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* compute derivatives of P w.r.t. uv */
|
|
|
|
*dPdu = (p0 - p2);
|
|
|
|
*dPdv = (p1 - p2);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
/* Reading attributes on various triangle elements */
|
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
|
|
|
ccl_device float triangle_attribute_float(const KernelGlobals *kg,
|
|
|
|
const ShaderData *sd,
|
|
|
|
const AttributeDescriptor desc,
|
|
|
|
float *dx,
|
|
|
|
float *dy)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION | ATTR_ELEMENT_CORNER)) {
|
|
|
|
float f0, f1, f2;
|
|
|
|
|
|
|
|
if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION)) {
|
|
|
|
const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
|
|
|
|
f0 = kernel_tex_fetch(__attributes_float, desc.offset + tri_vindex.x);
|
|
|
|
f1 = kernel_tex_fetch(__attributes_float, desc.offset + tri_vindex.y);
|
|
|
|
f2 = kernel_tex_fetch(__attributes_float, desc.offset + tri_vindex.z);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const int tri = desc.offset + sd->prim * 3;
|
|
|
|
f0 = kernel_tex_fetch(__attributes_float, tri + 0);
|
|
|
|
f1 = kernel_tex_fetch(__attributes_float, tri + 1);
|
|
|
|
f2 = kernel_tex_fetch(__attributes_float, tri + 2);
|
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
|
|
|
|
#ifdef __RAY_DIFFERENTIALS__
|
2019-04-17 06:17:24 +02:00
|
|
|
if (dx)
|
|
|
|
*dx = sd->du.dx * f0 + sd->dv.dx * f1 - (sd->du.dx + sd->dv.dx) * f2;
|
|
|
|
if (dy)
|
|
|
|
*dy = sd->du.dy * f0 + sd->dv.dy * f1 - (sd->du.dy + sd->dv.dy) * f2;
|
2013-01-03 12:08:54 +00:00
|
|
|
#endif
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return sd->u * f0 + sd->v * f1 + (1.0f - sd->u - sd->v) * f2;
|
|
|
|
}
|
|
|
|
else {
|
2020-10-26 19:25:00 +01:00
|
|
|
#ifdef __RAY_DIFFERENTIALS__
|
2019-04-17 06:17:24 +02:00
|
|
|
if (dx)
|
|
|
|
*dx = 0.0f;
|
|
|
|
if (dy)
|
|
|
|
*dy = 0.0f;
|
2020-10-26 19:25:00 +01:00
|
|
|
#endif
|
2013-01-03 12:08:54 +00:00
|
|
|
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) {
|
|
|
|
const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim :
|
|
|
|
desc.offset;
|
|
|
|
return kernel_tex_fetch(__attributes_float, offset);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
ccl_device float2 triangle_attribute_float2(const KernelGlobals *kg,
|
2019-04-17 06:17:24 +02:00
|
|
|
const ShaderData *sd,
|
|
|
|
const AttributeDescriptor desc,
|
|
|
|
float2 *dx,
|
|
|
|
float2 *dy)
|
2019-03-05 14:54:54 +01:00
|
|
|
{
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION | ATTR_ELEMENT_CORNER)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
float2 f0, f1, f2;
|
2019-03-05 14:54:54 +01:00
|
|
|
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION)) {
|
|
|
|
const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
|
|
|
|
f0 = kernel_tex_fetch(__attributes_float2, desc.offset + tri_vindex.x);
|
|
|
|
f1 = kernel_tex_fetch(__attributes_float2, desc.offset + tri_vindex.y);
|
|
|
|
f2 = kernel_tex_fetch(__attributes_float2, desc.offset + tri_vindex.z);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const int tri = desc.offset + sd->prim * 3;
|
2019-04-17 06:17:24 +02:00
|
|
|
f0 = kernel_tex_fetch(__attributes_float2, tri + 0);
|
|
|
|
f1 = kernel_tex_fetch(__attributes_float2, tri + 1);
|
|
|
|
f2 = kernel_tex_fetch(__attributes_float2, tri + 2);
|
|
|
|
}
|
2019-03-05 14:54:54 +01:00
|
|
|
|
|
|
|
#ifdef __RAY_DIFFERENTIALS__
|
2019-04-17 06:17:24 +02:00
|
|
|
if (dx)
|
|
|
|
*dx = sd->du.dx * f0 + sd->dv.dx * f1 - (sd->du.dx + sd->dv.dx) * f2;
|
|
|
|
if (dy)
|
|
|
|
*dy = sd->du.dy * f0 + sd->dv.dy * f1 - (sd->du.dy + sd->dv.dy) * f2;
|
2019-03-05 14:54:54 +01:00
|
|
|
#endif
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return sd->u * f0 + sd->v * f1 + (1.0f - sd->u - sd->v) * f2;
|
|
|
|
}
|
|
|
|
else {
|
2020-10-26 19:25:00 +01:00
|
|
|
#ifdef __RAY_DIFFERENTIALS__
|
2019-04-17 06:17:24 +02:00
|
|
|
if (dx)
|
|
|
|
*dx = make_float2(0.0f, 0.0f);
|
|
|
|
if (dy)
|
|
|
|
*dy = make_float2(0.0f, 0.0f);
|
2020-10-26 19:25:00 +01:00
|
|
|
#endif
|
2019-03-05 14:54:54 +01:00
|
|
|
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) {
|
|
|
|
const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim :
|
|
|
|
desc.offset;
|
|
|
|
return kernel_tex_fetch(__attributes_float2, offset);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return make_float2(0.0f, 0.0f);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-03-05 14:54:54 +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
|
|
|
ccl_device float3 triangle_attribute_float3(const KernelGlobals *kg,
|
2019-04-17 06:17:24 +02:00
|
|
|
const ShaderData *sd,
|
|
|
|
const AttributeDescriptor desc,
|
|
|
|
float3 *dx,
|
|
|
|
float3 *dy)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION | ATTR_ELEMENT_CORNER)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
float3 f0, f1, f2;
|
|
|
|
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION)) {
|
|
|
|
const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
|
|
|
|
f0 = float4_to_float3(kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.x));
|
|
|
|
f1 = float4_to_float3(kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.y));
|
|
|
|
f2 = float4_to_float3(kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.z));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const int tri = desc.offset + sd->prim * 3;
|
|
|
|
f0 = float4_to_float3(kernel_tex_fetch(__attributes_float3, tri + 0));
|
|
|
|
f1 = float4_to_float3(kernel_tex_fetch(__attributes_float3, tri + 1));
|
|
|
|
f2 = float4_to_float3(kernel_tex_fetch(__attributes_float3, tri + 2));
|
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
|
|
|
|
#ifdef __RAY_DIFFERENTIALS__
|
2019-04-17 06:17:24 +02:00
|
|
|
if (dx)
|
|
|
|
*dx = sd->du.dx * f0 + sd->dv.dx * f1 - (sd->du.dx + sd->dv.dx) * f2;
|
|
|
|
if (dy)
|
|
|
|
*dy = sd->du.dy * f0 + sd->dv.dy * f1 - (sd->du.dy + sd->dv.dy) * f2;
|
2012-12-28 14:21:30 +00:00
|
|
|
#endif
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return sd->u * f0 + sd->v * f1 + (1.0f - sd->u - sd->v) * f2;
|
|
|
|
}
|
|
|
|
else {
|
2020-10-26 19:25:00 +01:00
|
|
|
#ifdef __RAY_DIFFERENTIALS__
|
2019-04-17 06:17:24 +02:00
|
|
|
if (dx)
|
|
|
|
*dx = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
if (dy)
|
|
|
|
*dy = make_float3(0.0f, 0.0f, 0.0f);
|
2020-10-26 19:25:00 +01:00
|
|
|
#endif
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) {
|
|
|
|
const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim :
|
|
|
|
desc.offset;
|
|
|
|
return float4_to_float3(kernel_tex_fetch(__attributes_float3, offset));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-04-30 12:49:26 +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
|
|
|
ccl_device float4 triangle_attribute_float4(const KernelGlobals *kg,
|
2019-09-12 17:42:13 +02:00
|
|
|
const ShaderData *sd,
|
|
|
|
const AttributeDescriptor desc,
|
|
|
|
float4 *dx,
|
|
|
|
float4 *dy)
|
|
|
|
{
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION | ATTR_ELEMENT_CORNER |
|
|
|
|
ATTR_ELEMENT_CORNER_BYTE)) {
|
2020-06-25 13:48:44 +02:00
|
|
|
float4 f0, f1, f2;
|
|
|
|
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION)) {
|
|
|
|
const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
|
|
|
|
f0 = kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.x);
|
|
|
|
f1 = kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.y);
|
|
|
|
f2 = kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.z);
|
2020-06-25 13:48:44 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-10-26 19:25:00 +01:00
|
|
|
const int tri = desc.offset + sd->prim * 3;
|
|
|
|
if (desc.element == ATTR_ELEMENT_CORNER) {
|
|
|
|
f0 = kernel_tex_fetch(__attributes_float3, tri + 0);
|
|
|
|
f1 = kernel_tex_fetch(__attributes_float3, tri + 1);
|
|
|
|
f2 = kernel_tex_fetch(__attributes_float3, tri + 2);
|
|
|
|
}
|
|
|
|
else {
|
2020-11-09 17:37:21 +01:00
|
|
|
f0 = color_srgb_to_linear_v4(
|
|
|
|
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 0)));
|
|
|
|
f1 = color_srgb_to_linear_v4(
|
|
|
|
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 1)));
|
|
|
|
f2 = color_srgb_to_linear_v4(
|
|
|
|
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 2)));
|
2020-10-26 19:25:00 +01:00
|
|
|
}
|
2020-06-25 13:48:44 +02:00
|
|
|
}
|
2019-09-12 17:42:13 +02:00
|
|
|
|
|
|
|
#ifdef __RAY_DIFFERENTIALS__
|
|
|
|
if (dx)
|
|
|
|
*dx = sd->du.dx * f0 + sd->dv.dx * f1 - (sd->du.dx + sd->dv.dx) * f2;
|
|
|
|
if (dy)
|
|
|
|
*dy = sd->du.dy * f0 + sd->dv.dy * f1 - (sd->du.dy + sd->dv.dy) * f2;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return sd->u * f0 + sd->v * f1 + (1.0f - sd->u - sd->v) * f2;
|
|
|
|
}
|
|
|
|
else {
|
2020-10-26 19:25:00 +01:00
|
|
|
#ifdef __RAY_DIFFERENTIALS__
|
2019-09-12 17:42:13 +02:00
|
|
|
if (dx)
|
|
|
|
*dx = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
if (dy)
|
|
|
|
*dy = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
2020-10-26 19:25:00 +01:00
|
|
|
#endif
|
2019-09-12 17:42:13 +02:00
|
|
|
|
2020-10-26 19:25:00 +01:00
|
|
|
if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) {
|
|
|
|
const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim :
|
|
|
|
desc.offset;
|
|
|
|
return kernel_tex_fetch(__attributes_float3, offset);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
}
|
2019-09-12 17:42:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|