Text archives Help
- From: aek@sci.utah.edu
- To: rtrt@sci.utah.edu
- Subject: [MANTA] r296 - in trunk: Model/Textures scenes
- Date: Thu, 12 May 2005 15:20:44 -0600 (MDT)
Author: aek
Date: Thu May 12 15:20:44 2005
New Revision: 296
Added:
trunk/Model/Textures/OakTexture.cc
trunk/Model/Textures/OakTexture.h
Modified:
trunk/scenes/primtest.cc
Log:
* Added "OakTexture", a better procedural wood texture ported from the
"Advanced Renderman" wood shader. Added to primtest with "-material oak"
option.
* Changed primtest so that a material may require a TexCoordMapper to
override the primitive default. This lets solid procedural textures
appear in the correct shading space.
Added: trunk/Model/Textures/OakTexture.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Textures/OakTexture.cc Thu May 12 15:20:44 2005
@@ -0,0 +1,88 @@
+
+#include <Model/Textures/OakTexture.h>
+#include <Interface/RayPacket.h>
+#include <Core/Geometry/Point.h>
+#include <Core/Geometry/Vector.h>
+#include <Core/Math/Noise.h>
+#include <Core/Math/MiscMath.h>
+
+namespace Manta {
+
+ template< class ValueType >
+ OakTexture< ValueType >::OakTexture(
+ ValueType const &value1,
+ ValueType const &value2,
+ double const ringfreq,
+ double const ringunevenness,
+ double const grainfreq,
+ double const ringnoise,
+ double const ringnoisefreq,
+ double const trunkwobble,
+ double const trunkwobblefreq,
+ double const angularwobble,
+ double const angularwobblefreq,
+ double const ringy,
+ double const grainy )
+ : value1( value1 ),
+ value2( value2 ),
+ ringfreq( ringfreq ),
+ ringunevenness( ringunevenness ),
+ grainfreq( grainfreq ),
+ ringnoise( ringnoise ),
+ ringnoisefreq( ringnoisefreq ),
+ trunkwobble( trunkwobble ),
+ trunkwobblefreq( trunkwobblefreq ),
+ angularwobble( angularwobble ),
+ angularwobblefreq( angularwobblefreq ),
+ ringy( ringy ),
+ grainy( grainy )
+ {
+ }
+
+ template< class ValueType >
+ OakTexture< ValueType >::~OakTexture()
+ {
+ }
+
+ template< class ValueType >
+ void OakTexture< ValueType >::mapValues(
+ RenderContext const &context,
+ RayPacket &rays,
+ ValueType results[] ) const
+ {
+ rays.computeTextureCoordinates3( context );
+ for( int i = 0; i < rays.getSize(); i++ ) {
+ RayPacket::Element &e = rays.get( i );
+
+ Vector offset = VectorFBM( e.texCoords * ringnoisefreq, 2, 4.0, 0.5 );
+ Point Pring = e.texCoords + ringnoise * offset;
+ Vector vsnoise = VectorNoise( Point( 0.5, 0.5, e.texCoords.z() *
trunkwobblefreq ) );
+ Pring += Vector( trunkwobble * vsnoise.x(), trunkwobble * vsnoise.y(),
0.0 );
+ double r = sqrt( Pring.x() * Pring.x() + Pring.y() * Pring.y() ) *
ringfreq;
+ r += angularwobble * SmoothStep( r, 0, 5 ) * ScalarNoise( Point(
angularwobble * Pring.x(),
+
angularwobble * Pring.y(),
+
angularwobble * Pring.z() * 0.1 ) );
+ r += 0.5 * ScalarNoise( Point( 0.5, 0.5, r ) );
+ double rfrac = r - floor( r );
+ double inring = SmoothStep( rfrac, 0.1, 0.55 ) - SmoothStep( rfrac,
0.7, 0.95 );
+ Point Pgrain = Point( e.texCoords.x() * grainfreq, e.texCoords.y() *
grainfreq, e.texCoords.z() * grainfreq * 0.05 );
+ double grain = 0.0;
+ double amp = 1.0;
+ for ( int it = 0; it < 2; ++it )
+ {
+ double g = 0.8 * ScalarNoise( Pgrain );
+ g *= ( 0.3 + 0.7 * inring );
+ g = Clamp( 0.8 - g, 0.0, 1.0 );
+ g = grainy * SmoothStep( g * g, 0.5, 1.0 );
+ if ( it == 0 )
+ inring *= 0.7;
+ grain = max( grain, g );
+ Pgrain *= 2.0;
+ amp *= 0.5;
+ }
+ double value = Interpolate( 1.0, grain, inring * ringy );
+ results[ i ] = Interpolate( value2, value1, value );
+ }
+ }
+
+}
Added: trunk/Model/Textures/OakTexture.h
==============================================================================
--- (empty file)
+++ trunk/Model/Textures/OakTexture.h Thu May 12 15:20:44 2005
@@ -0,0 +1,59 @@
+
+#ifndef Manta_Model_OakTexture_h
+#define Manta_Model_OakTexture_h
+
+#include <Interface/Texture.h>
+
+namespace Manta {
+ class RayPacket;
+ class RenderContext;
+ template< typename ValueType >
+ class OakTexture : public Texture< ValueType > {
+ public:
+ OakTexture(
+ ValueType const &value1,
+ ValueType const &value2,
+ double const ringfreq,
+ double const ringunevenness,
+ double const grainfreq,
+ double const ringnoise,
+ double const ringnoisefreq,
+ double const trunkwobble,
+ double const trunkwobblefreq,
+ double const angularwobble,
+ double const angularwobblefreq,
+ double const ringy,
+ double const grainy );
+ virtual ~OakTexture();
+ virtual void mapValues(
+ RenderContext const &context,
+ RayPacket &rays,
+ ValueType results[] ) const;
+ private:
+ OakTexture(
+ OakTexture const & );
+ OakTexture& operator=(
+ OakTexture const & );
+
+ ValueType value1;
+ ValueType value2;
+ double const ringfreq;
+ double const ringunevenness;
+ double const grainfreq;
+ double const ringnoise;
+ double const ringnoisefreq;
+ double const trunkwobble;
+ double const trunkwobblefreq;
+ double const angularwobble;
+ double const angularwobblefreq;
+ double const ringy;
+ double const grainy;
+ };
+}
+
+#ifdef __GNUG__
+// This should instead be a configure variable...
+#include <Model/Textures/OakTexture.cc>
+#endif
+
+#endif
Modified: trunk/scenes/primtest.cc
==============================================================================
--- trunk/scenes/primtest.cc (original)
+++ trunk/scenes/primtest.cc Thu May 12 15:20:44 2005
@@ -26,10 +26,12 @@
#include <Model/Primitives/SuperEllipsoid.h>
#include <Model/TexCoordMappers/LinearMapper.h>
#include <Model/TexCoordMappers/SphericalMapper.h>
+#include <Model/TexCoordMappers/UniformMapper.h>
#include <Model/Textures/Constant.h>
#include <Model/Textures/CheckerTexture.h>
#include <Model/Textures/MarbleTexture.h>
#include <Model/Textures/WoodTexture.h>
+#include <Model/Textures/OakTexture.h>
#include <Core/Math/MinMax.h>
#include <sgi_stl_warnings_off.h>
#include <string>
@@ -40,11 +42,11 @@
using namespace Manta;
using namespace std;
-extern "C"
+extern "C"
Scene* make_scene(const ReadContext&, const vector<string>& args)
{
std::cout << "Make_scene args: " << args.size() << std::endl;
-
+
double scale = 1;
double texscale = 20;
int numx = 8;
@@ -87,6 +89,7 @@
Group* group = new Group();
Material* matl;
+ TexCoordMapper* mapr = 0;
int max = Max(numx, numy);
if(material == "redphong")
matl=new Phong(Color(RGB(.6,0,0)), Color(RGB(.6,.6,.6)), 32, 0.4);
@@ -117,20 +120,35 @@
new Phong(Color(RGB(.6,0,0)), Color(RGB(.6,.6,.6)),
32, 0.5),
Vector(1,0,0)*texscale, Vector(0,1,0)*texscale);
else if(material == "marble")
+ {
matl = new Phong(
new MarbleTexture<Color>(
Color(RGB(0.1,0.2,0.5)), Color(RGB(0.7,0.8,1.0)),
- 10.0, 1.0, 15.0, 6, 2.0, 0.6 ),
+ 10.0, 1.0, 15.0, 6, 2.0, 0.6 ),
new Constant<Color>(Color(RGB(.6,.6,.6))),
32,
new Constant<double>(0));
+ mapr = new UniformMapper();
+ }
else if(material == "wood")
+ {
matl = new Lambertian(
new WoodTexture<Color>(
- Color(RGB(0.32,0.25,0.21)), Color(RGB(0.41,0.35,0.3)),
+ Color(RGB(0.32,0.25,0.21)), Color(RGB(0.41,0.35,0.3)),
12.0, 20.0, 5.0, 5.0, 6, 2.0, 0.6 ) );
+ mapr = new UniformMapper();
+ }
+ else if(material == "oak")
+ {
+ matl = new Lambertian(
+ new OakTexture<Color>(
+ Color(RGB(0.15,0.077,0.028)), Color(RGB(0.5,0.2,0.067)),
+ 64.0, 0.5, 200.0, 0.02, 1.0, 0.3, 0.4, 1.0, 2.0, 1.0, 0.4 ) );
+ mapr = new UniformMapper();
+ }
else
throw IllegalArgument("Unknown material type for primtest: "+material,
0, args);
+
Object* spinprim = 0;
if(primtype == "simplesphere"){
for(int i=0;i<numx;i++){
@@ -140,7 +158,10 @@
Point p((i/static_cast<double>(numx-1) - 0.5)*scale*2,
(j/static_cast<double>(numy-1) - 0.5)*scale*2,
0);
- group->add(new Sphere(matl, p, radius));
+ Primitive* prim = new Sphere( matl, p, radius );
+ if ( mapr )
+ prim->setTexCoordMapper( mapr );
+ group->add( prim );
}
}
} else if (primtype == "simplesuperellipsoid"){
@@ -153,7 +174,10 @@
Point p((i/static_cast<double>(numx-1) - 0.5)*scale*2,
(j/static_cast<double>(numy-1) - 0.5)*scale*2,
0);
- group->add(new SuperEllipsoid(matl, p, radius, alpha, beta));
+ Primitive* prim = new SuperEllipsoid( matl, p, radius, alpha, beta );
+ if ( mapr )
+ prim->setTexCoordMapper( mapr );
+ group->add( prim );
}
}
} else if(primtype == "simplebox"){
@@ -163,21 +187,30 @@
Point p((i/static_cast<double>(numx-1) - 0.5)*scale*2,
(j/static_cast<double>(numy-1) - 0.5)*scale*2,
0);
- group->add(new Cube(matl, p-p2, p2.x()*1.156, p2.y()*1.156,
p2.z()*1.156));
+ Primitive* prim = new Cube( matl, p-p2, p2.x()*1.156, p2.y()*1.156,
p2.z()*1.156 );
+ if ( mapr )
+ prim->setTexCoordMapper( mapr );
+ group->add( prim );
}
}
} else if(primtype == "sphere"){
- spinprim = new Sphere(matl, Point(0,0,0), scale/max);
+ Primitive* prim = new Sphere(matl, Point(0,0,0), scale/max);
+ if ( mapr )
+ prim->setTexCoordMapper( mapr );
+ spinprim = prim;
} else if(primtype == "box"){
Point p2(scale/max/1.732, scale/max/1.732, scale/max/1.732);
- spinprim = new Cube(matl, -p2, p2.x()*2, p2.y()*2, p2.z()*2);
+ Primitive* prim = new Cube(matl, -p2, p2.x()*2, p2.y()*2, p2.z()*2);
+ if ( mapr )
+ prim->setTexCoordMapper( mapr );
+ spinprim = prim;
} else if(primtype == "intersection"){
Point p2(scale/max/1.414, scale/max/1.414, scale/max/1.414);
Primitive* o1 = new Cube(matl, -p2, p2.x()*2, p2.y()*2, p2.z()*2);
Primitive* o2 = new Sphere(matl, Point(0,0,0), scale/max);
SphericalMapper* map = new SphericalMapper(Point(0,0,0), scale/max);
- o1->setTexCoordMapper(map);
- o2->setTexCoordMapper(map);
+ o1->setTexCoordMapper( mapr ? mapr : map );
+ o2->setTexCoordMapper( mapr ? mapr : map );
spinprim = new Intersection(o1, o2);
} else if(primtype == "difference"){
Point p2(scale/max/1.414, scale/max/1.414, scale/max/1.414);
@@ -188,13 +221,19 @@
Vector(s,0,0),
Vector(0,s,0),
Vector(0,0,s));
- o1->setTexCoordMapper(map);
- o2->setTexCoordMapper(map);
+ o1->setTexCoordMapper( mapr ? mapr : map );
+ o2->setTexCoordMapper( mapr ? mapr : map );
spinprim = new Difference(o1, o2);
} else if (primtype == "disk") {
- spinprim = new Disk(matl, Point(0.0, 0.0, 0.0), Vector(0.0, 0.0, 1.0),
scale / max, Vector(1.0, 0.0, 0.0), 0.25 * M_PI, 1.75 * M_PI);
+ Primitive* prim = new Disk(matl, Point(0.0, 0.0, 0.0), Vector(0.0, 0.0,
1.0), scale / max, Vector(1.0, 0.0, 0.0), 0.25 * M_PI, 1.75 * M_PI);
+ if ( mapr )
+ prim->setTexCoordMapper( mapr );
+ spinprim = prim;
} else if (primtype == "hemisphere") {
- spinprim = new Hemisphere(matl, Point(0.0, 0.0, 0.0), scale / max,
Vector(0.0, 0.0, 1.0));
+ Primitive* prim = new Hemisphere(matl, Point(0.0, 0.0, 0.0), scale /
max, Vector(0.0, 0.0, 1.0));
+ if ( mapr )
+ prim->setTexCoordMapper( mapr );
+ spinprim = prim;
} else {
throw IllegalArgument("Unknown primitive type for primtest: "+primtype,
0, args);
}
@@ -291,7 +330,7 @@
Color(RGB(0.2, 0.2, 0.2)),
Vector(1,0,0)*numx*2,
Vector(0,1,0)*numy*2));
-
+
group->add(new Parallelogram(bgmatl, Point(-scale-1./max, -scale-1./max,
-1.5/max),
Vector(scale*2+2./max, 0, 0), Vector(0,
scale*2+2./max, 0)));
}
- [MANTA] r296 - in trunk: Model/Textures scenes, aek, 05/12/2005
Archive powered by MHonArc 2.6.16.