[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23466] branches/soc-2009-jaguarandi/ source/blender/render: *Added VlakPrimitive ( this rayobject rimitive only stores ObjectRenderInstance and VlakRen pointers )

Andre Susano Pinto andresusanopinto at gmail.com
Fri Sep 25 00:55:57 CEST 2009


Revision: 23466
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23466
Author:   jaguarandi
Date:     2009-09-25 00:55:57 +0200 (Fri, 25 Sep 2009)

Log Message:
-----------
*Added VlakPrimitive (this rayobject rimitive only stores ObjectRenderInstance and VlakRen pointers)
- it difers from RayFace that localy stored the vertex coordinates.
- basicaly this reduces memory usage

Modified Paths:
--------------
    branches/soc-2009-jaguarandi/source/blender/render/extern/include/RE_raytrace.h
    branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject.h
    branches/soc-2009-jaguarandi/source/blender/render/intern/include/render_types.h
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/renderdatabase.c

Added Paths:
-----------
    branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject.cpp

Removed Paths:
-------------
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject.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-09-24 22:11:35 UTC (rev 23465)
+++ branches/soc-2009-jaguarandi/source/blender/render/extern/include/RE_raytrace.h	2009-09-24 22:55:57 UTC (rev 23466)
@@ -52,6 +52,8 @@
 
 struct DerivedMesh;
 struct Mesh;
+struct VlakRen;
+struct ObjectInstanceRen;
 
 int  RE_rayobject_raycast(RayObject *r, Isect *i);
 void RE_rayobject_add    (RayObject *r, RayObject *);
@@ -93,14 +95,28 @@
 } RayFace;
 
 #define RE_rayface_isQuad(a) ((a)->quad)
-struct VlakRen;
-struct ObjectInstanceRen;
 
 RayObject* RE_rayface_from_vlak(RayFace *face, struct ObjectInstanceRen *obi, struct VlakRen *vlr);
 RayObject* RE_rayface_from_coords(RayFace *rayface, void *ob, void *face, float *co1, float *co2, float *co3, float *co4);
 
 
+/*
+ * This ray object represents faces directly from a given VlakRen structure.
+ * Thus allowing to save memory, but making code triangle intersection dependant on render structures
+ */
+typedef struct VlakPrimitive
+{
+	struct ObjectInstanceRen *ob;
+	struct VlakRen *face;
+} VlakPrimitive;
 
+RayObject* RE_vlakprimitive_from_vlak(VlakPrimitive *face, struct ObjectInstanceRen *obi, struct VlakRen *vlr);
+
+
+
+/*
+ * Raytrace hints
+ */
 typedef struct LCTSHint LCTSHint;
 struct LCTSHint
 {

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject.h
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject.h	2009-09-24 22:11:35 UTC (rev 23465)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject.h	2009-09-24 22:55:57 UTC (rev 23466)
@@ -57,17 +57,18 @@
 	
 	In order to allow a mixture of RayFace+RayObjects,
 	all RayObjects must be 4byte aligned, allowing us to use the
-	2 least significant bits (with the mask 0x02) to define the
+	2 least significant bits (with the mask 0x03) to define the
 	type of RayObject.
 	
-	This leads to 4 possible types of RayObject, but at the moment
-	only 2 are used:
+	This leads to 4 possible types of RayObject:
 
-	 addr&2  - type of object
+	 addr&3  - type of object
 	 	0		Self (reserved for each structure)
-		1     	RayFace
+		1     	RayFace (tri/quad primitive)
 		2		RayObject (generic with API callbacks)
-		3		RayObject_Vlak
+		3		VlakPrimitive
+				(vlak primitive - to be used when we have a vlak describing the data
+				 eg.: on render code)
 
 	0 means it's reserved and has it own meaning inside each ray acceleration structure
 	(this way each structure can use the allign offset to determine if a node represents a
@@ -83,26 +84,16 @@
 /* used to unalign a given ray object */
 #define RE_rayobject_unalignRayFace(o)		((RayObject*)(((intptr_t)o)|1))
 #define RE_rayobject_unalignRayAPI(o)		((RayObject*)(((intptr_t)o)|2))
-#define RE_rayobject_unalignRayVlak(o)		((RayObject*)(((intptr_t)o)|3))
+#define RE_rayobject_unalignVlakPrimitive(o)	((RayObject*)(((intptr_t)o)|3))
 
 /* used to test the type of ray object */
 #define RE_rayobject_isAligned(o)	((((intptr_t)o)&3) == 0)
 #define RE_rayobject_isRayFace(o)	((((intptr_t)o)&3) == 1)
 #define RE_rayobject_isRayAPI(o)	((((intptr_t)o)&3) == 2)
-#define RE_rayobject_isRayVlak(o)	((((intptr_t)o)&3) == 3)
+#define RE_rayobject_isVlakPrimitive(o)	((((intptr_t)o)&3) == 3)
 
 
 /*
- * This ray object represents faces directly from a given VlakRen structure.
- * Thus allowing to save memory, but making code dependant on render structures
-typedef struct RayVlak
-{
-	struct ObjectInstanceRen *ob;
-	struct VlakRen *face;
-} RayVlak;
- */
-
-/*
  * This rayobject represents a generic object. With it's own callbacks for raytrace operations.
  * It's suitable to implement things like LOD.
  */

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/include/render_types.h
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/include/render_types.h	2009-09-24 22:11:35 UTC (rev 23465)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/include/render_types.h	2009-09-24 22:55:57 UTC (rev 23466)
@@ -172,6 +172,7 @@
 	/* octree tables and variables for raytrace */
 	struct RayObject *raytree;
 	struct RayFace *rayfaces;
+	struct VlakPrimitive *rayprimitives;
 	float maxdist; /* needed for keeping an incorrect behaviour of SUN and HEMI lights (avoid breaking old scenes) */
 
 	/* occlusion tree */
@@ -289,6 +290,7 @@
 	/* used on makeraytree */
 	struct RayObject *raytree;
 	struct RayFace *rayfaces;
+	struct VlakPrimitive *rayprimitives;
 	struct ObjectInstanceRen *rayobi;
 	
 } ObjectRen;
@@ -313,6 +315,7 @@
 	
 	/* used on makeraytree */
 	struct RayObject *raytree;
+	int transform_primitives;
 
 } ObjectInstanceRen;
 

Copied: branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject.cpp (from rev 23365, branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject.c)
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject.cpp	                        (rev 0)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject.cpp	2009-09-24 22:55:57 UTC (rev 23466)
@@ -0,0 +1,529 @@
+/**
+ * $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 "BKE_utildefines.h"
+#include "BLI_arithb.h"
+#include "DNA_material_types.h"
+
+#include "RE_raytrace.h"
+#include "render_types.h"
+#include "rayobject.h"
+#include "raycounter.h"
+
+/*
+ * Determines the distance that the ray must travel to hit the bounding volume of the given node
+ * Based on Tactical Optimization of Ray/Box Intersection, by Graham Fyffe
+ *  [http://tog.acm.org/resources/RTNews/html/rtnv21n1.html#art9]
+ */
+int RE_rayobject_bb_intersect_test(const Isect *isec, const float *_bb)
+{
+	const float *bb = _bb;
+	
+	float t1x = (bb[isec->bv_index[0]] - isec->start[0]) * isec->idot_axis[0];
+	float t2x = (bb[isec->bv_index[1]] - isec->start[0]) * isec->idot_axis[0];
+	float t1y = (bb[isec->bv_index[2]] - isec->start[1]) * isec->idot_axis[1];
+	float t2y = (bb[isec->bv_index[3]] - isec->start[1]) * isec->idot_axis[1];
+	float t1z = (bb[isec->bv_index[4]] - isec->start[2]) * isec->idot_axis[2];
+	float t2z = (bb[isec->bv_index[5]] - isec->start[2]) * isec->idot_axis[2];
+
+	RE_RC_COUNT(isec->raycounter->bb.test);
+	
+	if(t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return 0;
+	if(t2x < 0.0 || t2y < 0.0 || t2z < 0.0) return 0;
+	if(t1x > isec->labda || t1y > isec->labda || t1z > isec->labda) return 0;
+	RE_RC_COUNT(isec->raycounter->bb.hit);	
+
+	return 1;
+}
+
+
+/* only for self-intersecting test with current render face (where ray left) */
+static int intersection2(VlakRen *face, float r0, float r1, float r2, float rx1, float ry1, float rz1)
+{
+	float co1[3], co2[3], co3[3], co4[3];
+	float x0,x1,x2,t00,t01,t02,t10,t11,t12,t20,t21,t22;
+	float m0, m1, m2, divdet, det, det1;
+	float u1, v, u2;
+
+	VECCOPY(co1, face->v1->co);
+	VECCOPY(co2, face->v2->co);
+	if(face->v4)
+	{
+		VECCOPY(co3, face->v4->co);
+		VECCOPY(co4, face->v3->co);
+	}
+	else
+	{
+		VECCOPY(co3, face->v3->co);
+	}
+
+	t00= co3[0]-co1[0];
+	t01= co3[1]-co1[1];
+	t02= co3[2]-co1[2];
+	t10= co3[0]-co2[0];
+	t11= co3[1]-co2[1];
+	t12= co3[2]-co2[2];
+	
+	x0= t11*r2-t12*r1;
+	x1= t12*r0-t10*r2;
+	x2= t10*r1-t11*r0;
+
+	divdet= t00*x0+t01*x1+t02*x2;
+
+	m0= rx1-co3[0];
+	m1= ry1-co3[1];
+	m2= rz1-co3[2];
+	det1= m0*x0+m1*x1+m2*x2;
+	
+	if(divdet!=0.0f) {
+		u1= det1/divdet;
+
+		if(u1<ISECT_EPSILON) {
+			det= t00*(m1*r2-m2*r1);
+			det+= t01*(m2*r0-m0*r2);
+			det+= t02*(m0*r1-m1*r0);
+			v= det/divdet;
+
+			if(v<ISECT_EPSILON && (u1 + v) > -(1.0f+ISECT_EPSILON)) {
+				return 1;
+			}
+		}
+	}
+
+	if(face->v4) {
+
+		t20= co3[0]-co4[0];
+		t21= co3[1]-co4[1];
+		t22= co3[2]-co4[2];
+
+		divdet= t20*x0+t21*x1+t22*x2;
+		if(divdet!=0.0f) {
+			u2= det1/divdet;
+		
+			if(u2<ISECT_EPSILON) {
+				det= t20*(m1*r2-m2*r1);
+				det+= t21*(m2*r0-m0*r2);
+				det+= t22*(m0*r1-m1*r0);
+				v= det/divdet;
+	
+				if(v<ISECT_EPSILON && (u2 + v) >= -(1.0f+ISECT_EPSILON)) {
+					return 2;
+				}
+			}
+		}
+	}
+	return 0;
+}
+
+static int vlr_check_intersect(Isect *is, ObjectInstanceRen *obi, VlakRen *vlr)
+{
+	/* for baking selected to active non-traceable materials might still
+	 * be in the raytree */
+	if(!(vlr->mat->mode & MA_TRACEBLE))
+		return 0;
+
+	/* I know... cpu cycle waste, might do smarter once */
+	if(is->mode==RE_RAY_MIRROR)
+		return !(vlr->mat->mode & MA_ONLYCAST);
+	else
+		return (is->lay & obi->lay);
+}
+
+static int vlr_check_intersect_solid(Isect *is, ObjectInstanceRen* obi, VlakRen *vlr)
+{
+	/* solid material types only */
+	if (vlr->mat->material_type == MA_TYPE_SURFACE)
+		return 1;
+	else
+		return 0;
+}
+
+static int rayface_check_cullface(RayFace *face, Isect *is)
+{
+	float nor[3];
+	
+	/* don't intersect if the ray faces along the face normal */
+	if(face->quad) CalcNormFloat4(face->v1, face->v2, face->v3, face->v4, nor);
+	else CalcNormFloat(face->v1, face->v2, face->v3, nor);
+
+	return (INPR(nor, is->vec) < 0);
+}
+
+/* ray - triangle or quad intersection */
+/* this function shall only modify Isect if it detects an hit */
+static int intersect_rayface(RayObject *hit_obj, RayFace *face, Isect *is)
+{

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list