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