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 template <class T> class WrinkledTexture : public Texture<T> {
00033 public:
00034
00035 ~WrinkledTexture() {
00036 delete mapping;
00037 }
00038 WrinkledTexture(int oct, float roughness, TextureMapping3D *map) {
00039 omega = roughness;
00040 octaves = oct;
00041 mapping = map;
00042 }
00043 T Evaluate(const DifferentialGeometry &dg) const {
00044 Vector dpdx, dpdy;
00045 Point P = mapping->Map(dg, &dpdx, &dpdy);
00046 return Turbulence(P, dpdx, dpdy, omega, octaves);
00047 }
00048
00049 static Texture<float> * CreateFloatTexture(const Transform &tex2world, const TextureParams &tp);
00050 static Texture<Spectrum> * CreateSpectrumTexture(const Transform &tex2world, const TextureParams &tp);
00051 private:
00052
00053 int octaves;
00054 float omega;
00055 TextureMapping3D *mapping;
00056 };
00057
00058
00059
00060 template <class T> inline Texture<float> * WrinkledTexture<T>::CreateFloatTexture(const Transform &tex2world,
00061 const TextureParams &tp) {
00062
00063 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00064
00065 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00066 imap->Apply3DTextureMappingOptions(tp);
00067 return new WrinkledTexture<float>(tp.FindInt("octaves", 8),
00068 tp.FindFloat("roughness", .5f), map);
00069 }
00070
00071 template <class T> inline Texture<Spectrum> * WrinkledTexture<T>::CreateSpectrumTexture(const Transform &tex2world,
00072 const TextureParams &tp) {
00073
00074 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00075
00076 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00077 imap->Apply3DTextureMappingOptions(tp);
00078 return new WrinkledTexture<Spectrum>(tp.FindInt("octaves", 8),
00079 tp.FindFloat("roughness", .5f), map);
00080 }
00081
00082 }
00083