00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 #if defined(_MSC_VER)
00025 #pragma once
00026 #endif
00027 
00028 #ifndef PBRT_TEXTURES_MARBLE_H
00029 #define PBRT_TEXTURES_MARBLE_H
00030 
00031 
00032 #include "pbrt.h"
00033 #include "texture.h"
00034 #include "paramset.h"
00035 
00036 
00037 class MarbleTexture : public Texture<Spectrum> {
00038 public:
00039     
00040     ~MarbleTexture() {
00041         delete mapping;
00042     }
00043     MarbleTexture(int oct, float roughness, float sc, float var,
00044                   TextureMapping3D *map)
00045         : octaves(oct), omega(roughness), scale(sc), variation(var),
00046           mapping(map) { }
00047     Spectrum Evaluate(const DifferentialGeometry &dg) const {
00048         Vector dpdx, dpdy;
00049         Point P = mapping->Map(dg, &dpdx, &dpdy);
00050         P *= scale;
00051         float marble = P.y + variation *
00052                        FBm(P, scale * dpdx, scale * dpdy, omega, octaves);
00053         float t = .5f + .5f * sinf(marble);
00054         
00055         static float c[][3] = { { .58f, .58f, .6f }, { .58f, .58f, .6f }, { .58f, .58f, .6f },
00056             { .5f, .5f, .5f }, { .6f, .59f, .58f }, { .58f, .58f, .6f },
00057             { .58f, .58f, .6f }, {.2f, .2f, .33f }, { .58f, .58f, .6f }, };
00058 #define NC  sizeof(c) / sizeof(c[0])
00059 #define NSEG (NC-3)
00060         int first = Floor2Int(t * NSEG);
00061         t = (t * NSEG - first);
00062         Spectrum c0 = Spectrum::FromRGB(c[first]);
00063         Spectrum c1 = Spectrum::FromRGB(c[first+1]);
00064         Spectrum c2 = Spectrum::FromRGB(c[first+2]);
00065         Spectrum c3 = Spectrum::FromRGB(c[first+3]);
00066         
00067         Spectrum s0 = (1.f - t) * c0 + t * c1;
00068         Spectrum s1 = (1.f - t) * c1 + t * c2;
00069         Spectrum s2 = (1.f - t) * c2 + t * c3;
00070         s0 = (1.f - t) * s0 + t * s1;
00071         s1 = (1.f - t) * s1 + t * s2;
00072         
00073         return 1.5f * ((1.f - t) * s0 + t * s1);
00074     }
00075 private:
00076     
00077     int octaves;
00078     float omega, scale, variation;
00079     TextureMapping3D *mapping;
00080 };
00081 
00082 
00083 Texture<float> *CreateMarbleFloatTexture(const Transform &tex2world,
00084         const TextureParams &tp);
00085 MarbleTexture *CreateMarbleSpectrumTexture(const Transform &tex2world,
00086         const TextureParams &tp);
00087 
00088 #endif // PBRT_TEXTURES_MARBLE_H