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