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