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