Skip to content
Browse files

new texture test

  • Loading branch information...
1 parent 441051a commit 7e8f69a3f7fe6dbdba67457aba8bb6a943967d08 @Xaseron committed Jan 30, 2012
Showing with 143 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +46 −0 test_image_texture.cc
  3. +48 −0 test_marble_texture.cc
  4. +48 −0 test_simple_texture.cc
View
1 .gitignore
@@ -0,0 +1 @@
+build/
View
46 test_image_texture.cc
@@ -0,0 +1,46 @@
+// simple_raytrace.cc
+
+#include <iostream>
+#include "vector3.h"
+#include "rgb.h"
+#include "image.h"
+#include "shape.h"
+#include "uvsphere.h"
+#include "image_texture.h"
+using namespace std;
+
+int main() {
+ HitRecord rec;
+ bool is_a_hit;
+ float tmax;
+ // negative z so we can use right-handed coords
+ Vector3 dir(0,0,-1); // direction of viewing rays
+
+ //input Texture
+ Texture * tex = new ImageTexture("worldmap.ppm");
+
+ // scene geometry
+ UVSphere sphere(Vector3(750,750,-1000), 500, tex);
+ Image im(1500, 1500);
+
+ // loop over pixels
+ for (int i = 0; i < 1500; i++)
+ for (int j = 0; j < 1500; j++) {
+ tmax = 100000.0f;
+ is_a_hit = false;
+ Ray r(Vector3(i,j,0), dir);
+
+ if (sphere.hit(r, .00001f, tmax, 0.0f, rec)) {
+ tmax = rec.t;
+ is_a_hit = true;
+ }
+ if (is_a_hit) {
+ rgb color = tex->value(rec.uv, rec.hit_p);
+ im.set(i, j, color);
+ }
+ else
+ im.set(i, j, rgb(.2, .2, .2));
+ }
+ im.writePPM(cout);
+}
+
View
48 test_marble_texture.cc
@@ -0,0 +1,48 @@
+// simple_raytrace.cc
+
+#include <iostream>
+#include "vector3.h"
+#include "rgb.h"
+#include "image.h"
+#include "shape.h"
+#include "uvsphere.h"
+#include "marble_texture.h"
+using namespace std;
+
+int main() {
+ HitRecord rec;
+ bool is_a_hit;
+ float tmax;
+ // negative z so we can use right-handed coords
+ Vector3 dir(0,0,-1); // direction of viewing rays
+
+ //generate Texture
+ Texture *tex = new MarbleTexture(0.001f, 5.0f, 8);
+
+ // scene geometry
+ UVSphere sphere(Vector3(750,750,-1000), 500, tex);
+ Image im(1500, 1500);
+
+ // loop over pixels
+ for (int i = 0; i < 1500; i++)
+ for (int j = 0; j < 1500; j++) {
+ tmax = 100000.0f;
+ is_a_hit = false;
+ Ray r(Vector3(i,j,0), dir);
+
+ if (sphere.hit(r, .00001f, tmax, 0.0f, rec)) {
+ tmax = rec.t;
+ is_a_hit = true;
+ }
+ if (is_a_hit) {
+ rgb color = tex->value(rec.uv, rec.hit_p);
+ im.set(i, j, color);
+ }
+ // else if(sphere.shadowHit(r, .00001f, tmax, 0.0f))
+ // im.set(i,j,rgb(.0, .0, .0));
+ else
+ im.set(i, j, rgb(.2, .2, .2));
+ }
+ im.writePPM(cout);
+}
+
View
48 test_simple_texture.cc
@@ -0,0 +1,48 @@
+// simple_raytrace.cc
+
+#include <iostream>
+#include "vector3.h"
+#include "rgb.h"
+#include "image.h"
+#include "shape.h"
+#include "uvsphere.h"
+#include "simple_texture.h"
+using namespace std;
+
+int main() {
+ HitRecord rec;
+ bool is_a_hit;
+ float tmax;
+ // negative z so we can use right-handed coords
+ Vector3 dir(0,0,-1); // direction of viewing rays
+
+ //generate Texture
+ Texture *tex = new SimpleTexture(rgb(0.8,0.0,0.0));
+
+ // scene geometry
+ UVSphere sphere(Vector3(750,750,-1000), 350, tex);
+ Image im(1500, 1500);
+
+ // loop over pixels
+ for (int i = 0; i < 1500; i++)
+ for (int j = 0; j < 1500; j++) {
+ tmax = 100000.0f;
+ is_a_hit = false;
+ Ray r(Vector3(i,j,0), dir);
+
+ if (sphere.hit(r, .00001f, tmax, 0.0f, rec)) {
+ tmax = rec.t;
+ is_a_hit = true;
+ }
+ if (is_a_hit) {
+ rgb color = tex->value(rec.uv, rec.hit_p);
+ im.set(i, j, color);
+ }
+ // else if(sphere.shadowHit(r, .00001f, tmax, 0.0f))
+ // im.set(i,j,rgb(.0, .0, .0));
+ else
+ im.set(i, j, rgb(.2, .2, .2));
+ }
+ im.writePPM(cout);
+}
+

0 comments on commit 7e8f69a

Please sign in to comment.
Something went wrong with that request. Please try again.