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_DOTS_H
00029 #define PBRT_TEXTURES_DOTS_H
00030
00031
00032 #include "pbrt.h"
00033 #include "texture.h"
00034 #include "paramset.h"
00035
00036
00037 template <typename T> class DotsTexture : public Texture<T> {
00038 public:
00039
00040 ~DotsTexture() {
00041 delete mapping;
00042 }
00043 DotsTexture(TextureMapping2D *m, Reference<Texture<T> > t1,
00044 Reference<Texture<T> > t2)
00045 : mapping(m), outsideDot(t1), insideDot(t2) {
00046 }
00047 T Evaluate(const DifferentialGeometry &dg) const {
00048
00049 float s, t, dsdx, dtdx, dsdy, dtdy;
00050 mapping->Map(dg, &s, &t, &dsdx, &dtdx, &dsdy, &dtdy);
00051 int sCell = Floor2Int(s + .5f), tCell = Floor2Int(t + .5f);
00052
00053
00054 if (Noise(sCell+.5f, tCell+.5f) > 0) {
00055 float radius = .35f;
00056 float maxShift = 0.5f - radius;
00057 float sCenter = sCell + maxShift *
00058 Noise(sCell + 1.5f, tCell + 2.8f);
00059 float tCenter = tCell + maxShift *
00060 Noise(sCell + 4.5f, tCell + 9.8f);
00061 float ds = s - sCenter, dt = t - tCenter;
00062 if (ds*ds + dt*dt < radius*radius)
00063 return insideDot->Evaluate(dg);
00064 }
00065 return outsideDot->Evaluate(dg);
00066 }
00067 private:
00068
00069 TextureMapping2D *mapping;
00070 Reference<Texture<T> > outsideDot, insideDot;
00071 };
00072
00073
00074 DotsTexture<float> *CreateDotsFloatTexture(const Transform &tex2world,
00075 const TextureParams &tp);
00076 DotsTexture<Spectrum> *CreateDotsSpectrumTexture(const Transform &tex2world,
00077 const TextureParams &tp);
00078
00079 #endif // PBRT_TEXTURES_DOTS_H