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 FBmTexture : public Texture<T> {
00035 public:
00036
00037 virtual ~FBmTexture() {
00038 delete mapping;
00039 }
00040 FBmTexture(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 FBm(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
00054 private:
00055
00056 int octaves;
00057 float omega;
00058 TextureMapping3D *mapping;
00059 };
00060
00061
00062 template <class T> Texture<float> * FBmTexture<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
00070 return new FBmTexture<float>(tp.FindInt("octaves", 8),
00071 tp.FindFloat("roughness", .5f), map);
00072 }
00073
00074 template <class T> Texture<SWCSpectrum> * FBmTexture<T>::CreateSWCSpectrumTexture(const Transform &tex2world,
00075 const TextureParams &tp) {
00076
00077 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00078
00079 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00080 imap->Apply3DTextureMappingOptions(tp);
00081
00082 return new FBmTexture<SWCSpectrum>(tp.FindInt("octaves", 8),
00083 tp.FindFloat("roughness", .5f), map);
00084 }
00085
00086 }