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