Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r672 - in trunk: Model/Materials scenes


Chronological Thread 
  • From: aek@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r672 - in trunk: Model/Materials scenes
  • Date: Thu, 27 Oct 2005 15:34:23 -0600 (MDT)

Author: aek
Date: Thu Oct 27 15:34:22 2005
New Revision: 672

Modified:
   trunk/Model/Materials/AmbientOcclusion.cc
   trunk/Model/Materials/AmbientOcclusion.h
   trunk/scenes/ParticleBVHTest.cc
Log:
Tweaked the AmbientOcclusion material.  It now computes a diffuse term as
well and respects light sources and shadows.



Modified: trunk/Model/Materials/AmbientOcclusion.cc
==============================================================================
--- trunk/Model/Materials/AmbientOcclusion.cc   (original)
+++ trunk/Model/Materials/AmbientOcclusion.cc   Thu Oct 27 15:34:22 2005
@@ -3,6 +3,7 @@
 #include <Interface/RayPacket.h>
 #include <Interface/Context.h>
 #include <Interface/Scene.h>
+#include <Interface/ShadowAlgorithm.h>
 #include <Model/Textures/Constant.h>
 #include <Core/Math/MT_RNG.h>
 #include <SCIRun/Core/Math/Trig.h>
@@ -15,13 +16,13 @@
 AmbientOcclusion::AmbientOcclusion(const Color& color, float cutoff_dist, 
int num_dirs)
 {
     colortex = new Constant<Color>(color);
-    cutoff_tex = new Constant<float>(cutoff_dist);
+    cutoff = cutoff_dist;
     num_directions = num_dirs;
     inv_num_directions = 1.f/float(num_directions);
     generateDirections();
 }
 
-AmbientOcclusion::AmbientOcclusion(const Texture<Color>* color, const 
Texture<float>* cutoff_dist, int num_dirs) : colortex(color), 
cutoff_tex(cutoff_dist), num_directions(num_dirs)
+AmbientOcclusion::AmbientOcclusion(const Texture<Color>* color, float 
cutoff_dist, int num_dirs) : colortex(color), cutoff(cutoff_dist), 
num_directions(num_dirs)
 {
     inv_num_directions = 1.f/float(num_directions);
     generateDirections();
@@ -62,62 +63,82 @@
 
     // Compute colors
     Color colors[RayPacket::MaxSize];
-    float dists[RayPacket::MaxSize];
     colortex->mapValues(context, rays, colors);
-    cutoff_tex->mapValues(context, rays, dists);
 
-    for (int i = 0; i < rays.getSize(); i++)
+    RayPacketData data;
+    int start = 0;
+    do
     {
-        // for each position, compute a local coordinate frame
-        // and build a set of rays to push into a ray packet
-        RayPacket::Element& e = rays.get(i);
-        Vector U,V,W; // surface ONB
-        W = e.normal;
-        W.normalize();
-        U = Cross(W, Vector(1,0,0));
-        double squared_length = U.length2();
-        if ( squared_length < 1e-6 )
+        RayPacket shadowRays(data, 0, rays.getDepth(), 0);
+        int end = context.shadowAlgorithm->computeShadows(context, 
activeLights,
+                                                          rays, start, 
shadowRays);
+        shadowRays.normalizeDirections();
+        for(int i=start;i<end;i++)
         {
-            U = Cross(W, Vector(0,1,0));
-            U.normalize();
-        }
-        else
-            U *= 1./sqrt(squared_length);
-        V = Cross(W, U);
-
-        int num_sent = 0;
-        float num_miss = 0.f;
-        while ( num_sent < num_directions )
-        {
-            int start = num_sent;
-            int end   = start + RayPacket::MaxSize;
-            if (end > num_directions) end = num_directions;
-
-            RayPacketData occlusion_data;
-            RayPacket occlusion_rays(occlusion_data, end-start, 
rays.getDepth(), RayPacket::NormalizedDirections | RayPacket::ConstantOrigin);
+            RayPacket::Element& e = rays.get(i);
 
-            for ( int r = start; r < end; r++ )
+            // for each position, compute a local coordinate frame
+            // and build a set of rays to push into a ray packet
+            Vector W(e.normal); // surface ONB
+            W.normalize();
+            Vector U(Cross(W, Vector(1,0,0)));
+            double squared_length = U.length2();
+            if ( squared_length < 1e-6 )
             {
-                RayPacket::Element& element = occlusion_rays.get(r-start);
-                Vector trans_dir = directions[r][0]*U + directions[r][1]*V + 
directions[r][2]*W;
-                element.ray.set(e.hitPosition, trans_dir);
-                // set max distance
-                element.hitInfo.reset(dists[i]);
+                U = Cross(W, Vector(0,1,0));
+                U.normalize();
             }
-            // packet is ready, test it for shadows
-            context.scene->getObject()->intersect(context, occlusion_rays);
-            // count the number of occluded ones
-            for (int r = start; r < end; r++ )
+            else
+                U *= 1./sqrt(squared_length);
+            Vector V(Cross(W, U));
+
+            // Send out the ambient occlusion tests
+            int num_sent = 0;
+            float num_miss = 0.f;
+            while ( num_sent < num_directions )
             {
-                RayPacket::Element& element = occlusion_rays.get(r-start);
-                if(!element.hitInfo.wasHit())
-                    num_miss+=1.0f;
+                int start = num_sent;
+                int end   = start + RayPacket::MaxSize;
+                if (end > num_directions) end = num_directions;
+
+                RayPacketData occlusion_data;
+                RayPacket occlusion_rays(occlusion_data, end-start, 
rays.getDepth(), RayPacket::NormalizedDirections | RayPacket::ConstantOrigin);
+
+                for ( int r = start; r < end; r++ )
+                {
+                    RayPacket::Element& element = 
occlusion_rays.get(r-start);
+                    Vector trans_dir = directions[r][0]*U + 
directions[r][1]*V + directions[r][2]*W;
+                    element.ray.set(e.hitPosition, trans_dir);
+                    // set max distance
+                    element.hitInfo.reset(cutoff);
+                }
+                // packet is ready, test it for occlusion
+                context.scene->getObject()->intersect(context, 
occlusion_rays);
+                // count the number of occluded ones
+                for (int r = start; r < end; r++ )
+                {
+                    RayPacket::Element& element = 
occlusion_rays.get(r-start);
+                    if(!element.hitInfo.wasHit())
+                        num_miss+=1.0f;
+                }
+                num_sent = end;
             }
-            num_sent = end;
-        }
 
-        // now we can shade our ray
-        *e.color = colors[i]*(num_miss*inv_num_directions);
-    }
+            // Test for shadows and diffuse lighting from regular light 
sources
+            Color totalLight(RGB(0,0,0));
+            for(int j=e.shadowBegin;j<e.shadowEnd;j++)
+            {
+                RayPacket::Element& s = shadowRays.get(j);
+                if(!s.hitInfo.wasHit())
+                {
+                    double cos_theta = Dot(s.ray.direction(), e.normal);
+                    totalLight += s.light*cos_theta;
+                }
+            }
+
+            rays.setResult(i, 
colors[i]*totalLight*0.6+colors[i]*(num_miss*inv_num_directions*0.4));
+        }
+        start = end;
+    } while(start < rays.getSize());
 
 }

Modified: trunk/Model/Materials/AmbientOcclusion.h
==============================================================================
--- trunk/Model/Materials/AmbientOcclusion.h    (original)
+++ trunk/Model/Materials/AmbientOcclusion.h    Thu Oct 27 15:34:22 2005
@@ -13,7 +13,7 @@
     {
     public:
         AmbientOcclusion(const Color& color, float cutoff_dist, int 
num_dirs);
-        AmbientOcclusion(const Texture<Color>* color, const Texture<float>* 
cutoff_dist, int num_dirs);
+        AmbientOcclusion(const Texture<Color>* color, float cutoff_dist, int 
num_dirs);
         AmbientOcclusion() {  }
         ~AmbientOcclusion();
 
@@ -23,7 +23,7 @@
         void shade(const RenderContext& context, RayPacket& rays) const;
     private:
         const Texture<Color>* colortex;
-        const Texture<float>* cutoff_tex;
+        float cutoff;
         Vector* directions;
         int num_directions;
         float inv_num_directions;

Modified: trunk/scenes/ParticleBVHTest.cc
==============================================================================
--- trunk/scenes/ParticleBVHTest.cc     (original)
+++ trunk/scenes/ParticleBVHTest.cc     Thu Oct 27 15:34:22 2005
@@ -1,5 +1,4 @@
 
-
 #include <Core/Exceptions/IllegalArgument.h>
 #include <Core/Util/Args.h>
 #include <Core/Math/MiscMath.h>
@@ -128,7 +127,7 @@
   ParticleBVH::ParticleTexture *texture = new ParticleBVH::ParticleTexture();
   Material *material = new Lambertian( texture );
   if ( occlusion_rays > 0 )
-      material = new AmbientOcclusion( texture, new Constant<float>( 0.01 ), 
occlusion_rays );
+      material = new AmbientOcclusion( texture, 0.01, occlusion_rays );
   ParticleBVH *bvh = new ParticleBVH( material, number_of_particles );
   texture->setParticleBVH( bvh );
   for ( int particle = 0; particle < number_of_particles; ++particle ) {
@@ -152,7 +151,7 @@
                                               Vector( 0.0, 1.0, 0.0 ) ) );
   scene->setObject( bvh );
   LightSet *lights = new LightSet();
-  lights->add( new PointLight( light_position, Color( RGB( 2.0, 2.0 , 2.0 ) 
) ) );
+  lights->add( new PointLight( light_position, Color( RGB( 1.0, 1.0 , 1.0 ) 
) ) );
   lights->setAmbientLight( new ArcAmbient( Color( RGB( 0.1, 0.3, 0.8 ) ),
                                            Color( RGB( 0.8, 0.6, 0.6 ) ),
                                            Vector( 0.0, 1.0, 0.0 ) ) );




  • [MANTA] r672 - in trunk: Model/Materials scenes, aek, 10/27/2005

Archive powered by MHonArc 2.6.16.

Top of page