00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "stdafx.h"
00027 #include "textures/checkerboard.h"
00028
00029
00030 Texture<float> *CreateCheckerboardFloatTexture(const Transform &tex2world,
00031 const TextureParams &tp) {
00032 int dim = tp.FindInt("dimension", 2);
00033 if (dim != 2 && dim != 3) {
00034 Error("%d dimensional checkerboard texture not supported", dim);
00035 return NULL;
00036 }
00037 Reference<Texture<float> > tex1 = tp.GetFloatTexture("tex1", 1.f);
00038 Reference<Texture<float> > tex2 = tp.GetFloatTexture("tex2", 0.f);
00039 if (dim == 2) {
00040
00041 TextureMapping2D *map = NULL;
00042 string type = tp.FindString("mapping", "uv");
00043 if (type == "uv") {
00044 float su = tp.FindFloat("uscale", 1.);
00045 float sv = tp.FindFloat("vscale", 1.);
00046 float du = tp.FindFloat("udelta", 0.);
00047 float dv = tp.FindFloat("vdelta", 0.);
00048 map = new UVMapping2D(su, sv, du, dv);
00049 }
00050 else if (type == "spherical") map = new SphericalMapping2D(Inverse(tex2world));
00051 else if (type == "cylindrical") map = new CylindricalMapping2D(Inverse(tex2world));
00052 else if (type == "planar")
00053 map = new PlanarMapping2D(tp.FindVector("v1", Vector(1,0,0)),
00054 tp.FindVector("v2", Vector(0,1,0)),
00055 tp.FindFloat("udelta", 0.f), tp.FindFloat("vdelta", 0.f));
00056 else {
00057 Error("2D texture mapping \"%s\" unknown", type.c_str());
00058 map = new UVMapping2D;
00059 }
00060 string aamode = tp.FindString("aamode", "closedform");
00061 return new Checkerboard2DTexture<float>(map, tex1, tex2, aamode);
00062 }
00063 else {
00064
00065 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00066 return new Checkerboard3DTexture<float>(map, tex1, tex2);
00067 }
00068 }
00069
00070
00071
00072 Texture<Spectrum> *CreateCheckerboardSpectrumTexture(const Transform &tex2world,
00073 const TextureParams &tp) {
00074 int dim = tp.FindInt("dimension", 2);
00075 if (dim != 2 && dim != 3) {
00076 Error("%d dimensional checkerboard texture not supported", dim);
00077 return NULL;
00078 }
00079 Reference<Texture<Spectrum> > tex1 = tp.GetSpectrumTexture("tex1", 1.f);
00080 Reference<Texture<Spectrum> > tex2 = tp.GetSpectrumTexture("tex2", 0.f);
00081 if (dim == 2) {
00082
00083 TextureMapping2D *map = NULL;
00084 string type = tp.FindString("mapping", "uv");
00085 if (type == "uv") {
00086 float su = tp.FindFloat("uscale", 1.);
00087 float sv = tp.FindFloat("vscale", 1.);
00088 float du = tp.FindFloat("udelta", 0.);
00089 float dv = tp.FindFloat("vdelta", 0.);
00090 map = new UVMapping2D(su, sv, du, dv);
00091 }
00092 else if (type == "spherical") map = new SphericalMapping2D(Inverse(tex2world));
00093 else if (type == "cylindrical") map = new CylindricalMapping2D(Inverse(tex2world));
00094 else if (type == "planar")
00095 map = new PlanarMapping2D(tp.FindVector("v1", Vector(1,0,0)),
00096 tp.FindVector("v2", Vector(0,1,0)),
00097 tp.FindFloat("udelta", 0.f), tp.FindFloat("vdelta", 0.f));
00098 else {
00099 Error("2D texture mapping \"%s\" unknown", type.c_str());
00100 map = new UVMapping2D;
00101 }
00102 string aamode = tp.FindString("aamode", "closedform");
00103 return new Checkerboard2DTexture<Spectrum>(map, tex1, tex2, aamode);
00104 }
00105 else {
00106
00107 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00108 return new Checkerboard3DTexture<Spectrum>(map, tex1, tex2);
00109 }
00110 }
00111
00112