Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

turbulence tests

  • Loading branch information...
commit d346be9f1c6522db157213f7b0b6f170e11442f9 1 parent 59f7f32
@Xaseron Xaseron authored
View
26 CMakeLists.txt
@@ -1,23 +1,5 @@
cmake_minimum_required(VERSION 2.6)
-SET(SRC
- image.cc
- vector3.cc
- onb.cc
- )
-
-SET(FLS
- rgb.h
- image.h
- vector3.h
- onb.h
- dynarray.h
- rng.h
- ray.h
- shape.h
- triangle.h
- sphere.h
- )
PROJECT(RayBeam)
@@ -34,10 +16,14 @@ ADD_EXECUTABLE(test_rng test_rng.cc)
ADD_EXECUTABLE(test_ray vector3.cc test_ray.cc)
ADD_EXECUTABLE(test_surfaces triangle.cc sphere.cc test_surfaces.cc)
ADD_EXECUTABLE(test_solid_noise solid_noise.cc test_solid_noise.cc)
+
ADD_EXECUTABLE(test_noise_texture image.cc solid_noise.cc noise_texture.cc test_noise_texture.cc)
ADD_EXECUTABLE(test_wood_texture image.cc solid_noise.cc wood_texture.cc test_wood_texture.cc)
-ADD_EXECUTABLE(test_simple_texture image.cc uvsphere.cc test_simple_texture.cc)
-ADD_EXECUTABLE(test_marble_texture image.cc solid_noise.cc marble_texture.cc uvsphere.cc test_marble_texture.cc)
+ADD_EXECUTABLE(test_turbulence_texture image.cc solid_noise.cc turbulence_texture.cc test_turbulence_texture.cc)
+ADD_EXECUTABLE(test_simple_texture image.cc test_simple_texture.cc)
+ADD_EXECUTABLE(test_marble_texture image.cc solid_noise.cc marble_texture.cc test_marble_texture.cc)
+
+ADD_EXECUTABLE(test_uvsphere image.cc solid_noise.cc marble_texture.cc wood_texture.cc uvsphere.cc test_uvsphere.cc)
ADD_EXECUTABLE(test_image_texture image.cc image_texture.cc uvsphere.cc test_image_texture.cc)
ADD_EXECUTABLE(simple_raytrace image.cc triangle.cc sphere.cc simple_raytrace.cc)
View
4 noise_texture.h
@@ -12,8 +12,8 @@ class NoiseTexture : public Texture {
public:
NoiseTexture(float _scale = 1.0f){
scale = _scale;
- c0 = rgb(0.8,0.0,0.0);
- c1 = rgb(0.0,0.0,0.8);
+ c0 = rgb(1.0,1.0,1.0);
+ c1 = rgb(0.0,0.0,0.0);
}
NoiseTexture(const rgb& _c0, const rgb& _c1, float _scale = 1.0f)
View
29 test_marble_texture.cc
@@ -4,44 +4,19 @@
#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);
+ Texture *tex = new MarbleTexture(0.001f);
- // 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.set(i, j, tex->value(Vector2(i, j), Vector3(i, j, 0)));
}
im.writePPM(cout);
}
View
2  test_noise_texture.cc
@@ -9,7 +9,7 @@ using namespace std;
int main() {
//generate Texture
- Texture *tex = new NoiseTexture(rgb(1.0,1.0,1.0), rgb(0.0,0.0,0.0), 0.01f);
+ Texture *tex = new NoiseTexture(0.01f);
Image im(1500, 1500);
View
29 test_simple_texture.cc
@@ -4,44 +4,19 @@
#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));
+ Texture *tex = new SimpleTexture(rgb(1.0, 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.set(i, j, tex->value(Vector2(i, j), Vector3(i, j, 0)));
}
im.writePPM(cout);
}
View
23 test_turbulence_texture.cc
@@ -0,0 +1,23 @@
+// simple_raytrace.cc
+
+#include <iostream>
+#include "vector3.h"
+#include "rgb.h"
+#include "image.h"
+#include "turbulence_texture.h"
+using namespace std;
+
+int main() {
+ //generate Texture
+ Texture *tex = new TurbulenceTexture(0.01f);
+
+ Image im(1500, 1500);
+
+ // loop over pixels
+ for (int i = 0; i < 1500; i++)
+ for (int j = 0; j < 1500; j++) {
+ im.set(i, j, tex->value(Vector2(i, j), Vector3(i, j, 0)));
+ }
+ im.writePPM(cout);
+}
+
View
50 test_uvsphere.cc
@@ -0,0 +1,50 @@
+// simple_raytrace.cc
+
+#include <iostream>
+#include "vector3.h"
+#include "rgb.h"
+#include "image.h"
+#include "shape.h"
+#include "uvsphere.h"
+#include "marble_texture.h"
+#include "wood_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);
+ Texture *tex = new WoodTexture(0.0015f, 10);
+
+ // 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
8 turbulence_texture.cc
@@ -0,0 +1,8 @@
+// turbulence_texture.cc
+
+#include "turbulence_texture.h"
+
+rgb TurbulenceTexture::value(const Vector2& uv, const Vector3& p) const {
+ float t = (1.0f + solid_noise.turbulence(p * scale, depth)) / 2.0f;
+ return t*c0 + (1.0f - t)*c1;
+}
View
31 turbulence_texture.h
@@ -0,0 +1,31 @@
+//noise_texture.h
+
+#ifndef _TURBULENCE_TEXTURE_H_
+#define _TURBULENCE_TEXTURE_H_ 1
+
+#include <math.h>
+#include "texture.h"
+#include "rgb.h"
+#include "solid_noise.h"
+
+class TurbulenceTexture : public Texture {
+ public:
+ TurbulenceTexture(float _scale = 1.0f, int _depth = 4){
+ scale = _scale;
+ c0 = rgb(1.0,1.0,1.0);
+ c1 = rgb(0.0,0.0,0.0);
+ depth = _depth;
+ }
+
+ TurbulenceTexture(const rgb& _c0, const rgb& _c1, float _scale = 1.0f, int _depth = 4)
+ : c0(_c0), c1(_c1), scale(_scale), depth(_depth) {}
+
+ virtual rgb value(const Vector2& uv, const Vector3& p) const;
+
+ rgb c0, c1;
+ float scale;
+ int depth;
+ SolidNoise solid_noise;
+};
+
+#endif // _TURBULENCE_TEXTURE_H_
View
10 uvsphere.cc
@@ -31,14 +31,14 @@ bool UVSphere::hit(const Ray& r, float tmin, float tmax, float time, HitRecord&
Vector3 n = record.normal = (record.hit_p - center) / radius;
//calculate UV coordinates
- float twopi = 6.28318530718f;
- float theta = acos( n.z());
- float phi = atan2(n.y(), n.x());
+ float twopi = 2*M_PI;
+ float theta = acos( n.y());
+ float phi = atan2(n.x(), n.z())+M_PI;
if(phi < 0.0f )
phi += twopi;
- float one_over_2pi = .159154943092f;
- float one_over_pi = .318309886184f;
+ float one_over_2pi = 1/twopi;
+ float one_over_pi = 1/M_PI;
record.uv = Vector2(phi*one_over_2pi, (M_PI - theta) * one_over_pi);
View
2  wood_texture.cc
@@ -1,4 +1,4 @@
-// noise_texture.cc
+// wood_texture.cc
#include "wood_texture.h"
#include <cstdio>
View
8 wood_texture.h
@@ -1,7 +1,7 @@
-//noise_texture.h
+//wood_texture.h
-#ifndef _NOISE_TEXTURE_H_
-#define _NOISE_TEXTURE_H_ 1
+#ifndef _WOOD_TEXTURE_H_
+#define _WOOD_TEXTURE_H_ 1
#include <math.h>
#include "texture.h"
@@ -28,4 +28,4 @@ class WoodTexture : public Texture {
SolidNoise solid_noise;
};
-#endif // _NOISE_TEXTURE_H_
+#endif // _WOOD_TEXTURE_H_
Please sign in to comment.
Something went wrong with that request. Please try again.