00001 #include "noisematerial.h" 00002 #include <math.h> 00003 #include <iostream> 00004 00005 using Magick::Color; 00006 using Magick::ColorRGB; 00007 00008 NoiseMaterial::StaticInit NoiseMaterial::m_init; 00009 00010 double NoiseMaterial::choose_material(const Point3D& intersection_point) const 00011 { 00012 return m_noise.get_noise(intersection_point * m_scale); 00013 } 00014 00015 Color NoiseMaterial::get_color(const Point3D& intersection_point) const 00016 { 00017 // TODO: I don't think this is needed anymore after switching to Magick++ 00018 // colors and getting rid of the global color map in the scene. 00019 #if 0 00020 // !!!THREAD SAFETY ALERT!!! 00021 // we are using one global color here. This 00022 // will absolutely break if we go multi-threaded. 00023 // When that day comes, we will either need to 00024 // revisit this strategy or mangle the key 00025 // based on the thread id 00026 00027 const char * noiseColorKey = "__NOISE_WORKING_COLOR"; 00028 00029 Scene * scene = Scene::get_instance(); 00030 ColorRGB retVal(noiseColorKey); 00031 if(!is_valid(retVal)) 00032 { 00033 retVal = Color("red"); 00034 } 00035 00036 #endif 00037 double coeff = choose_material(intersection_point); 00038 00039 ColorRGB one = m_material_one->get_color(intersection_point); 00040 ColorRGB two = m_material_two->get_color(intersection_point); 00041 00042 return (one * coeff) + (two * (1.0-coeff)); 00043 00044 } 00045 00046 bool NoiseMaterial::is_light(const Point3D& intersection_point) const 00047 { 00048 return false; 00049 } 00050 00051 void NoiseMaterial::set_is_light(bool v) 00052 { 00053 } 00054 00055 double NoiseMaterial::get_diffuse(const Point3D& intersection_point) const 00056 { 00057 double coeff = choose_material(intersection_point); 00058 double contributionOne = m_material_one->get_diffuse(intersection_point) * coeff; 00059 double contributionTwo = m_material_two->get_diffuse(intersection_point) * (1.0 - coeff); 00060 return contributionOne + contributionTwo; 00061 } 00062 00063 void NoiseMaterial::set_diffuse(double diffuse) 00064 { 00065 } 00066 00067 double NoiseMaterial::get_reflection(const Point3D& intersection_point) const 00068 { 00069 double coeff = choose_material(intersection_point); 00070 double contributionOne = m_material_one->get_reflection(intersection_point) * coeff; 00071 double contributionTwo = m_material_two->get_reflection(intersection_point) * (1.0 - coeff); 00072 return contributionOne + contributionTwo; 00073 } 00074 00075 double NoiseMaterial::get_reflectivity(const Point3D& intersection_point) const 00076 { 00077 double coeff = choose_material(intersection_point); 00078 double contributionOne = m_material_one->get_reflectivity(intersection_point) * coeff; 00079 double contributionTwo = m_material_two->get_reflectivity(intersection_point) * (1.0 - coeff); 00080 return contributionOne + contributionTwo; 00081 } 00082 00083 double NoiseMaterial::get_refraction_index(const Point3D& intersection_point) const 00084 { 00085 // This would seem sketchy at best. Perhaps better 00086 // would be to make material one the authority... 00087 double coeff = choose_material(intersection_point); 00088 double contributionOne = m_material_one->get_refraction_index(intersection_point) * coeff; 00089 double contributionTwo = m_material_two->get_refraction_index(intersection_point) * (1.0 - coeff); 00090 return contributionOne + contributionTwo; 00091 } 00092 00093 double NoiseMaterial::get_opacity(const Point3D& intersection_point) const 00094 { 00095 double coeff = choose_material(intersection_point); 00096 double contributionOne = m_material_one->get_opacity(intersection_point) * coeff; 00097 double contributionTwo = m_material_two->get_opacity(intersection_point) * (1.0 - coeff); 00098 return contributionOne + contributionTwo; 00099 } 00100 00101 void NoiseMaterial::set_opacity(double opacity) 00102 { 00103 } 00104 00105 00106 Material * NoiseMaterial::createNoiseMaterial(std::map<std::string, std::string> props) 00107 { 00108 Scene * scene = Scene::get_instance(); 00109 Material * one = scene->get_material(props["material1"]); 00110 Material * two = scene->get_material(props["material2"]); 00111 return new NoiseMaterial(one, two); 00112 00113 } 00114