Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 508)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 511)
@@ -692,4 +692,6 @@
 	int mMaxPvs;
 
+	int mMaxPvsRatio;
+
 	/// View cell corresponding to the space outside the valid view space
 	BspViewCell *mOutOfBoundsCell;
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Beam.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Beam.cpp	(revision 510)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Beam.cpp	(revision 511)
@@ -1,10 +1,9 @@
+#include "VssRay.h"
 #include "Beam.h"
-#include "VssRay.h"
-
 
 
 
 void
-Beam::Construct(const  AxisAlignedBox3 &box,
+MyBeam::Construct(const  AxisAlignedBox3 &box,
 				const  AxisAlignedBox3 &dBox)
 {
@@ -54,5 +53,5 @@
 
 int
-Beam::ComputeIntersection(const  AxisAlignedBox3 &box)
+MyBeam::ComputeIntersection(const AxisAlignedBox3 &box)
 {
   int i;
Index: trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.h	(revision 507)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.h	(revision 511)
@@ -22,5 +22,9 @@
 #include "AxisAlignedBox3.h"
 #include "Halton.h"
-#include "beam.h"
+#include "Beam.h"
+#include "Statistics.h"
+#include "Ray.h"
+
+#include "Containers.h"
 
 #define USE_KDNODE_VECTORS 1
@@ -29,8 +33,4 @@
 
 
-#include "Statistics.h"
-#include "Ray.h"
-
-#include "Containers.h"
 // --------------------------------------------------------------
 // Static statistics for kd-tree search
@@ -420,5 +420,5 @@
   HaltonSequence halton;
 
-  Beam mBeam;
+  MyBeam mBeam;
   
   RssTreeLeaf(RssTreeInterior *p,
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 509)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 511)
@@ -87,5 +87,6 @@
 	environment->GetBoolValue("VspBspTree.splitUseOnlyDrivingAxis", mOnlyDrivingAxis);
 	environment->GetBoolValue("VspBspTree.PostProcess.useRaysForMerge", mUseRaysForMerge);
-	environment->GetIntValue("ViewCells.maxPvs", mMaxPvs);
+
+	environment->GetIntValue("ViewCells.pvsInvalid", mMaxPvsRatio);
 
 	//-- termination criteria for axis aligned split
@@ -275,4 +276,5 @@
 	Intersectable::NewMail();
 
+	int numObj = 0;
 	//-- extract polygons intersected by the rays
 	for (rit = sampleRays.begin(); rit != rit_end; ++ rit)
@@ -287,4 +289,5 @@
 			MeshInstance *obj = dynamic_cast<MeshInstance *>(ray->mTerminationObject);
 			AddMeshToPolygons(obj->GetMesh(), polys, obj);
+			++ numObj;
 			//-- compute bounding box
 			if (!forcedBoundingBox)
@@ -299,4 +302,6 @@
 			MeshInstance *obj = dynamic_cast<MeshInstance *>(ray->mOriginObject);
 			AddMeshToPolygons(obj->GetMesh(), polys, obj);
+			++ numObj;
+
 			//-- compute bounding box
 			if (!forcedBoundingBox)
@@ -305,6 +310,5 @@
 	}
 
-	//-- compute bounding box
-	//if (!forcedBoundingBox) Polygon3::IncludeInBox(polys, mBox);
+	mMaxPvs = (int)(mMaxPvsRatio * (float)numObj);
 
 	//-- store rays
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 508)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 511)
@@ -1229,8 +1229,8 @@
 			"0");
 
-	RegisterOption("ViewCells.maxPvs",
-					optInt,
-					"view_cells_max_pvs=",
-					"300");
+	RegisterOption("ViewCells.maxPvsRatio",
+					optFloat,
+					"view_cells_max_pvs_ratio=",
+					"0.1");
 
 	RegisterOption("ViewCells.filename",
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Beam.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Beam.h	(revision 507)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Beam.h	(revision 511)
@@ -3,11 +3,12 @@
 
 #include <vector>
+#include "AxisAlignedBox3.h"
+
 using namespace std;
 
 class KdNode;
 class Intersectable;
-#include "AxisAlignedBox3.h"
 
-class Beam {
+class MyBeam {
   
 public:			
@@ -28,18 +29,18 @@
   vector<Plane3> mPlanes;
 
+    
+  void Construct(const AxisAlignedBox3 &box,
+	  const AxisAlignedBox3 &dBox);
+  
+  
+  int
+	  ComputeIntersection(const AxisAlignedBox3 &box);
+
   bool IsValid() { return mFlags & VALID; }
   bool SetValid() { return mFlags |= VALID; }
 
-  Beam():mFlags(STORE_KD_NODES+STORE_OBJECTS),mKdNodes(0), mObjects(0)
+  MyBeam():mFlags(STORE_KD_NODES+STORE_OBJECTS), mKdNodes(0), mObjects(0)
   {
   }
-  
-  void Construct(const  AxisAlignedBox3 &box,
-				 const  AxisAlignedBox3 &dBox);
-  
-  
-  int
-  ComputeIntersection(const  AxisAlignedBox3 &box);
-
   
 };
Index: trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp	(revision 507)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp	(revision 511)
@@ -968,5 +968,5 @@
 int
 KdTree::CastBeam(
-				 Beam &beam
+				 MyBeam &beam
 				 )
 {
Index: trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.h	(revision 505)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.h	(revision 511)
@@ -16,5 +16,5 @@
 class Intersectable;
 //class KdViewCell;
-class Beam;
+class MyBeam;
 
 // --------------------------------------------------------------
@@ -289,5 +289,5 @@
   int
   CastBeam(
-		   Beam &beam
+		   MyBeam &beam
 		   );
   
Index: trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h	(revision 507)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h	(revision 511)
@@ -17,5 +17,5 @@
 class Intersectable;
 class Material;
-class Beam;
+class MyBeam;
 
 struct PvsRenderStatistics {
@@ -159,5 +159,5 @@
   void SampleBeamContributions(
 							   Intersectable *sourceObject,
-							   Beam &beam,
+							   MyBeam &beam,
 							   const int samples,
 							   BeamSampleStatistics &stat
@@ -167,5 +167,5 @@
   SampleViewpointContributions(
 							   Intersectable *sourceObject,
-							   Beam &beam,
+							   MyBeam &beam,
 							   const int desiredSamples,
 							   BeamSampleStatistics &stat
Index: trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp	(revision 507)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp	(revision 511)
@@ -5,5 +5,5 @@
 #include "Pvs.h"
 #include "Viewcell.h"
-#include "Beam.cpp"
+#include "Beam.h"
 
 #include <GL/glext.h>
@@ -118,4 +118,19 @@
   glGetOcclusionQueryuivNV = (PFNGLGETOCCLUSIONQUERYUIVNVPROC)
 	wglGetProcAddress("glGetOcclusionQueryuivNV");
+
+  // second depth buffer texture
+  GLuint shadowMap;
+  const int shadowMapSize=512;
+ 
+
+  glGenTextures(1, &shadowMap);
+  glBindTexture(GL_TEXTURE_2D, shadowMap);
+  
+  glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapSize, 
+	  shadowMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
 }
 
@@ -535,5 +550,5 @@
 GlRendererBuffer::SampleBeamContributions(
 										  Intersectable *sourceObject,
-										  Beam &beam,
+										  MyBeam &beam,
 										  const int desiredSamples,
 										  BeamSampleStatistics &stat
@@ -589,5 +604,5 @@
 GlRendererBuffer::SampleViewpointContributions(
 											   Intersectable *sourceObject,
-											   Beam &beam,
+											   MyBeam &beam,
 											   const int desiredSamples,
 											   BeamSampleStatistics &stat
