Fix #30966: cycles nan mesh vertices got set to (0, 0, 0), now remove them instead.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 16 Apr 2012 08:35:21 +0000 (08:35 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 16 Apr 2012 08:35:21 +0000 (08:35 +0000)
17 files changed:
intern/cycles/app/cycles_xml.cpp
intern/cycles/kernel/kernel_bvh.h
intern/cycles/kernel/kernel_camera.h
intern/cycles/kernel/kernel_mbvh.h
intern/cycles/kernel/kernel_object.h
intern/cycles/kernel/kernel_passes.h
intern/cycles/kernel/kernel_qbvh.h
intern/cycles/kernel/svm/svm_camera.h
intern/cycles/kernel/svm/svm_mapping.h
intern/cycles/kernel/svm/svm_tex_coord.h
intern/cycles/render/camera.cpp
intern/cycles/render/light.cpp
intern/cycles/render/object.cpp
intern/cycles/subd/subd_dice.cpp
intern/cycles/subd/subd_split.cpp
intern/cycles/util/util_boundbox.h
intern/cycles/util/util_transform.h

index b93f61b98d509e4cbd8ca2f395d651e09f75e8a1..b954ff45e2781db68001b58b351df06567e81adc 100644 (file)
@@ -724,7 +724,7 @@ static void xml_read_patch(const XMLReadState& state, pugi::xml_node node)
                        LinearQuadPatch *bpatch = new LinearQuadPatch();
 
                        for(int i = 0; i < 4; i++)
-                               P[i] = transform(&state.tfm, P[i]);
+                               P[i] = transform_point(&state.tfm, P[i]);
                        memcpy(bpatch->hull, &P[0], sizeof(bpatch->hull));
 
                        patch = bpatch;
@@ -738,7 +738,7 @@ static void xml_read_patch(const XMLReadState& state, pugi::xml_node node)
                        BicubicPatch *bpatch = new BicubicPatch();
 
                        for(int i = 0; i < 16; i++)
-                               P[i] = transform(&state.tfm, P[i]);
+                               P[i] = transform_point(&state.tfm, P[i]);
                        memcpy(bpatch->hull, &P[0], sizeof(bpatch->hull));
 
                        patch = bpatch;
@@ -777,7 +777,7 @@ static void xml_read_light(const XMLReadState& state, pugi::xml_node node)
        Light *light = new Light();
        light->shader = state.shader;
        xml_read_float3(&light->co, node, "P");
-       light->co = transform(&state.tfm, light->co);
+       light->co = transform_point(&state.tfm, light->co);
 
        state.scene->lights.push_back(light);
 }
index 35215fd0f9fd1de4b58cb491cd5209ddf42486bb..523ae8ae92621fb92d7167ee24418c7889e12904 100644 (file)
@@ -59,7 +59,7 @@ __device_inline void bvh_instance_push(KernelGlobals *kg, int object, const Ray
 {
        Transform tfm = object_fetch_transform(kg, object, OBJECT_INVERSE_TRANSFORM);
 
-       *P = transform(&tfm, ray->P);
+       *P = transform_point(&tfm, ray->P);
 
        float3 dir = transform_direction(&tfm, ray->D);
 
@@ -351,7 +351,7 @@ __device_inline float3 bvh_triangle_refine(KernelGlobals *kg, const Intersection
        if(isect->object != ~0) {
                Transform tfm = object_fetch_transform(kg, isect->object, OBJECT_INVERSE_TRANSFORM);
 
-               P = transform(&tfm, P);
+               P = transform_point(&tfm, P);
                D = transform_direction(&tfm, D*t);
                D = normalize_len(D, &t);
        }
@@ -367,7 +367,7 @@ __device_inline float3 bvh_triangle_refine(KernelGlobals *kg, const Intersection
 
        if(isect->object != ~0) {
                Transform tfm = object_fetch_transform(kg, isect->object, OBJECT_TRANSFORM);
-               P = transform(&tfm, P);
+               P = transform_point(&tfm, P);
        }
 
        return P;
index 0460765fe862552b91eebd4cda69e22f819d5dc9..58c482212df8142d19567b5b08c9f5d04f5c8b9e 100644 (file)
@@ -39,7 +39,7 @@ __device void camera_sample_perspective(KernelGlobals *kg, float raster_x, float
 {
        /* create ray form raster position */
        Transform rastertocamera = kernel_data.cam.rastertocamera;
-       float3 Pcamera = transform(&rastertocamera, make_float3(raster_x, raster_y, 0.0f));
+       float3 Pcamera = transform_perspective(&rastertocamera, make_float3(raster_x, raster_y, 0.0f));
 
        ray->P = make_float3(0.0f, 0.0f, 0.0f);
        ray->D = Pcamera;
@@ -63,7 +63,7 @@ __device void camera_sample_perspective(KernelGlobals *kg, float raster_x, float
        /* transform ray from camera to world */
        Transform cameratoworld = kernel_data.cam.cameratoworld;
 
-       ray->P = transform(&cameratoworld, ray->P);
+       ray->P = transform_point(&cameratoworld, ray->P);
        ray->D = transform_direction(&cameratoworld, ray->D);
        ray->D = normalize(ray->D);
 
@@ -93,7 +93,7 @@ __device void camera_sample_orthographic(KernelGlobals *kg, float raster_x, floa
 {
        /* create ray form raster position */
        Transform rastertocamera = kernel_data.cam.rastertocamera;
-       float3 Pcamera = transform(&rastertocamera, make_float3(raster_x, raster_y, 0.0f));
+       float3 Pcamera = transform_perspective(&rastertocamera, make_float3(raster_x, raster_y, 0.0f));
 
        ray->P = Pcamera;
        ray->D = make_float3(0.0f, 0.0f, 1.0f);
@@ -101,7 +101,7 @@ __device void camera_sample_orthographic(KernelGlobals *kg, float raster_x, floa
        /* transform ray from camera to world */
        Transform cameratoworld = kernel_data.cam.cameratoworld;
 
-       ray->P = transform(&cameratoworld, ray->P);
+       ray->P = transform_point(&cameratoworld, ray->P);
        ray->D = transform_direction(&cameratoworld, ray->D);
        ray->D = normalize(ray->D);
 
@@ -127,7 +127,7 @@ __device void camera_sample_orthographic(KernelGlobals *kg, float raster_x, floa
 __device void camera_sample_environment(KernelGlobals *kg, float raster_x, float raster_y, Ray *ray)
 {
        Transform rastertocamera = kernel_data.cam.rastertocamera;
-       float3 Pcamera = transform(&rastertocamera, make_float3(raster_x, raster_y, 0.0f));
+       float3 Pcamera = transform_perspective(&rastertocamera, make_float3(raster_x, raster_y, 0.0f));
 
        /* create ray form raster position */
        ray->P = make_float3(0.0, 0.0f, 0.0f);
@@ -136,7 +136,7 @@ __device void camera_sample_environment(KernelGlobals *kg, float raster_x, float
        /* transform ray from camera to world */
        Transform cameratoworld = kernel_data.cam.cameratoworld;
 
-       ray->P = transform(&cameratoworld, ray->P);
+       ray->P = transform_point(&cameratoworld, ray->P);
        ray->D = transform_direction(&cameratoworld, ray->D);
        ray->D = normalize(ray->D);
 
@@ -145,10 +145,10 @@ __device void camera_sample_environment(KernelGlobals *kg, float raster_x, float
        ray->dP.dx = make_float3(0.0f, 0.0f, 0.0f);
        ray->dP.dy = make_float3(0.0f, 0.0f, 0.0f);
 
-       Pcamera = transform(&rastertocamera, make_float3(raster_x + 1.0f, raster_y, 0.0f));
+       Pcamera = transform_perspective(&rastertocamera, make_float3(raster_x + 1.0f, raster_y, 0.0f));
        ray->dD.dx = normalize(transform_direction(&cameratoworld, equirectangular_to_direction(Pcamera.x, Pcamera.y))) - ray->D;
 
-       Pcamera = transform(&rastertocamera, make_float3(raster_x, raster_y + 1.0f, 0.0f));
+       Pcamera = transform_perspective(&rastertocamera, make_float3(raster_x, raster_y + 1.0f, 0.0f));
        ray->dD.dy = normalize(transform_direction(&cameratoworld, equirectangular_to_direction(Pcamera.x, Pcamera.y))) - ray->D;
 #endif
 
index 3995e782abd16044b5b8b7bb85da1917d9e1a2d9..ccbd3d069b4215311b6879709076747f7f1378c1 100644 (file)
@@ -61,7 +61,7 @@ __device void mbvh_instance_push(KernelGlobals *kg, int object, MBVHRay *ray)
 {
        Transform tfm = object_fetch_transform(kg, object, OBJECT_INVERSE_TRANSFORM);
 
-       ray->P = transform(&tfm, ray->origP);
+       ray->P = transform_point(&tfm, ray->origP);
 
        float3 dir = ray->origD;
 
index 318a6fea489cdb7ff88f6b77b4b74dd1d6000829..b676f58e5d4fd74251ee4c83dc6a8818c9f70feb 100644 (file)
@@ -42,7 +42,7 @@ __device_inline Transform object_fetch_transform(KernelGlobals *kg, int object,
 __device_inline void object_position_transform(KernelGlobals *kg, int object, float3 *P)
 {
        Transform tfm = object_fetch_transform(kg, object, OBJECT_TRANSFORM);
-       *P = transform(&tfm, *P);
+       *P = transform_point(&tfm, *P);
 }
 
 __device_inline void object_normal_transform(KernelGlobals *kg, int object, float3 *N)
index d195af293b7454e97f1d537a6df19cd53e77f775..fd4ee17cdc1120e5e69aa012c43a2057c8766726 100644 (file)
@@ -53,7 +53,7 @@ __device_inline void kernel_write_data_passes(KernelGlobals *kg, __global float
                if(sample == 0) {
                        if(flag & PASS_DEPTH) {
                                Transform tfm = kernel_data.cam.worldtocamera;
-                               float depth = len(transform(&tfm, sd->P));
+                               float depth = len(transform_point(&tfm, sd->P));
 
                                kernel_write_pass_float(buffer + kernel_data.film.pass_depth, sample, depth);
                        }
index 96e68d797ddd67b9280ad7a8f64beafde747993c..525b616921d02062a729115642f53991aadfe1c1 100644 (file)
@@ -50,7 +50,7 @@ __device_inline void qbvh_instance_push(KernelGlobals *kg, int object, const Ray
 {
        Transform tfm = object_fetch_transform(kg, object, OBJECT_INVERSE_TRANSFORM);
 
-       *P = transform(&tfm, ray->P);
+       *P = transform_point(&tfm, ray->P);
 
        float3 dir = transform_direction(&tfm, ray->D);
 
@@ -384,7 +384,7 @@ __device_inline float3 bvh_triangle_refine(KernelGlobals *kg, const Intersection
        if(isect->object != ~0) {
                Transform tfm = object_fetch_transform(kg, isect->object, OBJECT_INVERSE_TRANSFORM);
 
-               P = transform(&tfm, P);
+               P = transform_point(&tfm, P);
                D = transform_direction(&tfm, D*t);
                D = normalize_len(D, &t);
        }
@@ -400,7 +400,7 @@ __device_inline float3 bvh_triangle_refine(KernelGlobals *kg, const Intersection
 
        if(isect->object != ~0) {
                Transform tfm = object_fetch_transform(kg, isect->object, OBJECT_TRANSFORM);
-               P = transform(&tfm, P);
+               P = transform_point(&tfm, P);
        }
 
        return P;
index cf161ddcd8cf67f96b4cc2e7975ad889396749d2..f13cefb77640797aed3a7a69bbe557102451cdfe 100644 (file)
@@ -25,7 +25,7 @@ __device void svm_node_camera(KernelGlobals *kg, ShaderData *sd, float *stack, u
        float3 vector;
 
        Transform tfm = kernel_data.cam.worldtocamera;
-       vector = transform(&tfm, sd->P);
+       vector = transform_point(&tfm, sd->P);
        zdepth = vector.z;
        distance = len(vector);
 
index 7633c3e783b128d188108a8485ab9cd15b13ed03..6dc74aece085f35d970c4ab83b6844b9ee6d7c7f 100644 (file)
@@ -30,7 +30,7 @@ __device void svm_node_mapping(KernelGlobals *kg, ShaderData *sd, float *stack,
        tfm.z = read_node_float(kg, offset);
        tfm.w = read_node_float(kg, offset);
 
-       float3 r = transform(&tfm, v);
+       float3 r = transform_point(&tfm, v);
        stack_store_float3(stack, out_offset, r);
 }
 
index bcf3716ae57095250dea095383eefaa7efe86568..f494b6d66e1c9b6c6e70b2b057b651c00432fa7d 100644 (file)
@@ -34,7 +34,7 @@ __device void svm_node_tex_coord(KernelGlobals *kg, ShaderData *sd, float *stack
                case NODE_TEXCO_OBJECT: {
                        if(sd->object != ~0) {
                                Transform tfm = object_fetch_transform(kg, sd->object, OBJECT_INVERSE_TRANSFORM);
-                               data = transform(&tfm, sd->P);
+                               data = transform_point(&tfm, sd->P);
                        }
                        else
                                data = sd->P;
@@ -44,18 +44,18 @@ __device void svm_node_tex_coord(KernelGlobals *kg, ShaderData *sd, float *stack
                        Transform tfm = kernel_data.cam.worldtocamera;
 
                        if(sd->object != ~0)
-                               data = transform(&tfm, sd->P);
+                               data = transform_point(&tfm, sd->P);
                        else
-                               data = transform(&tfm, sd->P + svm_background_offset(kg));
+                               data = transform_point(&tfm, sd->P + svm_background_offset(kg));
                        break;
                }
                case NODE_TEXCO_WINDOW: {
                        Transform tfm = kernel_data.cam.worldtondc;
 
                        if(sd->object != ~0)
-                               data = transform(&tfm, sd->P);
+                               data = transform_perspective(&tfm, sd->P);
                        else
-                               data = transform(&tfm, sd->P + svm_background_offset(kg));
+                               data = transform_perspective(&tfm, sd->P + svm_background_offset(kg));
                        break;
                }
                case NODE_TEXCO_REFLECTION: {
@@ -79,7 +79,7 @@ __device void svm_node_tex_coord_bump_dx(KernelGlobals *kg, ShaderData *sd, floa
                case NODE_TEXCO_OBJECT: {
                        if(sd->object != ~0) {
                                Transform tfm = object_fetch_transform(kg, sd->object, OBJECT_INVERSE_TRANSFORM);
-                               data = transform(&tfm, sd->P + sd->dP.dx);
+                               data = transform_point(&tfm, sd->P + sd->dP.dx);
                        }
                        else
                                data = sd->P + sd->dP.dx;
@@ -89,18 +89,18 @@ __device void svm_node_tex_coord_bump_dx(KernelGlobals *kg, ShaderData *sd, floa
                        Transform tfm = kernel_data.cam.worldtocamera;
 
                        if(sd->object != ~0)
-                               data = transform(&tfm, sd->P + sd->dP.dx);
+                               data = transform_point(&tfm, sd->P + sd->dP.dx);
                        else
-                               data = transform(&tfm, sd->P + sd->dP.dx + svm_background_offset(kg));
+                               data = transform_point(&tfm, sd->P + sd->dP.dx + svm_background_offset(kg));
                        break;
                }
                case NODE_TEXCO_WINDOW: {
                        Transform tfm = kernel_data.cam.worldtondc;
 
                        if(sd->object != ~0)
-                               data = transform(&tfm, sd->P + sd->dP.dx);
+                               data = transform_perspective(&tfm, sd->P + sd->dP.dx);
                        else
-                               data = transform(&tfm, sd->P + sd->dP.dx + svm_background_offset(kg));
+                               data = transform_perspective(&tfm, sd->P + sd->dP.dx + svm_background_offset(kg));
                        break;
                }
                case NODE_TEXCO_REFLECTION: {
@@ -127,7 +127,7 @@ __device void svm_node_tex_coord_bump_dy(KernelGlobals *kg, ShaderData *sd, floa
                case NODE_TEXCO_OBJECT: {
                        if(sd->object != ~0) {
                                Transform tfm = object_fetch_transform(kg, sd->object, OBJECT_INVERSE_TRANSFORM);
-                               data = transform(&tfm, sd->P + sd->dP.dy);
+                               data = transform_point(&tfm, sd->P + sd->dP.dy);
                        }
                        else
                                data = sd->P + sd->dP.dy;
@@ -137,18 +137,18 @@ __device void svm_node_tex_coord_bump_dy(KernelGlobals *kg, ShaderData *sd, floa
                        Transform tfm = kernel_data.cam.worldtocamera;
 
                        if(sd->object != ~0)
-                               data = transform(&tfm, sd->P + sd->dP.dy);
+                               data = transform_point(&tfm, sd->P + sd->dP.dy);
                        else
-                               data = transform(&tfm, sd->P + sd->dP.dy + svm_background_offset(kg));
+                               data = transform_point(&tfm, sd->P + sd->dP.dy + svm_background_offset(kg));
                        break;
                }
                case NODE_TEXCO_WINDOW: {
                        Transform tfm = kernel_data.cam.worldtondc;
 
                        if(sd->object != ~0)
-                               data = transform(&tfm, sd->P + sd->dP.dy);
+                               data = transform_perspective(&tfm, sd->P + sd->dP.dy);
                        else
-                               data = transform(&tfm, sd->P + sd->dP.dy + svm_background_offset(kg));
+                               data = transform_perspective(&tfm, sd->P + sd->dP.dy + svm_background_offset(kg));
                        break;
                }
                case NODE_TEXCO_REFLECTION: {
index 6edf9c66f1d7f37d605cbab5c17d5e5bbcedbfde..f9290dfc83544d59da2b6a451c65cd20b69b448c 100644 (file)
@@ -107,10 +107,10 @@ void Camera::update()
                dy = transform_direction(&rastertocamera, make_float3(0, 1, 0));
        }
        else if(type == CAMERA_PERSPECTIVE) {
-               dx = transform(&rastertocamera, make_float3(1, 0, 0)) -
-                    transform(&rastertocamera, make_float3(0, 0, 0));
-               dy = transform(&rastertocamera, make_float3(0, 1, 0)) -
-                    transform(&rastertocamera, make_float3(0, 0, 0));
+               dx = transform_perspective(&rastertocamera, make_float3(1, 0, 0)) -
+                    transform_perspective(&rastertocamera, make_float3(0, 0, 0));
+               dy = transform_perspective(&rastertocamera, make_float3(0, 1, 0)) -
+                    transform_perspective(&rastertocamera, make_float3(0, 0, 0));
        }
        else {
                dx = make_float3(0, 0, 0);
index bd3acb00f6d8c863b7f1eff352c89b474db7f46d..316e5cec9aa7bf9c19dea81673c2a085a54cffeb 100644 (file)
@@ -213,9 +213,9 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen
                                        offset++;
 
                                        Mesh::Triangle t = mesh->triangles[i];
-                                       float3 p1 = transform(&tfm, mesh->verts[t.v[0]]);
-                                       float3 p2 = transform(&tfm, mesh->verts[t.v[1]]);
-                                       float3 p3 = transform(&tfm, mesh->verts[t.v[2]]);
+                                       float3 p1 = transform_point(&tfm, mesh->verts[t.v[0]]);
+                                       float3 p2 = transform_point(&tfm, mesh->verts[t.v[1]]);
+                                       float3 p3 = transform_point(&tfm, mesh->verts[t.v[2]]);
 
                                        totarea += triangle_area(p1, p2, p3);
                                }
index f83c85c632d03d3b43f1f0c674354084a99e3ce9..5f7a5810c0982227c0db590e7c9a2a10e169e97b 100644 (file)
@@ -54,7 +54,7 @@ void Object::apply_transform()
                return;
        
        for(size_t i = 0; i < mesh->verts.size(); i++)
-               mesh->verts[i] = transform(&tfm, mesh->verts[i]);
+               mesh->verts[i] = transform_point(&tfm, mesh->verts[i]);
 
        Attribute *attr_fN = mesh->attributes.find(Attribute::STD_FACE_NORMAL);
        Attribute *attr_vN = mesh->attributes.find(Attribute::STD_VERTEX_NORMAL);
@@ -159,9 +159,9 @@ void ObjectManager::device_update_transforms(Device *device, DeviceScene *dscene
                }
                else {
                        foreach(Mesh::Triangle& t, mesh->triangles) {
-                               float3 p1 = transform(&tfm, mesh->verts[t.v[0]]);
-                               float3 p2 = transform(&tfm, mesh->verts[t.v[1]]);
-                               float3 p3 = transform(&tfm, mesh->verts[t.v[2]]);
+                               float3 p1 = transform_point(&tfm, mesh->verts[t.v[0]]);
+                               float3 p2 = transform_point(&tfm, mesh->verts[t.v[1]]);
+                               float3 p3 = transform_point(&tfm, mesh->verts[t.v[2]]);
 
                                surface_area += triangle_area(p1, p2, p3);
                        }
index 086b7b246d3d40b36c9c14ecccc9aef0d3cf51de..6b29d1ca51a21481ed111bbba93883ecac72287a 100644 (file)
@@ -141,7 +141,7 @@ float3 QuadDice::eval_projected(SubPatch& sub, float u, float v)
 
        sub.patch->eval(&P, NULL, NULL, uv.x, uv.y);
        if(camera)
-               P = transform(&camera->worldtoraster, P);
+               P = transform_perspective(&camera->worldtoraster, P);
 
        return P;
 }
index d61a42e4dcf0600fcb048539e755f6d6430b61ac..f0b87200f08c753d2ef8c051c365ff47db1395ad 100644 (file)
@@ -57,7 +57,7 @@ float3 DiagSplit::project(Patch *patch, float2 uv)
 
        patch->eval(&P, NULL, NULL, uv.x, uv.y);
        if(camera)
-               P = transform(&camera->worldtoraster, P);
+               P = transform_perspective(&camera->worldtoraster, P);
 
        return P;
 }
index 0114a9a26a5af2f41c173b66eb98c7f2e0c9c8b4..bb1df0b220f974a43b5d69ea663f8f3c1fbfa5a2 100644 (file)
@@ -76,8 +76,8 @@ public:
        bool valid(void) const
        {
                return (min.x <= max.x) && (min.y <= max.y) && (min.z <= max.z) &&
-                      !(isnan(min.x) || isnan(min.y) || isnan(min.z)) &&
-                      !(isnan(max.x) || isnan(max.y) || isnan(max.z));
+                      (isfinite(min.x) && isfinite(min.y) && isfinite(min.z)) &&
+                      (isfinite(max.x) && isfinite(max.y) && isfinite(max.z));
        }
 
        BoundBox transformed(const Transform *tfm)
@@ -91,7 +91,7 @@ public:
                        p.y = (i & 2)? min.y: max.y;
                        p.z = (i & 4)? min.z: max.z;
 
-                       result.grow(transform(tfm, p));
+                       result.grow(transform_point(tfm, p));
                }
 
                return result;
index 07db52f6392b6b5a29ec96b34b880e61de4cc851..aeaef7b0e216c72e8356b202423a2fc804a3ce70 100644 (file)
@@ -37,7 +37,7 @@ typedef struct Transform {
 #endif
 } Transform;
 
-__device_inline float3 transform(const Transform *t, const float3 a)
+__device_inline float3 transform_perspective(const Transform *t, const float3 a)
 {
        float4 b = make_float4(a.x, a.y, a.z, 1.0f);
        float3 c = make_float3(dot(t->x, b), dot(t->y, b), dot(t->z, b));
@@ -46,6 +46,14 @@ __device_inline float3 transform(const Transform *t, const float3 a)
        return (w != 0.0f)? c/w: make_float3(0.0f, 0.0f, 0.0f);
 }
 
+__device_inline float3 transform_point(const Transform *t, const float3 a)
+{
+       float4 b = make_float4(a.x, a.y, a.z, 1.0f);
+       float3 c = make_float3(dot(t->x, b), dot(t->y, b), dot(t->z, b));
+
+       return c;
+}
+
 __device_inline float3 transform_direction(const Transform *t, const float3 a)
 {
        float4 b = make_float4(a.x, a.y, a.z, 0.0f);