2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-06-03 14:42:28 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2018-06-01 18:19:39 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2009-06-03 14:42:28 +00:00
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-06-03 14:42:28 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2009 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
|
*
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
* Contributor(s): André Pinto.
|
2009-06-03 14:42:28 +00:00
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
|
2011-02-27 19:31:27 +00:00
|
|
|
/** \file blender/render/intern/raytrace/rayobject_instance.cpp
|
|
|
|
|
* \ingroup render
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2009-06-03 14:42:28 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
#include "BLI_math.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
#include "rayintersection.h"
|
2009-06-03 14:42:28 +00:00
|
|
|
#include "rayobject.h"
|
|
|
|
|
|
2009-07-10 16:42:51 +00:00
|
|
|
#define RE_COST_INSTANCE (1.0f)
|
|
|
|
|
|
2009-08-25 20:26:50 +00:00
|
|
|
static int RE_rayobject_instance_intersect(RayObject *o, Isect *isec);
|
|
|
|
|
static void RE_rayobject_instance_free(RayObject *o);
|
|
|
|
|
static void RE_rayobject_instance_bb(RayObject *o, float *min, float *max);
|
|
|
|
|
static float RE_rayobject_instance_cost(RayObject *o);
|
2009-06-03 14:42:28 +00:00
|
|
|
|
2012-01-14 10:08:47 +00:00
|
|
|
static void RE_rayobject_instance_hint_bb(RayObject *UNUSED(o), RayHint *UNUSED(hint),
|
|
|
|
|
float *UNUSED(min), float *UNUSED(max))
|
2009-10-10 18:42:20 +00:00
|
|
|
{}
|
|
|
|
|
|
2009-06-03 14:42:28 +00:00
|
|
|
static RayObjectAPI instance_api =
|
|
|
|
|
{
|
2009-08-25 20:26:50 +00:00
|
|
|
RE_rayobject_instance_intersect,
|
|
|
|
|
NULL, //static void RE_rayobject_instance_add(RayObject *o, RayObject *ob);
|
|
|
|
|
NULL, //static void RE_rayobject_instance_done(RayObject *o);
|
|
|
|
|
RE_rayobject_instance_free,
|
|
|
|
|
RE_rayobject_instance_bb,
|
2009-10-10 18:42:20 +00:00
|
|
|
RE_rayobject_instance_cost,
|
2012-10-21 05:46:41 +00:00
|
|
|
RE_rayobject_instance_hint_bb
|
2009-06-03 14:42:28 +00:00
|
|
|
};
|
|
|
|
|
|
2012-06-06 22:38:39 +00:00
|
|
|
typedef struct InstanceRayObject {
|
2009-06-03 14:42:28 +00:00
|
|
|
RayObject rayobj;
|
|
|
|
|
RayObject *target;
|
2009-06-11 16:44:01 +00:00
|
|
|
|
|
|
|
|
void *ob; //Object represented by this instance
|
|
|
|
|
void *target_ob; //Object represented by the inner RayObject, needed to handle self-intersection
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2009-06-03 14:42:28 +00:00
|
|
|
float global2target[4][4];
|
|
|
|
|
float target2global[4][4];
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2009-06-03 14:42:28 +00:00
|
|
|
} InstanceRayObject;
|
|
|
|
|
|
|
|
|
|
|
2012-12-11 14:29:01 +00:00
|
|
|
RayObject *RE_rayobject_instance_create(RayObject *target, float transform[4][4], void *ob, void *target_ob)
|
2009-06-03 14:42:28 +00:00
|
|
|
{
|
2012-06-27 18:29:47 +00:00
|
|
|
InstanceRayObject *obj = (InstanceRayObject *)MEM_callocN(sizeof(InstanceRayObject), "InstanceRayObject");
|
|
|
|
|
assert(RE_rayobject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */
|
|
|
|
|
|
2009-06-03 14:42:28 +00:00
|
|
|
obj->rayobj.api = &instance_api;
|
|
|
|
|
obj->target = target;
|
2009-06-11 16:44:01 +00:00
|
|
|
obj->ob = ob;
|
|
|
|
|
obj->target_ob = target_ob;
|
2012-06-27 18:29:47 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
copy_m4_m4(obj->target2global, transform);
|
|
|
|
|
invert_m4_m4(obj->global2target, obj->target2global);
|
2012-06-27 18:29:47 +00:00
|
|
|
|
|
|
|
|
return RE_rayobject_unalignRayAPI((RayObject *) obj);
|
2009-06-03 14:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-25 20:26:50 +00:00
|
|
|
static int RE_rayobject_instance_intersect(RayObject *o, Isect *isec)
|
2009-06-03 14:42:28 +00:00
|
|
|
{
|
2012-06-27 18:29:47 +00:00
|
|
|
InstanceRayObject *obj = (InstanceRayObject *)o;
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
float start[3], dir[3], idot_axis[3], dist;
|
|
|
|
|
int changed = 0, i, res;
|
2012-06-27 18:29:47 +00:00
|
|
|
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
// TODO - this is disabling self intersection on instances
|
2012-04-28 06:31:57 +00:00
|
|
|
if (isec->orig.ob == obj->ob && obj->ob) {
|
2009-06-11 16:44:01 +00:00
|
|
|
changed = 1;
|
|
|
|
|
isec->orig.ob = obj->target_ob;
|
|
|
|
|
}
|
2012-06-27 18:29:47 +00:00
|
|
|
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
// backup old values
|
|
|
|
|
copy_v3_v3(start, isec->start);
|
|
|
|
|
copy_v3_v3(dir, isec->dir);
|
|
|
|
|
copy_v3_v3(idot_axis, isec->idot_axis);
|
|
|
|
|
dist = isec->dist;
|
2009-06-11 16:44:01 +00:00
|
|
|
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
// transform to target coordinates system
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_m4_v3(obj->global2target, isec->start);
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
mul_mat3_m4_v3(obj->global2target, isec->dir);
|
|
|
|
|
isec->dist *= normalize_v3(isec->dir);
|
2012-06-27 18:29:47 +00:00
|
|
|
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
// update idot_axis and bv_index
|
2012-06-27 18:29:47 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
|
isec->idot_axis[i] = 1.0f / isec->dir[i];
|
|
|
|
|
|
2012-08-05 13:26:39 +00:00
|
|
|
isec->bv_index[2 * i] = isec->idot_axis[i] < 0.0f ? 1 : 0;
|
2012-06-27 18:29:47 +00:00
|
|
|
isec->bv_index[2 * i + 1] = 1 - isec->bv_index[2 * i];
|
|
|
|
|
|
|
|
|
|
isec->bv_index[2 * i] = i + 3 * isec->bv_index[2 * i];
|
|
|
|
|
isec->bv_index[2 * i + 1] = i + 3 * isec->bv_index[2 * i + 1];
|
2009-07-10 16:42:51 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-08 18:10:29 +02:00
|
|
|
// Pre-calculate orientation for watertight intersection checks.
|
|
|
|
|
isect_ray_tri_watertight_v3_precalc(&isec->isect_precalc, isec->dir);
|
|
|
|
|
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
// raycast
|
2009-06-03 14:42:28 +00:00
|
|
|
res = RE_rayobject_intersect(obj->target, isec);
|
|
|
|
|
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
// map dist into original coordinate space
|
2012-04-28 06:31:57 +00:00
|
|
|
if (res == 0) {
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
isec->dist = dist;
|
2009-06-11 16:44:01 +00:00
|
|
|
}
|
2012-04-28 06:31:57 +00:00
|
|
|
else {
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
// note we don't just multiply dist, because of possible
|
|
|
|
|
// non-uniform scaling in the transform matrix
|
|
|
|
|
float vec[3];
|
|
|
|
|
|
|
|
|
|
mul_v3_v3fl(vec, isec->dir, isec->dist);
|
|
|
|
|
mul_mat3_m4_v3(obj->target2global, vec);
|
|
|
|
|
|
|
|
|
|
isec->dist = len_v3(vec);
|
2009-06-11 16:44:01 +00:00
|
|
|
isec->hit.ob = obj->ob;
|
2010-06-15 20:00:01 +00:00
|
|
|
|
2012-06-27 18:29:47 +00:00
|
|
|
#ifdef RT_USE_LAST_HIT
|
2010-06-15 20:00:01 +00:00
|
|
|
// TODO support for last hit optimization in instances that can jump
|
|
|
|
|
// directly to the last hit face.
|
|
|
|
|
// For now it jumps directly to the last-hit instance root node.
|
2012-06-27 18:29:47 +00:00
|
|
|
isec->last_hit = RE_rayobject_unalignRayAPI((RayObject *) obj);
|
2010-06-15 20:00:01 +00:00
|
|
|
#endif
|
2009-06-03 14:42:28 +00:00
|
|
|
}
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
|
|
|
|
|
// restore values
|
|
|
|
|
copy_v3_v3(isec->start, start);
|
|
|
|
|
copy_v3_v3(isec->dir, dir);
|
|
|
|
|
copy_v3_v3(isec->idot_axis, idot_axis);
|
2012-06-27 18:29:47 +00:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (changed)
|
2009-06-11 16:44:01 +00:00
|
|
|
isec->orig.ob = obj->ob;
|
2009-07-10 16:42:51 +00:00
|
|
|
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
// restore bv_index
|
2012-06-27 18:29:47 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2012-08-05 13:26:39 +00:00
|
|
|
isec->bv_index[2 * i] = isec->idot_axis[i] < 0.0f ? 1 : 0;
|
2012-06-27 18:29:47 +00:00
|
|
|
isec->bv_index[2 * i + 1] = 1 - isec->bv_index[2 * i];
|
|
|
|
|
|
|
|
|
|
isec->bv_index[2 * i] = i + 3 * isec->bv_index[2 * i];
|
|
|
|
|
isec->bv_index[2 * i + 1] = i + 3 * isec->bv_index[2 * i + 1];
|
2009-07-10 16:42:51 +00:00
|
|
|
}
|
2012-06-27 18:29:47 +00:00
|
|
|
|
2016-07-08 18:10:29 +02:00
|
|
|
// Pre-calculate orientation for watertight intersection checks.
|
|
|
|
|
isect_ray_tri_watertight_v3_precalc(&isec->isect_precalc, isec->dir);
|
|
|
|
|
|
2009-06-03 14:42:28 +00:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-25 20:26:50 +00:00
|
|
|
static void RE_rayobject_instance_free(RayObject *o)
|
2009-06-03 14:42:28 +00:00
|
|
|
{
|
2012-12-28 14:19:05 +00:00
|
|
|
InstanceRayObject *obj = (InstanceRayObject *)o;
|
2009-06-03 14:42:28 +00:00
|
|
|
MEM_freeN(obj);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-25 20:26:50 +00:00
|
|
|
static float RE_rayobject_instance_cost(RayObject *o)
|
2009-07-10 16:42:51 +00:00
|
|
|
{
|
2012-12-28 14:19:05 +00:00
|
|
|
InstanceRayObject *obj = (InstanceRayObject *)o;
|
2009-07-10 16:42:51 +00:00
|
|
|
return RE_rayobject_cost(obj->target) + RE_COST_INSTANCE;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-25 20:26:50 +00:00
|
|
|
static void RE_rayobject_instance_bb(RayObject *o, float *min, float *max)
|
2009-06-03 14:42:28 +00:00
|
|
|
{
|
|
|
|
|
//TODO:
|
2009-06-11 16:44:01 +00:00
|
|
|
// *better bb.. calculated without rotations of bb
|
|
|
|
|
// *maybe cache that better-fitted-BB at the InstanceRayObject
|
2012-06-27 18:29:47 +00:00
|
|
|
InstanceRayObject *obj = (InstanceRayObject *)o;
|
2009-06-03 14:42:28 +00:00
|
|
|
|
2009-06-11 16:44:01 +00:00
|
|
|
float m[3], M[3], t[3];
|
|
|
|
|
int i, j;
|
2009-06-03 14:42:28 +00:00
|
|
|
INIT_MINMAX(m, M);
|
|
|
|
|
RE_rayobject_merge_bb(obj->target, m, M);
|
|
|
|
|
|
2009-06-11 16:44:01 +00:00
|
|
|
//There must be a faster way than rotating all the 8 vertexs of the BB
|
2012-06-27 18:29:47 +00:00
|
|
|
for (i = 0; i < 8; i++) {
|
2015-06-04 15:28:26 +10:00
|
|
|
for (j = 0; j < 3; j++) t[j] = (i & (1 << j)) ? M[j] : m[j];
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_m4_v3(obj->target2global, t);
|
2009-06-11 16:44:01 +00:00
|
|
|
DO_MINMAX(t, min, max);
|
|
|
|
|
}
|
2009-06-03 14:42:28 +00:00
|
|
|
}
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
|