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
00029
00030 namespace lux
00031 {
00032
00033
00034 class MarbleTexture : public Texture<SWCSpectrum> {
00035 public:
00036
00037 virtual ~MarbleTexture() {
00038 delete mapping;
00039 }
00040 MarbleTexture(int oct, float roughness, float sc, float var,
00041 TextureMapping3D *map) {
00042 omega = roughness;
00043 octaves = oct;
00044 mapping = map;
00045 scale = sc;
00046 variation = var;
00047 }
00048 virtual SWCSpectrum Evaluate(const TsPack *tspack, const DifferentialGeometry &dg) const {
00049 Vector dpdx, dpdy;
00050 Point P = mapping->Map(dg, &dpdx, &dpdy);
00051 P *= scale;
00052 float marble = P.y + variation * FBm(P, scale * dpdx,
00053 scale * dpdy, omega, octaves);
00054 float t = .5f + .5f * sinf(marble);
00055
00056 static float c[][3] = { { .58f, .58f, .6f }, { .58f, .58f, .6f }, { .58f, .58f, .6f },
00057 { .5f, .5f, .5f }, { .6f, .59f, .58f }, { .58f, .58f, .6f },
00058 { .58f, .58f, .6f }, {.2f, .2f, .33f }, { .58f, .58f, .6f }, };
00059 #define NC sizeof(c) / sizeof(c[0])
00060 #define NSEG (NC-3)
00061 int first = Floor2Int(t * NSEG);
00062 t = (t * NSEG - first);
00063 RGBColor c0(c[first]), c1(c[first+1]), c2(c[first+2]), c3(c[first+3]);
00064
00065 RGBColor s0 = (1.f - t) * c0 + t * c1;
00066 RGBColor s1 = (1.f - t) * c1 + t * c2;
00067 RGBColor s2 = (1.f - t) * c2 + t * c3;
00068 s0 = (1.f - t) * s0 + t * s1;
00069 s1 = (1.f - t) * s1 + t * s2;
00070
00071 return SWCSpectrum(tspack, 1.5f * ((1.f - t) * s0 + t * s1));
00072 }
00073
00074 static Texture<float> * CreateFloatTexture(const Transform &tex2world, const TextureParams &tp);
00075 static Texture<SWCSpectrum> * CreateSWCSpectrumTexture(const Transform &tex2world, const TextureParams &tp);
00076 private:
00077
00078 int octaves;
00079 float omega, scale, variation;
00080 TextureMapping3D *mapping;
00081 };
00082
00083 }
00084