Commit 0b8fb87a authored by Weizhen Huang's avatar Weizhen Huang

extend the materialNode class with refractive materials

parent d539e524
......@@ -764,7 +764,7 @@ void GLState::set_shininess(float _shininess)
if (updateGL_ && compatibilityProfile_)
{
makeCurrent();
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, _shininess);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, std::min(128.f, _shininess));
}
}
......
......@@ -141,9 +141,9 @@ QString Material::serializeToJson() const {
matMap["specularColor"] = col2vl(specularColor_);
matMap["overlayColor"] = col2vl(overlayColor_);
matMap["shininess"] = shininess_;
matMap["illum"] = illum_;
matMap["reflectance"] = reflectance_;
matMap["indexOfRefraction"] = indexOfRefraction_;
matMap["isRefractive"] = isRefractive_;
matMap["pointSize"] = pointSize_;
matMap["lineWidth"] = lineWidth_;
matMap["roundPoints"] = roundPoints_;
......@@ -179,9 +179,9 @@ void Material::deserializeFromVariantMap(const QVariantMap &matMap) {
if (matMap.contains("specularColor")) specularColor_ = vl2col(matMap["specularColor"].toList());
if (matMap.contains("overlayColor")) overlayColor_ = vl2col(matMap["overlayColor"].toList());
if (matMap.contains("shininess")) shininess_ = matMap["shininess"].toFloat();
if (matMap.contains("illum")) illum_ = matMap["illum"].toInt();
if (matMap.contains("reflectance")) reflectance_ = matMap["reflectance"].toDouble();
if (matMap.contains("indexOfRefraction")) indexOfRefraction_ = matMap["indexOfRefraction"].toDouble();
if (matMap.contains("isRefractive")) isRefractive_ = matMap["isRefractive"].toBool();
if (matMap.contains("pointSize")) pointSize_ = matMap["pointSize"].toFloat();
if (matMap.contains("lineWidth")) lineWidth_ = matMap["lineWidth"].toFloat();
if (matMap.contains("roundPoints")) roundPoints_ = matMap["roundPoints"].toBool();
......@@ -484,7 +484,7 @@ MaterialNode::read(std::istream& _is)
char s[200];
float x, y, z, u;
int i;
bool b;
while (_is && (!_is.eof()) && _is.getline(s,200) ) {
std::istringstream buffer(s);
......@@ -546,12 +546,12 @@ MaterialNode::read(std::istream& _is)
material_.shininess(x);
}
}
// Illumination model
else if (specifier == "Illum") {
buffer >> i;
// Refractive
else if (specifier == "isRefractive") {
buffer >> b;
if (buffer.good()) {
material_.illum(i);
material_.set_refractive(b);
}
}
// OverlayColor
......
......@@ -95,9 +95,9 @@ public:
specularColor_(GLState::default_specular_color),
overlayColor_(GLState::default_overlay_color),
shininess_(GLState::default_shininess),
illum_(0),
reflectance_(0.0),
indexOfRefraction_(1.0),
isRefractive_(false),
pointSize_(1.0),
lineWidth_(1.0),
roundPoints_(false),
......@@ -122,9 +122,9 @@ public:
specularColor_(_m.specularColor_),
overlayColor_(_m.overlayColor_),
shininess_(_m.shininess_),
illum_(_m.illum_),
reflectance_(_m.reflectance_),
indexOfRefraction_(_m.indexOfRefraction_),
isRefractive_(_m.isRefractive_),
pointSize_(_m.pointSize_),
lineWidth_(_m.lineWidth_),
roundPoints_(_m.roundPoints_),
......@@ -211,23 +211,20 @@ public:
/// get shininess
float shininess() const { return shininess_; }
/// set illumnation model
void illum(int _m) { illum_ = _m; }
/// get illumination model
int illum() const { return illum_; }
/// set reflectance ( not used in OpenGL Rendering)
void reflectance(double _m) { reflectance_ = _m; }
/// get reflectance ( not used in OpenGL Rendering)
double reflectance() const { return reflectance_; }
/// set index of refraction
void indexOfRefraction(double _m) { indexOfRefraction_ = _m; }
/// get index of refraction ( not used in OpenGL Rendering)
double indexOfRefraction() const { return indexOfRefraction_; }
bool isRefractive() const {return illum_ == 4 || illum_ == 6 || illum_ == 7 || illum_ == 9;}
/// set refractive flag
void set_refractive(bool _r) { isRefractive_ = _r; }
/// get refractive flag
bool isRefractive() const {return isRefractive_;}
/// set point size (default: 1.0)
void pointSize(float _sz) { pointSize_ = _sz; }
......@@ -302,7 +299,7 @@ public:
/// disable backface culling (not active by default, see applyProperties)
void disableBackfaceCulling() { backfaceCulling_ = false; }
bool isEmissive() const { return baseColor_[0] > 0.f || baseColor_[1] > 0.f || baseColor_[2] > 0.f; }
bool isEmissive() const { return (baseColor_[0] > 0.f || baseColor_[1] > 0.f || baseColor_[2] > 0.f); }
protected:
......@@ -313,9 +310,9 @@ protected:
Vec4f overlayColor_;
float shininess_;
int illum_;
double reflectance_;
double indexOfRefraction_;
bool isRefractive_;
float pointSize_;
float lineWidth_;
......@@ -470,11 +467,6 @@ public:
/// get shininess
float shininess() const { return material_.shininess(); }
/// set illumination model
void set_illum(int _m) { material_.illum(_m); }
/// get illumination model
int illum() const { return material_.illum(); }
/// set reflectance
void set_reflectance(double _m) { material_.reflectance(_m); }
/// get reflectance
......@@ -485,6 +477,11 @@ public:
/// get index of refraction
double indexOfRefraction() const { return material_.indexOfRefraction(); }
/// set refractive flag
void set_refractive(bool _r) { material_.isRefractive_ = _r; }
/// get refractive flag
bool isRefractive() const {return material_.isRefractive_;}
/** @} */
//===========================================================================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment