00001 #ifndef MARBLEMATERIAL_H 00002 #define MARBLEMATERIAL_H 00003 00004 #include "raytrace_defs.h" 00005 #include "material.h" 00006 #include "pluginfactory.h" 00007 #include "noise.h" 00008 00009 00011 Material * make_marble_material(std::map<std::string, std::string> props); 00012 00013 00026 class MarbleMaterial : public Material{ 00028 class StaticInit 00029 { 00030 public: 00032 StaticInit() 00033 { 00034 log_info("Registering as \"marble\" "); 00035 MaterialFactory::get_instance()->registerPlugin("marble", sigc::ptr_fun(make_marble_material)); 00036 } 00037 }; 00038 00039 protected: 00040 00041 00043 Noise m_noise; 00044 00046 static StaticInit m_init; 00047 00049 Material * m_material_one_a; 00051 Material * m_material_one_b; 00052 00054 Material * m_material_two_a; 00056 Material * m_material_two_b; 00057 00060 double m_break_point; 00061 00063 double m_material_one_scale; 00064 00066 double m_material_two_scale; 00067 00070 double m_noise_scale; 00071 00072 public: 00074 MarbleMaterial( 00075 Material * one_a, 00076 Material * one_b, 00077 Material * two_a, 00078 Material * two_b, 00079 double break_point, 00080 double noise_scale) : 00081 m_material_one_a(one_a), 00082 m_material_one_b(one_b), 00083 m_material_two_a(two_a), 00084 m_material_two_b(two_b), 00085 m_break_point(break_point), 00086 m_noise_scale(noise_scale) 00087 { 00088 m_material_one_scale = 1.0 / m_break_point ; 00089 m_material_two_scale = 1.0 / (1-m_break_point); 00090 } 00091 00092 virtual ~MarbleMaterial() { 00093 } 00094 00096 double interpolate_value(double noise_amount, double one, double two) const; 00097 00099 void choose_materials(double noise_amount, Material ** one , Material ** two) const; 00100 00102 virtual Magick::Color get_color(const Point3D& intersesction_point) const ; 00103 00105 virtual bool is_light(const Point3D& intersesction_point) const ; 00106 00108 virtual void set_is_light(bool v); 00109 00111 virtual double get_diffuse(const Point3D& intersesction_point) const ; 00112 00114 virtual void set_diffuse(double diffuse); 00115 00117 virtual double get_reflection(const Point3D& intersesction_point) const; 00118 00120 virtual double get_reflectivity(const Point3D& intersesction_point) const ; 00121 00126 virtual double get_refraction_index(const Point3D& intersesction_point) const; 00127 00129 virtual double get_opacity(const Point3D& intersesction_point) const ; 00130 00132 virtual void set_opacity(double opacity) ; 00133 00134 }; 00135 00136 Material * make_marble_material(std::map<std::string, std::string> props) { 00137 Scene * scene = Scene::get_instance(); 00138 Material * one = scene->get_material(props["material1a"]); 00139 Material * two = scene->get_material(props["material1b"]); 00140 Material * three = scene->get_material(props["material2a"]); 00141 Material * four = scene->get_material(props["material2b"]); 00142 double break_point = (double)strtod(props["break_point"].c_str(), NULL); 00143 double noise_scale = (double)strtod(props["noise_scale"].c_str(), NULL); 00144 return new MarbleMaterial(one, two, three, four, break_point, noise_scale); 00145 } 00146 00147 #endif