Text archives Help
- From: leenak@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1617 - in trunk: Interface Model/Materials SwigInterface
- Date: Thu, 9 Aug 2007 15:37:54 -0600 (MDT)
Author: leenak
Date: Thu Aug 9 15:37:53 2007
New Revision: 1617
Added:
trunk/Model/Materials/OrenNayar.cc
trunk/Model/Materials/OrenNayar.h
Modified:
trunk/Interface/RayPacket.cc
trunk/Interface/RayPacket.h
trunk/Model/Materials/CMakeLists.txt
trunk/SwigInterface/manta.i
Log:
Oren Nayar Material classes are added to Manta
Modified: trunk/Interface/RayPacket.cc
==============================================================================
--- trunk/Interface/RayPacket.cc (original)
+++ trunk/Interface/RayPacket.cc Thu Aug 9 15:37:53 2007
@@ -182,12 +182,15 @@
for(int i = rayBegin; i < rayEnd; ++i) {
// Compute the dot product
Vector normal(getNormal(i));
- Real side = Dot(normal, getDirection(i));
- if (side <= 0)
+ side[i] = Dot(normal, getDirection(i));
+ data->side[i]=side[i];
+ if (side[i] <= 0)
setFFNormal(i, normal);
- else
+ else {
setFFNormal(i, -normal);
-
+ side[i]=-side[i];
+ data->side[i]=side[i];
+ }
}
flags |= HaveFFNormals;
Modified: trunk/Interface/RayPacket.h
==============================================================================
--- trunk/Interface/RayPacket.h (original)
+++ trunk/Interface/RayPacket.h Thu Aug 9 15:37:53 2007
@@ -97,6 +97,7 @@
MANTA_ALIGN(16) Real direction[3][MaxSize];
MANTA_ALIGN(16) Real inverseDirection[3][MaxSize];
MANTA_ALIGN(16) Real minT[MaxSize];
+ MANTA_ALIGN(16) Real side[MaxSize]; //To store dot product values
MANTA_ALIGN(16) Real image[2][MaxSize];
MANTA_ALIGN(16) Real normal[3][MaxSize];
@@ -820,6 +821,7 @@
int rayEnd;
int depth;
int flags;
+ Real side[MaxSize]; //To store dot product values
};
typedef MANTA_ALIGN(16) Color::ComponentType
ColorArray[Color::NumComponents][RayPacket::MaxSize];
Modified: trunk/Model/Materials/CMakeLists.txt
==============================================================================
--- trunk/Model/Materials/CMakeLists.txt (original)
+++ trunk/Model/Materials/CMakeLists.txt Thu Aug 9 15:37:53 2007
@@ -12,6 +12,8 @@
Materials/Flat.cc
Materials/Lambertian.h
Materials/Lambertian.cc
+ Materials/OrenNayar.h
+ Materials/OrenNayar.cc
Materials/LitMaterial.h
Materials/LitMaterial.cc
Materials/MaterialTable.h
Added: trunk/Model/Materials/OrenNayar.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Materials/OrenNayar.cc Thu Aug 9 15:37:53 2007
@@ -0,0 +1,133 @@
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2005-2006
+ Scientific Computing and Imaging Institute, University of Utah
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#include <Model/Materials/OrenNayar.h>
+#include <Interface/Light.h>
+#include <Interface/LightSet.h>
+#include <Interface/Primitive.h>
+#include <Interface/RayPacket.h>
+#include <Interface/AmbientLight.h>
+#include <Interface/Context.h>
+#include <Interface/ShadowAlgorithm.h>
+#include <Model/Textures/Constant.h>
+#include <iostream>
+#include <math.h>
+#include <SCIRun/Core/Math/MinMax.h>
+using namespace Manta;
+using std::cerr;
+
+OrenNayar::OrenNayar(const Color& color, const Real sigma)
+{
+ Real sigma_sqr=sigma*sigma;
+ colortex = new Constant<Color>(color);
+ a=1-sigma_sqr/(2*(sigma_sqr+0.33));
+ b=(0.45*sigma_sqr)/(sigma_sqr+0.09);
+}
+
+OrenNayar::OrenNayar(const Texture<Color>* colortex)
+ : colortex(colortex)
+{
+}
+
+OrenNayar::~OrenNayar()
+{
+}
+
+void OrenNayar::shade(const RenderContext& context, RayPacket& rays) const
+{
+ int debugFlag = rays.getAllFlags() & RayPacket::DebugPacket;
+ if (debugFlag) {
+ cerr << "OrenNayar::shade called (rays["<<rays.begin()<<",
"<<rays.end()<<"])\n";
+ // cerr << SCIRun::getStackTrace();
+ }
+ // Shade a bunch of rays. We know that they all have the same intersected
+ // object and are all of the same material
+
+ // We normalized directions for proper dot product computation.
+ rays.normalizeDirections();
+
+ // Compute colors
+ Packet<Color> diffuse;
+ colortex->mapValues(diffuse, context, rays);
+
+ // Compute normals
+
+ rays.computeFFNormals(context);
+ Real* cos_theta=rays.side; //To store dot product values
+
+ // Compute ambient contributions for all rays
+ MANTA_ALIGN(16) ColorArray totalLight;
+ activeLights->getAmbientLight()->computeAmbient(context, rays, totalLight);
+
+ ShadowAlgorithm::StateBuffer shadowState;
+ do {
+ RayPacketData shadowData;
+ RayPacket shadowRays(shadowData, RayPacket::UnknownShape, 0, 0,
rays.getDepth(), debugFlag);
+
+ // Call the shadowalgorithm(sa) to generate shadow rays. We may not be
+ // able to compute all of them, so we pass along a buffer for the sa
+ // object to store it's state.
+ context.shadowAlgorithm->computeShadows(context, shadowState,
activeLights,
+ rays, shadowRays);
+
+ // We need normalized directions for proper dot product computation.
+ shadowRays.normalizeDirections();
+
+ for(int i=shadowRays.begin(); i < shadowRays.end(); i++){
+ if(!shadowRays.wasHit(i)){
+ // Not in shadow, so compute the direct lighting contributions.
+ Vector normal = rays.getFFNormal(i);
+ Vector shadowdir = shadowRays.getDirection(i);
+ ColorComponent cos_phi = Dot(shadowdir, normal);
+ Color light = shadowRays.getColor(i);
+ Real theta=acos(cos_theta[i]);
+ Real phi=acos(cos_phi);
+
+ Real alpha, beta;
+ (theta > phi)? alpha = theta : alpha = phi;
+ (theta < phi)? beta = theta : beta = phi;
+
+ Real max_value;
+ (0 < cos(theta-phi))? max_value = cos(theta-phi) : max_value
= 0;
+
+ for(int k = 0; k < Color::NumComponents;k++)
+ totalLight[k][i] +=
light[k]*(0.6*cos_phi)*(a+b*max_value*sin(alpha)*tan(beta));
+ }
+ }
+ } while(!shadowState.done());
+
+
+ for(int i = rays.begin(); i < rays.end(); i++){
+ Color result;
+ for(int j=0;j<Color::NumComponents;j++)
+ result[j] = totalLight[j][i] * diffuse.colordata[j][i];
+ rays.setColor(i, result);
+ }
+
+
+}
Added: trunk/Model/Materials/OrenNayar.h
==============================================================================
--- (empty file)
+++ trunk/Model/Materials/OrenNayar.h Thu Aug 9 15:37:53 2007
@@ -0,0 +1,63 @@
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2005-2006
+ Scientific Computing and Imaging Institute, University of Utah
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+/*
+ * Coded by Leena Kora
+ * on 08/07/2007
+ *
+ * This material class is for rough surfaced objects.
+ * This class takes two arguments one for primary color and other argument
for providing surface roughness(0-1)
+ */
+
+
+#ifndef Manta_Model_OrenNayar_h
+#define Manta_Model_OrenNayar_h
+
+#include <Model/Materials/LitMaterial.h>
+#include <Core/Color/Color.h>
+#include <Interface/Texture.h>
+
+namespace Manta{
+ class LightSet;
+
+ class OrenNayar : public LitMaterial {
+ public:
+ OrenNayar(const Color& color, const Real sigma);
+ OrenNayar(const Texture<Color>* colorfn);
+ OrenNayar() { };
+ virtual ~OrenNayar();
+
+ virtual void shade(const RenderContext& context, RayPacket& rays) const;
+ private:
+ Real a, b;
+ const Texture<Color>* colortex;
+
+ };
+}
+
+#endif
Modified: trunk/SwigInterface/manta.i
==============================================================================
--- trunk/SwigInterface/manta.i (original)
+++ trunk/SwigInterface/manta.i Thu Aug 9 15:37:53 2007
@@ -223,6 +223,7 @@
// #include <Model/Materials/LitMaterial.h>
#include <Model/Materials/Phong.h>
#include <Model/Materials/Lambertian.h>
+#include <Model/Materials/OrenNayar.h>
#include <Model/Materials/MetalMaterial.h>
#include <Model/Materials/Dielectric.h>
#include <Model/Materials/ThinDielectric.h>
@@ -243,6 +244,7 @@
// %include <Model/Materials/LitMaterial.h>
%include <Model/Materials/Phong.h>
%include <Model/Materials/Lambertian.h>
+%include <Model/Materials/OrenNayar.h>
%include <Model/Materials/MetalMaterial.h>
%include <Model/Materials/Dielectric.h>
%include <Model/Materials/ThinDielectric.h>
- [MANTA] r1617 - in trunk: Interface Model/Materials SwigInterface, leenak, 08/09/2007
Archive powered by MHonArc 2.6.16.