00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef ARCHON_RAYTRACER_SURFACE_H
00021 #define ARCHON_RAYTRACER_SURFACE_H
00022
00023 #include <archon/math/vector.H>
00024 #include <archon/util/color.H>
00025 #include <archon/util/image.H>
00026
00027 #include "light.H"
00028
00029 namespace Archon
00030 {
00031 namespace Raytracer
00032 {
00033 using namespace Utilities;
00034 using namespace Math;
00035
00036 class Surface
00037 {
00038 private:
00039 double ambientReflection;
00040 double diffuseReflection;
00041 double specularReflection;
00042 double specularRefraction;
00043 double reflectiveExponent;
00044 double refractiveExponent;
00045 double refractiveIndex;
00046
00047 public:
00048 Surface(double ambientReflection,
00049 double diffuseReflection,
00050 double specularReflection,
00051 double specularRefraction,
00052 double reflectiveExponent,
00053 double refractiveExponent,
00054 double refractiveIndex):
00055 ambientReflection(ambientReflection),
00056 diffuseReflection(diffuseReflection),
00057 specularReflection(specularReflection),
00058 specularRefraction(specularRefraction),
00059 reflectiveExponent(reflectiveExponent),
00060 refractiveExponent(refractiveExponent),
00061 refractiveIndex(refractiveIndex) {}
00062
00063 virtual ~Surface() {}
00064
00065 ColorRGBA shade(const Light &light, const Vector3 &normal, const Vector3 &viewDirection,
00066 const Vector3 &lightDirection, const ColorRGBA &surfaceColor) const;
00067
00068 double getAmbientReflection() const { return ambientReflection; }
00069 double getDiffuseReflection() const { return diffuseReflection; }
00070 double getSpecularReflection() const { return specularReflection; }
00071 double getSpecularRefraction() const { return specularRefraction; }
00072 double getRefractiveIndex() const { return refractiveIndex; }
00073
00074 virtual void getColor(const Vector2 &texturePoint, ColorRGBA &) const = 0;
00075 };
00076
00077 class StandardSurface: public Surface
00078 {
00079 private:
00080 ColorRGBA color;
00081
00082 public:
00083 StandardSurface(ColorRGBA color,
00084 double ambientReflection = 0.1,
00085 double diffuseReflection = 0.5,
00086 double specularReflection = 0.5,
00087 double specularRefraction = 0.5,
00088 double reflectiveExponent = 20,
00089 double refractiveExponent = 20,
00090 double refractiveIndex = 1):
00091 Surface(ambientReflection, diffuseReflection,
00092 specularReflection, specularRefraction,
00093 reflectiveExponent, refractiveExponent,
00094 refractiveIndex), color(color) {}
00095
00096 void getColor(const Vector2 &, ColorRGBA &c) const { c = color; }
00097 };
00098
00099 class Texture: public Surface
00100 {
00101 private:
00102 const Image image;
00103 const unsigned horizontalTiles;
00104 const unsigned verticalTiles;
00105
00106 public:
00107 Texture(Image image,
00108 double ambientReflection = 0.1,
00109 double diffuseReflection = 0.5,
00110 double specularReflection = 0.5,
00111 double specularRefraction = 0.5,
00112 double reflectiveExponent = 20,
00113 double refractiveExponent = 20,
00114 double refractiveIndex = 1,
00115 unsigned horizontalTiles = 1,
00116 unsigned verticalTiles = 1):
00117 Surface(ambientReflection, diffuseReflection,
00118 specularReflection, specularRefraction,
00119 reflectiveExponent, refractiveExponent,
00120 refractiveIndex),
00121 image(image),
00122 horizontalTiles(horizontalTiles),
00123 verticalTiles(verticalTiles) {}
00124
00130 void getColor(const Vector2 &texturePoint, ColorRGBA &) const;
00131 };
00132 }
00133 }
00134
00135 #endif // ARCHON_RAYTRACER_SURFACE_H