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