Merge branch 'blender-v2.91-release'

This commit is contained in:
Brecht Van Lommel 2020-11-09 17:37:21 +01:00
commit cde2bd1828
7 changed files with 1093 additions and 37 deletions

View File

@ -347,7 +347,7 @@ static void attr_create_vertex_color(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh,
for (int i = 0; i < n; i++) {
float4 color = get_float4(l->data[p->loop_start() + i].color());
/* Compress/encode vertex color using the sRGB curve. */
*(cdata++) = color_float4_to_uchar4(color_srgb_to_linear_v4(color));
*(cdata++) = color_float4_to_uchar4(color);
}
}
}
@ -369,9 +369,10 @@ static void attr_create_vertex_color(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh,
float4 c3 = get_float4(l->data[li[2]].color());
/* Compress/encode vertex color using the sRGB curve. */
cdata[0] = color_float4_to_uchar4(color_srgb_to_linear_v4(c1));
cdata[1] = color_float4_to_uchar4(color_srgb_to_linear_v4(c2));
cdata[2] = color_float4_to_uchar4(color_srgb_to_linear_v4(c3));
cdata[0] = color_float4_to_uchar4(c1);
cdata[1] = color_float4_to_uchar4(c2);
cdata[2] = color_float4_to_uchar4(c3);
cdata += 3;
}
}

View File

@ -442,7 +442,8 @@ ccl_device float4 patch_eval_uchar4(KernelGlobals *kg,
*dv = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
for (int i = 0; i < num_control; i++) {
float4 v = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, offset + indices[i]));
float4 v = color_srgb_to_linear_v4(
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, offset + indices[i])));
val += v * weights[i];
if (du)

View File

@ -627,10 +627,14 @@ ccl_device_noinline float4 subd_triangle_attribute_float4(KernelGlobals *kg,
float4 f0, f1, f2, f3;
if (desc.element == ATTR_ELEMENT_CORNER_BYTE) {
f0 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[0] + desc.offset));
f1 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[1] + desc.offset));
f2 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[2] + desc.offset));
f3 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[3] + desc.offset));
f0 = color_srgb_to_linear_v4(
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[0] + desc.offset)));
f1 = color_srgb_to_linear_v4(
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[1] + desc.offset)));
f2 = color_srgb_to_linear_v4(
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[2] + desc.offset)));
f3 = color_srgb_to_linear_v4(
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[3] + desc.offset)));
}
else {
f0 = kernel_tex_fetch(__attributes_float3, corners[0] + desc.offset);

View File

@ -0,0 +1,698 @@
/*
* Copyright 2011-2016 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.
*/
/* Functions for retrieving attributes on triangles produced from subdivision meshes */
CCL_NAMESPACE_BEGIN
/* Patch index for triangle, -1 if not subdivision triangle */
ccl_device_inline uint subd_triangle_patch(KernelGlobals *kg, const ShaderData *sd)
{
return (sd->prim != PRIM_NONE) ? kernel_tex_fetch(__tri_patch, sd->prim) : ~0;
}
/* UV coords of triangle within patch */
ccl_device_inline void subd_triangle_patch_uv(KernelGlobals *kg,
const ShaderData *sd,
float2 uv[3])
{
uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
uv[0] = kernel_tex_fetch(__tri_patch_uv, tri_vindex.x);
uv[1] = kernel_tex_fetch(__tri_patch_uv, tri_vindex.y);
uv[2] = kernel_tex_fetch(__tri_patch_uv, tri_vindex.z);
}
/* Vertex indices of patch */
ccl_device_inline uint4 subd_triangle_patch_indices(KernelGlobals *kg, int patch)
{
uint4 indices;
indices.x = kernel_tex_fetch(__patches, patch + 0);
indices.y = kernel_tex_fetch(__patches, patch + 1);
indices.z = kernel_tex_fetch(__patches, patch + 2);
indices.w = kernel_tex_fetch(__patches, patch + 3);
return indices;
}
/* Originating face for patch */
ccl_device_inline uint subd_triangle_patch_face(KernelGlobals *kg, int patch)
{
return kernel_tex_fetch(__patches, patch + 4);
}
/* Number of corners on originating face */
ccl_device_inline uint subd_triangle_patch_num_corners(KernelGlobals *kg, int patch)
{
return kernel_tex_fetch(__patches, patch + 5) & 0xffff;
}
/* Indices of the four corners that are used by the patch */
ccl_device_inline void subd_triangle_patch_corners(KernelGlobals *kg, int patch, int corners[4])
{
uint4 data;
data.x = kernel_tex_fetch(__patches, patch + 4);
data.y = kernel_tex_fetch(__patches, patch + 5);
data.z = kernel_tex_fetch(__patches, patch + 6);
data.w = kernel_tex_fetch(__patches, patch + 7);
int num_corners = data.y & 0xffff;
if (num_corners == 4) {
/* quad */
corners[0] = data.z;
corners[1] = data.z + 1;
corners[2] = data.z + 2;
corners[3] = data.z + 3;
}
else {
/* ngon */
int c = data.y >> 16;
corners[0] = data.z + c;
corners[1] = data.z + mod(c + 1, num_corners);
corners[2] = data.w;
corners[3] = data.z + mod(c - 1, num_corners);
}
}
/* Reading attributes on various subdivision triangle elements */
ccl_device_noinline float subd_triangle_attribute_float(
KernelGlobals *kg, const ShaderData *sd, const AttributeDescriptor desc, float *dx, float *dy)
{
int patch = subd_triangle_patch(kg, sd);
#ifdef __PATCH_EVAL__
if (desc.flags & ATTR_SUBDIVIDED) {
float2 uv[3];
subd_triangle_patch_uv(kg, sd, uv);
float2 dpdu = uv[0] - uv[2];
float2 dpdv = uv[1] - uv[2];
/* p is [s, t] */
float2 p = dpdu * sd->u + dpdv * sd->v + uv[2];
float a, dads, dadt;
a = patch_eval_float(kg, sd, desc.offset, patch, p.x, p.y, 0, &dads, &dadt);
# ifdef __RAY_DIFFERENTIALS__
if (dx || dy) {
float dsdu = dpdu.x;
float dtdu = dpdu.y;
float dsdv = dpdv.x;
float dtdv = dpdv.y;
if (dx) {
float dudx = sd->du.dx;
float dvdx = sd->dv.dx;
float dsdx = dsdu * dudx + dsdv * dvdx;
float dtdx = dtdu * dudx + dtdv * dvdx;
*dx = dads * dsdx + dadt * dtdx;
}
if (dy) {
float dudy = sd->du.dy;
float dvdy = sd->dv.dy;
float dsdy = dsdu * dudy + dsdv * dvdy;
float dtdy = dtdu * dudy + dtdv * dvdy;
*dy = dads * dsdy + dadt * dtdy;
}
}
# endif
return a;
}
else
#endif /* __PATCH_EVAL__ */
if (desc.element == ATTR_ELEMENT_FACE) {
if (dx)
*dx = 0.0f;
if (dy)
*dy = 0.0f;
return kernel_tex_fetch(__attributes_float, desc.offset + subd_triangle_patch_face(kg, patch));
}
else if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) {
float2 uv[3];
subd_triangle_patch_uv(kg, sd, uv);
uint4 v = subd_triangle_patch_indices(kg, patch);
float f0 = kernel_tex_fetch(__attributes_float, desc.offset + v.x);
float f1 = kernel_tex_fetch(__attributes_float, desc.offset + v.y);
float f2 = kernel_tex_fetch(__attributes_float, desc.offset + v.z);
float f3 = kernel_tex_fetch(__attributes_float, desc.offset + v.w);
if (subd_triangle_patch_num_corners(kg, patch) != 4) {
f1 = (f1 + f0) * 0.5f;
f3 = (f3 + f0) * 0.5f;
}
float a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y);
float b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y);
float c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y);
#ifdef __RAY_DIFFERENTIALS__
if (dx)
*dx = sd->du.dx * a + sd->dv.dx * b - (sd->du.dx + sd->dv.dx) * c;
if (dy)
*dy = sd->du.dy * a + sd->dv.dy * b - (sd->du.dy + sd->dv.dy) * c;
#endif
return sd->u * a + sd->v * b + (1.0f - sd->u - sd->v) * c;
}
else if (desc.element == ATTR_ELEMENT_CORNER) {
float2 uv[3];
subd_triangle_patch_uv(kg, sd, uv);
int corners[4];
subd_triangle_patch_corners(kg, patch, corners);
float f0 = kernel_tex_fetch(__attributes_float, corners[0] + desc.offset);
float f1 = kernel_tex_fetch(__attributes_float, corners[1] + desc.offset);
float f2 = kernel_tex_fetch(__attributes_float, corners[2] + desc.offset);
float f3 = kernel_tex_fetch(__attributes_float, corners[3] + desc.offset);
if (subd_triangle_patch_num_corners(kg, patch) != 4) {
f1 = (f1 + f0) * 0.5f;
f3 = (f3 + f0) * 0.5f;
}
float a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y);
float b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y);
float c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y);
#ifdef __RAY_DIFFERENTIALS__
if (dx)
*dx = sd->du.dx * a + sd->dv.dx * b - (sd->du.dx + sd->dv.dx) * c;
if (dy)
*dy = sd->du.dy * a + sd->dv.dy * b - (sd->du.dy + sd->dv.dy) * c;
#endif
return sd->u * a + sd->v * b + (1.0f - sd->u - sd->v) * c;
}
else if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) {
if (dx)
*dx = 0.0f;
if (dy)
*dy = 0.0f;
return kernel_tex_fetch(__attributes_float, desc.offset);
}
else {
if (dx)
*dx = 0.0f;
if (dy)
*dy = 0.0f;
return 0.0f;
}
}
ccl_device_noinline float2 subd_triangle_attribute_float2(KernelGlobals *kg,
const ShaderData *sd,
const AttributeDescriptor desc,
float2 *dx,
float2 *dy)
{
int patch = subd_triangle_patch(kg, sd);
#ifdef __PATCH_EVAL__
if (desc.flags & ATTR_SUBDIVIDED) {
float2 uv[3];
subd_triangle_patch_uv(kg, sd, uv);
float2 dpdu = uv[0] - uv[2];
float2 dpdv = uv[1] - uv[2];
/* p is [s, t] */
float2 p = dpdu * sd->u + dpdv * sd->v + uv[2];
float2 a, dads, dadt;
a = patch_eval_float2(kg, sd, desc.offset, patch, p.x, p.y, 0, &dads, &dadt);
# ifdef __RAY_DIFFERENTIALS__
if (dx || dy) {
float dsdu = dpdu.x;
float dtdu = dpdu.y;
float dsdv = dpdv.x;
float dtdv = dpdv.y;
if (dx) {
float dudx = sd->du.dx;
float dvdx = sd->dv.dx;
float dsdx = dsdu * dudx + dsdv * dvdx;
float dtdx = dtdu * dudx + dtdv * dvdx;
*dx = dads * dsdx + dadt * dtdx;
}
if (dy) {
float dudy = sd->du.dy;
float dvdy = sd->dv.dy;
float dsdy = dsdu * dudy + dsdv * dvdy;
float dtdy = dtdu * dudy + dtdv * dvdy;
*dy = dads * dsdy + dadt * dtdy;
}
}
# endif
return a;
}
else
#endif /* __PATCH_EVAL__ */
if (desc.element == ATTR_ELEMENT_FACE) {
if (dx)
*dx = make_float2(0.0f, 0.0f);
if (dy)
*dy = make_float2(0.0f, 0.0f);
return kernel_tex_fetch(__attributes_float2,
desc.offset + subd_triangle_patch_face(kg, patch));
}
else if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) {
float2 uv[3];
subd_triangle_patch_uv(kg, sd, uv);
uint4 v = subd_triangle_patch_indices(kg, patch);
float2 f0 = kernel_tex_fetch(__attributes_float2, desc.offset + v.x);
float2 f1 = kernel_tex_fetch(__attributes_float2, desc.offset + v.y);
float2 f2 = kernel_tex_fetch(__attributes_float2, desc.offset + v.z);
float2 f3 = kernel_tex_fetch(__attributes_float2, desc.offset + v.w);
if (subd_triangle_patch_num_corners(kg, patch) != 4) {
f1 = (f1 + f0) * 0.5f;
f3 = (f3 + f0) * 0.5f;
}
float2 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y);
float2 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y);
float2 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y);
#ifdef __RAY_DIFFERENTIALS__
if (dx)
*dx = sd->du.dx * a + sd->dv.dx * b - (sd->du.dx + sd->dv.dx) * c;
if (dy)
*dy = sd->du.dy * a + sd->dv.dy * b - (sd->du.dy + sd->dv.dy) * c;
#endif
return sd->u * a + sd->v * b + (1.0f - sd->u - sd->v) * c;
}
else if (desc.element == ATTR_ELEMENT_CORNER) {
float2 uv[3];
subd_triangle_patch_uv(kg, sd, uv);
int corners[4];
subd_triangle_patch_corners(kg, patch, corners);
float2 f0, f1, f2, f3;
f0 = kernel_tex_fetch(__attributes_float2, corners[0] + desc.offset);
f1 = kernel_tex_fetch(__attributes_float2, corners[1] + desc.offset);
f2 = kernel_tex_fetch(__attributes_float2, corners[2] + desc.offset);
f3 = kernel_tex_fetch(__attributes_float2, corners[3] + desc.offset);
if (subd_triangle_patch_num_corners(kg, patch) != 4) {
f1 = (f1 + f0) * 0.5f;
f3 = (f3 + f0) * 0.5f;
}
float2 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y);
float2 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y);
float2 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y);
#ifdef __RAY_DIFFERENTIALS__
if (dx)
*dx = sd->du.dx * a + sd->dv.dx * b - (sd->du.dx + sd->dv.dx) * c;
if (dy)
*dy = sd->du.dy * a + sd->dv.dy * b - (sd->du.dy + sd->dv.dy) * c;
#endif
return sd->u * a + sd->v * b + (1.0f - sd->u - sd->v) * c;
}
else if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) {
if (dx)
*dx = make_float2(0.0f, 0.0f);
if (dy)
*dy = make_float2(0.0f, 0.0f);
return kernel_tex_fetch(__attributes_float2, desc.offset);
}
else {
if (dx)
*dx = make_float2(0.0f, 0.0f);
if (dy)
*dy = make_float2(0.0f, 0.0f);
return make_float2(0.0f, 0.0f);
}
}
ccl_device_noinline float3 subd_triangle_attribute_float3(KernelGlobals *kg,
const ShaderData *sd,
const AttributeDescriptor desc,
float3 *dx,
float3 *dy)
{
int patch = subd_triangle_patch(kg, sd);
#ifdef __PATCH_EVAL__
if (desc.flags & ATTR_SUBDIVIDED) {
float2 uv[3];
subd_triangle_patch_uv(kg, sd, uv);
float2 dpdu = uv[0] - uv[2];
float2 dpdv = uv[1] - uv[2];
/* p is [s, t] */
float2 p = dpdu * sd->u + dpdv * sd->v + uv[2];
float3 a, dads, dadt;
a = patch_eval_float3(kg, sd, desc.offset, patch, p.x, p.y, 0, &dads, &dadt);
# ifdef __RAY_DIFFERENTIALS__
if (dx || dy) {
float dsdu = dpdu.x;
float dtdu = dpdu.y;
float dsdv = dpdv.x;
float dtdv = dpdv.y;
if (dx) {
float dudx = sd->du.dx;
float dvdx = sd->dv.dx;
float dsdx = dsdu * dudx + dsdv * dvdx;
float dtdx = dtdu * dudx + dtdv * dvdx;
*dx = dads * dsdx + dadt * dtdx;
}
if (dy) {
float dudy = sd->du.dy;
float dvdy = sd->dv.dy;
float dsdy = dsdu * dudy + dsdv * dvdy;
float dtdy = dtdu * dudy + dtdv * dvdy;
*dy = dads * dsdy + dadt * dtdy;
}
}
# endif
return a;
}
else
#endif /* __PATCH_EVAL__ */
if (desc.element == ATTR_ELEMENT_FACE) {
if (dx)
*dx = make_float3(0.0f, 0.0f, 0.0f);
if (dy)
*dy = make_float3(0.0f, 0.0f, 0.0f);
return float4_to_float3(
kernel_tex_fetch(__attributes_float3, desc.offset + subd_triangle_patch_face(kg, patch)));
}
else if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) {
float2 uv[3];
subd_triangle_patch_uv(kg, sd, uv);
uint4 v = subd_triangle_patch_indices(kg, patch);
float3 f0 = float4_to_float3(kernel_tex_fetch(__attributes_float3, desc.offset + v.x));
float3 f1 = float4_to_float3(kernel_tex_fetch(__attributes_float3, desc.offset + v.y));
float3 f2 = float4_to_float3(kernel_tex_fetch(__attributes_float3, desc.offset + v.z));
float3 f3 = float4_to_float3(kernel_tex_fetch(__attributes_float3, desc.offset + v.w));
if (subd_triangle_patch_num_corners(kg, patch) != 4) {
f1 = (f1 + f0) * 0.5f;
f3 = (f3 + f0) * 0.5f;
}
float3 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y);
float3 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y);
float3 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y);
#ifdef __RAY_DIFFERENTIALS__
if (dx)
*dx = sd->du.dx * a + sd->dv.dx * b - (sd->du.dx + sd->dv.dx) * c;
if (dy)
*dy = sd->du.dy * a + sd->dv.dy * b - (sd->du.dy + sd->dv.dy) * c;
#endif
return sd->u * a + sd->v * b + (1.0f - sd->u - sd->v) * c;
}
else if (desc.element == ATTR_ELEMENT_CORNER) {
float2 uv[3];
subd_triangle_patch_uv(kg, sd, uv);
int corners[4];
subd_triangle_patch_corners(kg, patch, corners);
float3 f0, f1, f2, f3;
f0 = float4_to_float3(kernel_tex_fetch(__attributes_float3, corners[0] + desc.offset));
f1 = float4_to_float3(kernel_tex_fetch(__attributes_float3, corners[1] + desc.offset));
f2 = float4_to_float3(kernel_tex_fetch(__attributes_float3, corners[2] + desc.offset));
f3 = float4_to_float3(kernel_tex_fetch(__attributes_float3, corners[3] + desc.offset));
if (subd_triangle_patch_num_corners(kg, patch) != 4) {
f1 = (f1 + f0) * 0.5f;
f3 = (f3 + f0) * 0.5f;
}
float3 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y);
float3 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y);
float3 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y);
#ifdef __RAY_DIFFERENTIALS__
if (dx)
*dx = sd->du.dx * a + sd->dv.dx * b - (sd->du.dx + sd->dv.dx) * c;
if (dy)
*dy = sd->du.dy * a + sd->dv.dy * b - (sd->du.dy + sd->dv.dy) * c;
#endif
return sd->u * a + sd->v * b + (1.0f - sd->u - sd->v) * c;
}
else if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) {
if (dx)
*dx = make_float3(0.0f, 0.0f, 0.0f);
if (dy)
*dy = make_float3(0.0f, 0.0f, 0.0f);
return float4_to_float3(kernel_tex_fetch(__attributes_float3, desc.offset));
}
else {
if (dx)
*dx = make_float3(0.0f, 0.0f, 0.0f);
if (dy)
*dy = make_float3(0.0f, 0.0f, 0.0f);
return make_float3(0.0f, 0.0f, 0.0f);
}
}
ccl_device_noinline float4 subd_triangle_attribute_float4(KernelGlobals *kg,
const ShaderData *sd,
const AttributeDescriptor desc,
float4 *dx,
float4 *dy)
{
int patch = subd_triangle_patch(kg, sd);
#ifdef __PATCH_EVAL__
if (desc.flags & ATTR_SUBDIVIDED) {
float2 uv[3];
subd_triangle_patch_uv(kg, sd, uv);
float2 dpdu = uv[0] - uv[2];
float2 dpdv = uv[1] - uv[2];
/* p is [s, t] */
float2 p = dpdu * sd->u + dpdv * sd->v + uv[2];
float4 a, dads, dadt;
if (desc.type == NODE_ATTR_RGBA) {
a = patch_eval_uchar4(kg, sd, desc.offset, patch, p.x, p.y, 0, &dads, &dadt);
}
else {
a = patch_eval_float4(kg, sd, desc.offset, patch, p.x, p.y, 0, &dads, &dadt);
}
# ifdef __RAY_DIFFERENTIALS__
if (dx || dy) {
float dsdu = dpdu.x;
float dtdu = dpdu.y;
float dsdv = dpdv.x;
float dtdv = dpdv.y;
if (dx) {
float dudx = sd->du.dx;
float dvdx = sd->dv.dx;
float dsdx = dsdu * dudx + dsdv * dvdx;
float dtdx = dtdu * dudx + dtdv * dvdx;
*dx = dads * dsdx + dadt * dtdx;
}
if (dy) {
float dudy = sd->du.dy;
float dvdy = sd->dv.dy;
float dsdy = dsdu * dudy + dsdv * dvdy;
float dtdy = dtdu * dudy + dtdv * dvdy;
*dy = dads * dsdy + dadt * dtdy;
}
}
# endif
return a;
}
else
#endif /* __PATCH_EVAL__ */
if (desc.element == ATTR_ELEMENT_FACE) {
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);
return kernel_tex_fetch(__attributes_float3,
desc.offset + subd_triangle_patch_face(kg, patch));
}
else if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) {
float2 uv[3];
subd_triangle_patch_uv(kg, sd, uv);
uint4 v = subd_triangle_patch_indices(kg, patch);
float4 f0 = kernel_tex_fetch(__attributes_float3, desc.offset + v.x);
float4 f1 = kernel_tex_fetch(__attributes_float3, desc.offset + v.y);
float4 f2 = kernel_tex_fetch(__attributes_float3, desc.offset + v.z);
float4 f3 = kernel_tex_fetch(__attributes_float3, desc.offset + v.w);
if (subd_triangle_patch_num_corners(kg, patch) != 4) {
f1 = (f1 + f0) * 0.5f;
f3 = (f3 + f0) * 0.5f;
}
float4 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y);
float4 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y);
float4 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y);
#ifdef __RAY_DIFFERENTIALS__
if (dx)
*dx = sd->du.dx * a + sd->dv.dx * b - (sd->du.dx + sd->dv.dx) * c;
if (dy)
*dy = sd->du.dy * a + sd->dv.dy * b - (sd->du.dy + sd->dv.dy) * c;
#endif
return sd->u * a + sd->v * b + (1.0f - sd->u - sd->v) * c;
}
else if (desc.element == ATTR_ELEMENT_CORNER || desc.element == ATTR_ELEMENT_CORNER_BYTE) {
float2 uv[3];
subd_triangle_patch_uv(kg, sd, uv);
int corners[4];
subd_triangle_patch_corners(kg, patch, corners);
<<<<<<< HEAD
float4 f0, f1, f2, f3;
if (desc.element == ATTR_ELEMENT_CORNER_BYTE) {
f0 = color_srgb_to_linear_v4(
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[0] + desc.offset)));
f1 = color_srgb_to_linear_v4(
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[1] + desc.offset)));
f2 = color_srgb_to_linear_v4(
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[2] + desc.offset)));
f3 = color_srgb_to_linear_v4(
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[3] + desc.offset)));
}
else {
f0 = kernel_tex_fetch(__attributes_float3, corners[0] + desc.offset);
f1 = kernel_tex_fetch(__attributes_float3, corners[1] + desc.offset);
f2 = kernel_tex_fetch(__attributes_float3, corners[2] + desc.offset);
f3 = kernel_tex_fetch(__attributes_float3, corners[3] + desc.offset);
}
=======
float4 f0 = color_srgb_to_linear_v4(
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[0] + desc.offset)));
float4 f1 = color_srgb_to_linear_v4(
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[1] + desc.offset)));
float4 f2 = color_srgb_to_linear_v4(
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[2] + desc.offset)));
float4 f3 = color_srgb_to_linear_v4(
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[3] + desc.offset)));
>>>>>>> blender-v2.91-release
if (subd_triangle_patch_num_corners(kg, patch) != 4) {
f1 = (f1 + f0) * 0.5f;
f3 = (f3 + f0) * 0.5f;
}
float4 a = mix(mix(f0, f1, uv[0].x), mix(f3, f2, uv[0].x), uv[0].y);
float4 b = mix(mix(f0, f1, uv[1].x), mix(f3, f2, uv[1].x), uv[1].y);
float4 c = mix(mix(f0, f1, uv[2].x), mix(f3, f2, uv[2].x), uv[2].y);
#ifdef __RAY_DIFFERENTIALS__
if (dx)
*dx = sd->du.dx * a + sd->dv.dx * b - (sd->du.dx + sd->dv.dx) * c;
if (dy)
*dy = sd->du.dy * a + sd->dv.dy * b - (sd->du.dy + sd->dv.dy) * c;
#endif
return sd->u * a + sd->v * b + (1.0f - sd->u - sd->v) * c;
}
else if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) {
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);
<<<<<<< HEAD
return kernel_tex_fetch(__attributes_float3, desc.offset);
=======
return color_srgb_to_linear_v4(
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, desc.offset)));
>>>>>>> blender-v2.91-release
}
else {
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);
return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
}
}
CCL_NAMESPACE_END

View File

@ -282,9 +282,12 @@ ccl_device float4 triangle_attribute_float4(KernelGlobals *kg,
f2 = kernel_tex_fetch(__attributes_float3, tri + 2);
}
else {
f0 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 0));
f1 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 1));
f2 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 2));
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)));
}
}

View File

@ -0,0 +1,348 @@
/*
* 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.
*/
/* Triangle Primitive
*
* 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 */
CCL_NAMESPACE_BEGIN
/* normal on triangle */
ccl_device_inline float3 triangle_normal(KernelGlobals *kg, ShaderData *sd)
{
/* load triangle vertices */
const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
const float3 v0 = float4_to_float3(kernel_tex_fetch(__prim_tri_verts, tri_vindex.w + 0));
const float3 v1 = float4_to_float3(kernel_tex_fetch(__prim_tri_verts, tri_vindex.w + 1));
const float3 v2 = float4_to_float3(kernel_tex_fetch(__prim_tri_verts, tri_vindex.w + 2));
/* 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));
}
}
/* point and normal on triangle */
ccl_device_inline void triangle_point_normal(
KernelGlobals *kg, int object, int prim, float u, float v, float3 *P, float3 *Ng, int *shader)
{
/* load triangle vertices */
const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim);
float3 v0 = float4_to_float3(kernel_tex_fetch(__prim_tri_verts, tri_vindex.w + 0));
float3 v1 = float4_to_float3(kernel_tex_fetch(__prim_tri_verts, tri_vindex.w + 1));
float3 v2 = float4_to_float3(kernel_tex_fetch(__prim_tri_verts, tri_vindex.w + 2));
/* 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);
}
/* Triangle vertex locations */
ccl_device_inline void triangle_vertices(KernelGlobals *kg, int prim, float3 P[3])
{
const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim);
P[0] = float4_to_float3(kernel_tex_fetch(__prim_tri_verts, tri_vindex.w + 0));
P[1] = float4_to_float3(kernel_tex_fetch(__prim_tri_verts, tri_vindex.w + 1));
P[2] = float4_to_float3(kernel_tex_fetch(__prim_tri_verts, tri_vindex.w + 2));
}
/* Interpolate smooth vertex normal from vertices */
ccl_device_inline float3
triangle_smooth_normal(KernelGlobals *kg, float3 Ng, int prim, float u, float v)
{
/* 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));
float3 N = safe_normalize((1.0f - u - v) * n2 + u * n0 + v * n1);
return is_zero(N) ? Ng : N;
}
/* Ray differentials on triangle */
ccl_device_inline void triangle_dPdudv(KernelGlobals *kg,
int prim,
ccl_addr_space float3 *dPdu,
ccl_addr_space float3 *dPdv)
{
/* fetch triangle vertex coordinates */
const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim);
const float3 p0 = float4_to_float3(kernel_tex_fetch(__prim_tri_verts, tri_vindex.w + 0));
const float3 p1 = float4_to_float3(kernel_tex_fetch(__prim_tri_verts, tri_vindex.w + 1));
const float3 p2 = float4_to_float3(kernel_tex_fetch(__prim_tri_verts, tri_vindex.w + 2));
/* compute derivatives of P w.r.t. uv */
*dPdu = (p0 - p2);
*dPdv = (p1 - p2);
}
/* Reading attributes on various triangle elements */
ccl_device float triangle_attribute_float(
KernelGlobals *kg, const ShaderData *sd, const AttributeDescriptor desc, float *dx, float *dy)
{
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);
}
#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 {
#ifdef __RAY_DIFFERENTIALS__
if (dx)
*dx = 0.0f;
if (dy)
*dy = 0.0f;
#endif
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;
}
}
}
ccl_device float2 triangle_attribute_float2(KernelGlobals *kg,
const ShaderData *sd,
const AttributeDescriptor desc,
float2 *dx,
float2 *dy)
{
if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION | ATTR_ELEMENT_CORNER)) {
float2 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_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;
f0 = kernel_tex_fetch(__attributes_float2, tri + 0);
f1 = kernel_tex_fetch(__attributes_float2, tri + 1);
f2 = kernel_tex_fetch(__attributes_float2, tri + 2);
}
#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 {
#ifdef __RAY_DIFFERENTIALS__
if (dx)
*dx = make_float2(0.0f, 0.0f);
if (dy)
*dy = make_float2(0.0f, 0.0f);
#endif
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);
}
}
}
ccl_device float3 triangle_attribute_float3(KernelGlobals *kg,
const ShaderData *sd,
const AttributeDescriptor desc,
float3 *dx,
float3 *dy)
{
if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION | ATTR_ELEMENT_CORNER)) {
float3 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 = 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));
}
#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 {
#ifdef __RAY_DIFFERENTIALS__
if (dx)
*dx = make_float3(0.0f, 0.0f, 0.0f);
if (dy)
*dy = make_float3(0.0f, 0.0f, 0.0f);
#endif
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);
}
}
}
ccl_device float4 triangle_attribute_float4(KernelGlobals *kg,
const ShaderData *sd,
const AttributeDescriptor desc,
float4 *dx,
float4 *dy)
{
if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION | ATTR_ELEMENT_CORNER |
ATTR_ELEMENT_CORNER_BYTE)) {
float4 f0, f1, f2;
<<<<<<< HEAD
if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION)) {
const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
=======
if (desc.element == ATTR_ELEMENT_CORNER_BYTE) {
int tri = desc.offset + sd->prim * 3;
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)));
}
else {
uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
>>>>>>> blender-v2.91-release
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);
}
else {
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 {
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)));
}
}
#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;
}
<<<<<<< HEAD
=======
else if (desc.element == ATTR_ELEMENT_OBJECT || desc.element == ATTR_ELEMENT_MESH) {
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);
return color_srgb_to_linear_v4(
color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, desc.offset)));
}
>>>>>>> blender-v2.91-release
else {
#ifdef __RAY_DIFFERENTIALS__
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);
#endif
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);
}
}
}
CCL_NAMESPACE_END

View File

@ -60,12 +60,12 @@ typedef struct HullTriangle {
/*************************** Hull Triangles ***************************/
static void hull_add_triangle(
BMesh *bm, GSet *hull_triangles, BLI_mempool *pool, BMVert *v1, BMVert *v2, BMVert *v3)
BMesh *bm, BLI_mempool *hull_triangles, BMVert *v1, BMVert *v2, BMVert *v3)
{
HullTriangle *t;
int i;
t = BLI_mempool_calloc(pool);
t = BLI_mempool_calloc(hull_triangles);
t->v[0] = v1;
t->v[1] = v2;
t->v[2] = v3;
@ -75,7 +75,6 @@ static void hull_add_triangle(
BMO_vert_flag_disable(bm, t->v[i], HULL_FLAG_INTERIOR_ELE);
}
BLI_gset_insert(hull_triangles, t);
normal_tri_v3(t->no, v1->co, v2->co, v3->co);
}
@ -94,12 +93,13 @@ static BMFace *hull_find_example_face(BMesh *bm, BMEdge *e)
return NULL;
}
static void hull_output_triangles(BMesh *bm, GSet *hull_triangles)
static void hull_output_triangles(BMesh *bm, BLI_mempool *hull_triangles)
{
GSetIterator iter;
BLI_mempool_iter iter;
BLI_mempool_iternew(hull_triangles, &iter);
HullTriangle *t;
GSET_ITER (iter, hull_triangles) {
HullTriangle *t = BLI_gsetIterator_getKey(&iter);
while ((t = BLI_mempool_iterstep(&iter))) {
int i;
if (!t->skip) {
@ -198,18 +198,20 @@ static int hull_final_edges_lookup(HullFinalEdges *final_edges, BMVert *v1, BMVe
}
/* Used for checking whether a pre-existing edge lies on the hull */
static HullFinalEdges *hull_final_edges(GSet *hull_triangles)
static HullFinalEdges *hull_final_edges(BLI_mempool *hull_triangles)
{
HullFinalEdges *final_edges;
GSetIterator iter;
final_edges = MEM_callocN(sizeof(HullFinalEdges), "HullFinalEdges");
final_edges->edges = BLI_ghash_ptr_new("final edges ghash");
final_edges->base_pool = BLI_mempool_create(sizeof(ListBase), 0, 128, BLI_MEMPOOL_NOP);
final_edges->link_pool = BLI_mempool_create(sizeof(LinkData), 0, 128, BLI_MEMPOOL_NOP);
GSET_ITER (iter, hull_triangles) {
HullTriangle *t = BLI_gsetIterator_getKey(&iter);
BLI_mempool_iter iter;
BLI_mempool_iternew(hull_triangles, &iter);
HullTriangle *t;
while ((t = BLI_mempool_iterstep(&iter))) {
LinkData *link;
int i;
@ -250,12 +252,15 @@ static void hull_final_edges_free(HullFinalEdges *final_edges)
/**************************** Final Output ****************************/
static void hull_remove_overlapping(BMesh *bm, GSet *hull_triangles, HullFinalEdges *final_edges)
static void hull_remove_overlapping(BMesh *bm,
BLI_mempool *hull_triangles,
HullFinalEdges *final_edges)
{
GSetIterator hull_iter;
BLI_mempool_iter iter;
BLI_mempool_iternew(hull_triangles, &iter);
HullTriangle *t;
GSET_ITER (hull_iter, hull_triangles) {
HullTriangle *t = BLI_gsetIterator_getKey(&hull_iter);
while ((t = BLI_mempool_iterstep(&iter))) {
BMIter bm_iter1, bm_iter2;
BMFace *f;
bool f_on_hull;
@ -467,7 +472,7 @@ static BMVert **hull_verts_from_bullet(plConvexHull hull,
return hull_verts;
}
static void hull_from_bullet(BMesh *bm, BMOperator *op, GSet *hull_triangles, BLI_mempool *pool)
static void hull_from_bullet(BMesh *bm, BMOperator *op, BLI_mempool *hull_triangles)
{
int *fvi = NULL;
BLI_array_declare(fvi);
@ -509,7 +514,7 @@ static void hull_from_bullet(BMesh *bm, BMOperator *op, GSet *hull_triangles, BL
fv[1] = hull_verts[fvi[j - 1]];
fv[2] = hull_verts[fvi[j]];
hull_add_triangle(bm, hull_triangles, pool, fv[0], fv[1], fv[2]);
hull_add_triangle(bm, hull_triangles, fv[0], fv[1], fv[2]);
}
}
}
@ -543,10 +548,9 @@ static bool hull_num_input_verts_is_ok(BMOperator *op)
void bmo_convex_hull_exec(BMesh *bm, BMOperator *op)
{
HullFinalEdges *final_edges;
BLI_mempool *hull_pool;
BLI_mempool *hull_triangles;
BMElemF *ele;
BMOIter oiter;
GSet *hull_triangles;
/* Verify that at least three verts in the input */
if (!hull_num_input_verts_is_ok(op)) {
@ -569,10 +573,9 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op)
}
}
hull_pool = BLI_mempool_create(sizeof(HullTriangle), 0, 128, BLI_MEMPOOL_NOP);
hull_triangles = BLI_gset_ptr_new("hull_triangles");
hull_triangles = BLI_mempool_create(sizeof(HullTriangle), 0, 128, BLI_MEMPOOL_ALLOW_ITER);
hull_from_bullet(bm, op, hull_triangles, hull_pool);
hull_from_bullet(bm, op, hull_triangles);
final_edges = hull_final_edges(hull_triangles);
@ -590,9 +593,7 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op)
/* Convert hull triangles to BMesh faces */
hull_output_triangles(bm, hull_triangles);
BLI_mempool_destroy(hull_pool);
BLI_gset_free(hull_triangles, NULL);
BLI_mempool_destroy(hull_triangles);
hull_tag_unused(bm, op);