[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21277] branches/soc-2009-jaguarandi/ source/blender/render: *Added initial code of rayobject_rtbuild
André Pinto
andresusanopinto at gmail.com
Wed Jul 1 00:07:44 CEST 2009
Revision: 21277
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21277
Author: jaguarandi
Date: 2009-07-01 00:07:42 +0200 (Wed, 01 Jul 2009)
Log Message:
-----------
*Added initial code of rayobject_rtbuild
An helper class to build trees
Modified Paths:
--------------
branches/soc-2009-jaguarandi/source/blender/render/extern/include/RE_raytrace.h
branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c
Added Paths:
-----------
branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject_rtbuild.h
branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_blibvh.c
branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_rtbuild.c
Removed Paths:
-------------
branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_bvh.c
Modified: branches/soc-2009-jaguarandi/source/blender/render/extern/include/RE_raytrace.h
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/extern/include/RE_raytrace.h 2009-06-30 21:59:21 UTC (rev 21276)
+++ branches/soc-2009-jaguarandi/source/blender/render/extern/include/RE_raytrace.h 2009-06-30 22:07:42 UTC (rev 21277)
@@ -47,7 +47,7 @@
/* RayObject constructors */
RayObject* RE_rayobject_octree_create(int ocres, int size);
-RayObject* RE_rayobject_bvh_create(int size);
+RayObject* RE_rayobject_blibvh_create(int size);
RayObject* RE_rayobject_instance_create(RayObject *target, float transform[][4], void *ob, void *target_ob);
//RayObject* RayObject_derivedmesh_create(struct DerivedMesh*, void *ob);
@@ -59,8 +59,13 @@
float start[3];
float vec[3];
float labda;
+
+ /* length of vec, configured by RE_rayobject_raycast */
+ int bv_index[6];
+ float idot_axis[3];
+ float dist;
- float dist; /* length of vec, configured by RE_rayobject_raycast */
+
/* float end[3]; - not used */
float u, v;
Added: branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject_rtbuild.h
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject_rtbuild.h (rev 0)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject_rtbuild.h 2009-06-30 22:07:42 UTC (rev 21277)
@@ -0,0 +1,84 @@
+/**
+ * $Id$
+ *
+ * ***** 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
+ * of the License, or (at your option) any later version.
+ *
+ * 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,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2009 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): André Pinto.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#ifndef RE_RAYOBJECT_RTBUILD_H
+#define RE_RAYOBJECT_RTBUILD_H
+
+#include "rayobject.h"
+
+/*
+ * Ray Tree Builder
+ * this structs helps building any type of tree
+ * it contains several methods to organiza/split nodes
+ * allowing to create a given tree on the fly.
+ *
+ * Idea is that other trees BVH, BIH can use this code to
+ * generate with simple calls, and then convert to the theirs
+ * specific structure on the fly.
+ */
+#define MAX_CHILDS 32
+typedef struct RTBuilder
+{
+ /* list to all primitives in this tree */
+ RayObject **begin, **end;
+
+ /* axis used (if any) on the split method */
+ int split_axis;
+
+ /* links to child partitions calculated during splitting */
+ RayObject **child[MAX_CHILDS+1];
+
+} RTBuilder;
+
+/* used during creation */
+RTBuilder* rtbuild_create(int size);
+void rtbuild_free(RTBuilder *b);
+void rtbuild_add(RTBuilder *b, RayObject *o);
+int rtbuild_size(RTBuilder *b);
+
+/* used during tree reorganization */
+RTBuilder* rtbuild_get_child(RTBuilder *b, int child, RTBuilder *tmp);
+void rtbuild_mean_split(RTBuilder *b, int nchilds, int axis);
+void rtbuild_mean_split_largest_axis(RTBuilder *b, int nchilds);
+
+/*
+static BVHNode *bvh_rearrange(BVHTree *tree, RTBuilder *b)
+{
+ int i;
+ int nc = rtbuild_mean_split_largest_axis(b, BVH_NCHILDS);
+ RTBuilder tmp;
+
+ BVHNode *bvh = tree->next_node++;
+
+ bvh->split_axis = tmp->split_axis;
+ for(i=0; i<nc; i++)
+ bvh->child[i] = bvh_rearrange( rtbuild_get_child(b, i, &tmp) );
+}
+ */
+
+#endif
Property changes on: branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject_rtbuild.h
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_blibvh.c (from rev 21264, branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_bvh.c)
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_blibvh.c (rev 0)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_blibvh.c 2009-06-30 22:07:42 UTC (rev 21277)
@@ -0,0 +1,140 @@
+/**
+ * $Id$
+ *
+ * ***** 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
+ * of the License, or (at your option) any later version.
+ *
+ * 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,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2009 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): André Pinto.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#include <assert.h>
+
+#include "MEM_guardedalloc.h"
+#include "BKE_utildefines.h"
+#include "BLI_kdopbvh.h"
+#include "BLI_arithb.h"
+#include "RE_raytrace.h"
+#include "render_types.h"
+#include "rayobject.h"
+
+static int RayObject_blibvh_intersect(RayObject *o, Isect *isec);
+static void RayObject_blibvh_add(RayObject *o, RayObject *ob);
+static void RayObject_blibvh_done(RayObject *o);
+static void RayObject_blibvh_free(RayObject *o);
+static void RayObject_blibvh_bb(RayObject *o, float *min, float *max);
+
+static RayObjectAPI bvh_api =
+{
+ RayObject_blibvh_intersect,
+ RayObject_blibvh_add,
+ RayObject_blibvh_done,
+ RayObject_blibvh_free,
+ RayObject_blibvh_bb
+};
+
+typedef struct BVHObject
+{
+ RayObject rayobj;
+ BVHTree *bvh;
+ float bb[2][3];
+
+} BVHObject;
+
+
+RayObject *RE_rayobject_blibvh_create(int size)
+{
+ BVHObject *obj= (BVHObject*)MEM_callocN(sizeof(BVHObject), "BVHObject");
+ assert( RayObject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */
+
+ obj->rayobj.api = &bvh_api;
+ obj->bvh = BLI_bvhtree_new(size, FLT_EPSILON, 4, 6);
+
+ INIT_MINMAX(obj->bb[0], obj->bb[1]);
+ return RayObject_unalignRayAPI((RayObject*) obj);
+}
+
+static void bvh_callback(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
+{
+ Isect *isec = (Isect*)userdata;
+ RayObject *face = (RayObject*)index;
+
+ if(RE_rayobject_intersect(face,isec))
+ {
+ hit->index = index;
+
+ if(isec->mode == RE_RAY_SHADOW)
+ hit->dist = 0;
+ else
+ hit->dist = isec->labda*isec->dist;
+ }
+}
+
+static int RayObject_blibvh_intersect(RayObject *o, Isect *isec)
+{
+ BVHObject *obj = (BVHObject*)o;
+ BVHTreeRayHit hit;
+ float dir[3];
+
+ VECCOPY(dir, isec->vec);
+ Normalize(dir);
+
+ hit.index = 0;
+ hit.dist = isec->labda*isec->dist;
+
+ return BLI_bvhtree_ray_cast(obj->bvh, isec->start, dir, 0.0, &hit, bvh_callback, isec);
+}
+
+static void RayObject_blibvh_add(RayObject *o, RayObject *ob)
+{
+ BVHObject *obj = (BVHObject*)o;
+ float min_max[6];
+ INIT_MINMAX(min_max, min_max+3);
+ RE_rayobject_merge_bb(ob, min_max, min_max+3);
+
+ DO_MINMAX(min_max , obj->bb[0], obj->bb[1]);
+ DO_MINMAX(min_max+3, obj->bb[0], obj->bb[1]);
+
+ BLI_bvhtree_insert(obj->bvh, (int)ob, min_max, 2 );
+}
+
+static void RayObject_blibvh_done(RayObject *o)
+{
+ BVHObject *obj = (BVHObject*)o;
+ BLI_bvhtree_balance(obj->bvh);
+}
+
+static void RayObject_blibvh_free(RayObject *o)
+{
+ BVHObject *obj = (BVHObject*)o;
+
+ if(obj->bvh)
+ BLI_bvhtree_free(obj->bvh);
+
+ MEM_freeN(obj);
+}
+
+static void RayObject_blibvh_bb(RayObject *o, float *min, float *max)
+{
+ BVHObject *obj = (BVHObject*)o;
+ DO_MINMAX( obj->bb[0], min, max );
+ DO_MINMAX( obj->bb[1], min, max );
+}
Deleted: branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_bvh.c
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_bvh.c 2009-06-30 21:59:21 UTC (rev 21276)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_bvh.c 2009-06-30 22:07:42 UTC (rev 21277)
@@ -1,140 +0,0 @@
-/**
- * $Id$
- *
- * ***** 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-#include <assert.h>
-
-#include "MEM_guardedalloc.h"
-#include "BKE_utildefines.h"
-#include "BLI_kdopbvh.h"
-#include "BLI_arithb.h"
-#include "RE_raytrace.h"
-#include "render_types.h"
-#include "rayobject.h"
-
-static int RayObject_bvh_intersect(RayObject *o, Isect *isec);
-static void RayObject_bvh_add(RayObject *o, RayObject *ob);
-static void RayObject_bvh_done(RayObject *o);
-static void RayObject_bvh_free(RayObject *o);
-static void RayObject_bvh_bb(RayObject *o, float *min, float *max);
-
-static RayObjectAPI bvh_api =
-{
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list