Commit d539e524 authored by Weizhen Huang's avatar Weizhen Huang

extend the materialNode class with refractive materials

parent 1275ee2d
...@@ -141,7 +141,9 @@ QString Material::serializeToJson() const { ...@@ -141,7 +141,9 @@ QString Material::serializeToJson() const {
matMap["specularColor"] = col2vl(specularColor_); matMap["specularColor"] = col2vl(specularColor_);
matMap["overlayColor"] = col2vl(overlayColor_); matMap["overlayColor"] = col2vl(overlayColor_);
matMap["shininess"] = shininess_; matMap["shininess"] = shininess_;
matMap["illum"] = illum_;
matMap["reflectance"] = reflectance_; matMap["reflectance"] = reflectance_;
matMap["indexOfRefraction"] = indexOfRefraction_;
matMap["pointSize"] = pointSize_; matMap["pointSize"] = pointSize_;
matMap["lineWidth"] = lineWidth_; matMap["lineWidth"] = lineWidth_;
matMap["roundPoints"] = roundPoints_; matMap["roundPoints"] = roundPoints_;
...@@ -177,7 +179,9 @@ void Material::deserializeFromVariantMap(const QVariantMap &matMap) { ...@@ -177,7 +179,9 @@ void Material::deserializeFromVariantMap(const QVariantMap &matMap) {
if (matMap.contains("specularColor")) specularColor_ = vl2col(matMap["specularColor"].toList()); if (matMap.contains("specularColor")) specularColor_ = vl2col(matMap["specularColor"].toList());
if (matMap.contains("overlayColor")) overlayColor_ = vl2col(matMap["overlayColor"].toList()); if (matMap.contains("overlayColor")) overlayColor_ = vl2col(matMap["overlayColor"].toList());
if (matMap.contains("shininess")) shininess_ = matMap["shininess"].toFloat(); 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("reflectance")) reflectance_ = matMap["reflectance"].toDouble();
if (matMap.contains("indexOfRefraction")) indexOfRefraction_ = matMap["indexOfRefraction"].toDouble();
if (matMap.contains("pointSize")) pointSize_ = matMap["pointSize"].toFloat(); if (matMap.contains("pointSize")) pointSize_ = matMap["pointSize"].toFloat();
if (matMap.contains("lineWidth")) lineWidth_ = matMap["lineWidth"].toFloat(); if (matMap.contains("lineWidth")) lineWidth_ = matMap["lineWidth"].toFloat();
if (matMap.contains("roundPoints")) roundPoints_ = matMap["roundPoints"].toBool(); if (matMap.contains("roundPoints")) roundPoints_ = matMap["roundPoints"].toBool();
...@@ -217,11 +221,11 @@ void MaterialNode::enter(GLState& _state, const DrawModes::DrawMode& _drawmode ...@@ -217,11 +221,11 @@ void MaterialNode::enter(GLState& _state, const DrawModes::DrawMode& _drawmode
if (applyProperties_ & Material) if (applyProperties_ & Material)
{ {
materialBackup_.ambientColor_ = _state.ambient_color(); materialBackup_.ambientColor_ = _state.ambient_color();
materialBackup_.diffuseColor_ = _state.diffuse_color(); materialBackup_.diffuseColor_ = _state.diffuse_color();
materialBackup_.specularColor_ = _state.specular_color(); materialBackup_.specularColor_ = _state.specular_color();
materialBackup_.overlayColor_ = _state.overlay_color(); materialBackup_.overlayColor_ = _state.overlay_color();
materialBackup_.shininess_ = _state.shininess(); materialBackup_.shininess_ = _state.shininess();
_state.set_ambient_color(material_.ambientColor_); _state.set_ambient_color(material_.ambientColor_);
_state.set_diffuse_color(material_.diffuseColor_); _state.set_diffuse_color(material_.diffuseColor_);
...@@ -480,6 +484,7 @@ MaterialNode::read(std::istream& _is) ...@@ -480,6 +484,7 @@ MaterialNode::read(std::istream& _is)
char s[200]; char s[200];
float x, y, z, u; float x, y, z, u;
int i;
while (_is && (!_is.eof()) && _is.getline(s,200) ) { while (_is && (!_is.eof()) && _is.getline(s,200) ) {
std::istringstream buffer(s); std::istringstream buffer(s);
...@@ -541,6 +546,22 @@ MaterialNode::read(std::istream& _is) ...@@ -541,6 +546,22 @@ MaterialNode::read(std::istream& _is)
material_.shininess(x); material_.shininess(x);
} }
} }
// Illumination model
else if (specifier == "Illum") {
buffer >> i;
if (buffer.good()) {
material_.illum(i);
}
}
// OverlayColor
else if (specifier == "indexOfRefraction") {
buffer >> x;
if (buffer.good()) {
material_.indexOfRefraction(x);
}
}
// PointSize // PointSize
else if (specifier == "PointSize") { else if (specifier == "PointSize") {
buffer >> x; buffer >> x;
......
...@@ -83,9 +83,9 @@ namespace SceneGraph { ...@@ -83,9 +83,9 @@ namespace SceneGraph {
**/ **/
class ACGDLLEXPORT Material { class ACGDLLEXPORT Material {
friend class MaterialNode; friend class MaterialNode;
public: public:
/// Default constructor /// Default constructor
Material() : Material() :
...@@ -95,7 +95,9 @@ public: ...@@ -95,7 +95,9 @@ public:
specularColor_(GLState::default_specular_color), specularColor_(GLState::default_specular_color),
overlayColor_(GLState::default_overlay_color), overlayColor_(GLState::default_overlay_color),
shininess_(GLState::default_shininess), shininess_(GLState::default_shininess),
illum_(0),
reflectance_(0.0), reflectance_(0.0),
indexOfRefraction_(1.0),
pointSize_(1.0), pointSize_(1.0),
lineWidth_(1.0), lineWidth_(1.0),
roundPoints_(false), roundPoints_(false),
...@@ -108,10 +110,10 @@ public: ...@@ -108,10 +110,10 @@ public:
colorMaterial_(true), colorMaterial_(true),
backfaceCulling_(false), backfaceCulling_(false),
multiSampling_(true) {}; multiSampling_(true) {};
/// Deconstructor /// Deconstructor
virtual ~Material() {}; virtual ~Material() {};
/// Copy constructor /// Copy constructor
Material(const Material& _m) : Material(const Material& _m) :
baseColor_(_m.baseColor_), baseColor_(_m.baseColor_),
...@@ -120,7 +122,9 @@ public: ...@@ -120,7 +122,9 @@ public:
specularColor_(_m.specularColor_), specularColor_(_m.specularColor_),
overlayColor_(_m.overlayColor_), overlayColor_(_m.overlayColor_),
shininess_(_m.shininess_), shininess_(_m.shininess_),
illum_(_m.illum_),
reflectance_(_m.reflectance_), reflectance_(_m.reflectance_),
indexOfRefraction_(_m.indexOfRefraction_),
pointSize_(_m.pointSize_), pointSize_(_m.pointSize_),
lineWidth_(_m.lineWidth_), lineWidth_(_m.lineWidth_),
roundPoints_(_m.roundPoints_), roundPoints_(_m.roundPoints_),
...@@ -138,7 +142,7 @@ public: ...@@ -138,7 +142,7 @@ public:
QString serializeToJson() const; QString serializeToJson() const;
void deserializeFromJson(const QString &json); void deserializeFromJson(const QString &json);
void deserializeFromVariantMap(const QVariantMap &matMap); void deserializeFromVariantMap(const QVariantMap &matMap);
/** \brief Set color based on _c /** \brief Set color based on _c
* *
* Basecolor (which is the emitted color is set to zero) * Basecolor (which is the emitted color is set to zero)
...@@ -154,7 +158,7 @@ public: ...@@ -154,7 +158,7 @@ public:
c = _c * 0.6f; c[3]=_c[3]; diffuseColor(c); c = _c * 0.6f; c[3]=_c[3]; diffuseColor(c);
c = _c * 0.8f; c[3]=_c[3]; specularColor(c); c = _c * 0.8f; c[3]=_c[3]; specularColor(c);
} }
/// Creates a randomized color and sets it /// Creates a randomized color and sets it
void generateRandomColor() { void generateRandomColor() {
color( Vec4f(0.2 + double(rand())/double(RAND_MAX)*0.8, color( Vec4f(0.2 + double(rand())/double(RAND_MAX)*0.8,
...@@ -168,6 +172,11 @@ public: ...@@ -168,6 +172,11 @@ public:
/// get the base color /// get the base color
const Vec4f& baseColor() const { return baseColor_; } const Vec4f& baseColor() const { return baseColor_; }
/// set emission
void emission(const Vec4f& _c) { baseColor_ = _c;}
/// get emission
const Vec4f& emission() const { return baseColor_; }
/// set the ambient color. /// set the ambient color.
void ambientColor(const Vec4f& _a) { ambientColor_ = _a; } void ambientColor(const Vec4f& _a) { ambientColor_ = _a; }
/// get the ambient color. /// get the ambient color.
...@@ -201,12 +210,25 @@ public: ...@@ -201,12 +210,25 @@ public:
void shininess(float _s) { shininess_ = _s; } void shininess(float _s) { shininess_ = _s; }
/// get shininess /// get shininess
float shininess() const { return 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) /// set reflectance ( not used in OpenGL Rendering)
void reflectance(double _m) { reflectance_ = _m; } void reflectance(double _m) { reflectance_ = _m; }
/// get reflectance ( not used in OpenGL Rendering) /// get reflectance ( not used in OpenGL Rendering)
double reflectance() const { return reflectance_; } 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 point size (default: 1.0) /// set point size (default: 1.0)
void pointSize(float _sz) { pointSize_ = _sz; } void pointSize(float _sz) { pointSize_ = _sz; }
/// get point size /// get point size
...@@ -226,7 +248,7 @@ public: ...@@ -226,7 +248,7 @@ public:
void lineSmooth(bool _b) { linesSmooth_ = _b; } void lineSmooth(bool _b) { linesSmooth_ = _b; }
/// get: rsmooth lines enabled /// get: rsmooth lines enabled
bool lineSmooth() const { return linesSmooth_; } bool lineSmooth() const { return linesSmooth_; }
/// enable alpha test (draw pixels if alpha >= _clip) /// enable alpha test (draw pixels if alpha >= _clip)
void enableAlphaTest(float _clip) { void enableAlphaTest(float _clip) {
alphaTest_ = true; alphaClip_ = _clip; alphaTest_ = true; alphaClip_ = _clip;
...@@ -237,7 +259,7 @@ public: ...@@ -237,7 +259,7 @@ public:
/// Return state of Alpha test /// Return state of Alpha test
bool alphaTest() const { return alphaTest_; }; bool alphaTest() const { return alphaTest_; };
/// Enable Multisampling /// Enable Multisampling
void enableMultisampling() { void enableMultisampling() {
multiSampling_ = true; multiSampling_ = true;
...@@ -280,32 +302,36 @@ public: ...@@ -280,32 +302,36 @@ public:
/// disable backface culling (not active by default, see applyProperties) /// disable backface culling (not active by default, see applyProperties)
void disableBackfaceCulling() { backfaceCulling_ = false; } void disableBackfaceCulling() { backfaceCulling_ = false; }
bool isEmissive() const { return baseColor_[0] > 0.f || baseColor_[1] > 0.f || baseColor_[2] > 0.f; }
protected: protected:
Vec4f baseColor_; Vec4f baseColor_;
Vec4f ambientColor_; Vec4f ambientColor_;
Vec4f diffuseColor_; Vec4f diffuseColor_;
Vec4f specularColor_; Vec4f specularColor_;
Vec4f overlayColor_; Vec4f overlayColor_;
float shininess_; float shininess_;
int illum_;
double reflectance_; double reflectance_;
double indexOfRefraction_;
float pointSize_; float pointSize_;
float lineWidth_; float lineWidth_;
bool roundPoints_; bool roundPoints_;
bool linesSmooth_; bool linesSmooth_;
bool alphaTest_; bool alphaTest_;
float alphaClip_; float alphaClip_;
bool blending_; bool blending_;
GLenum blendParam1_; GLenum blendParam1_;
GLenum blendParam2_; GLenum blendParam2_;
bool colorMaterial_; bool colorMaterial_;
bool backfaceCulling_; bool backfaceCulling_;
bool multiSampling_; bool multiSampling_;
}; };
...@@ -355,8 +381,8 @@ public: ...@@ -355,8 +381,8 @@ public:
/// Default constructor. Applies all properties. /// Default constructor. Applies all properties.
MaterialNode( BaseNode* _parent = 0, MaterialNode( BaseNode* _parent = 0,
const std::string& _name = "<MaterialNode>", const std::string& _name = "<MaterialNode>",
unsigned int _applyProperties = (All & ~BackFaceCulling)); unsigned int _applyProperties = (All & ~BackFaceCulling));
/// Destructor. /// Destructor.
virtual ~MaterialNode() {}; virtual ~MaterialNode() {};
...@@ -394,7 +420,7 @@ public: ...@@ -394,7 +420,7 @@ public:
void set_color(const Vec4f& _c) { void set_color(const Vec4f& _c) {
material_.color(_c); material_.color(_c);
} }
/// Generates a random color and sets it /// Generates a random color and sets it
void set_random_color() { void set_random_color() {
material_.generateRandomColor(); material_.generateRandomColor();
...@@ -405,6 +431,11 @@ public: ...@@ -405,6 +431,11 @@ public:
/// get the base color /// get the base color
const Vec4f& base_color() const { return material_.baseColor(); } const Vec4f& base_color() const { return material_.baseColor(); }
/// set emission
void set_emission(const Vec4f& _c) { material_.baseColor(_c); }
/// get emission
const Vec4f& emission() const { return material_.baseColor(); }
/// set the ambient color. /// set the ambient color.
void set_ambient_color(const Vec4f& _a) { material_.ambientColor(_a); } void set_ambient_color(const Vec4f& _a) { material_.ambientColor(_a); }
/// get the ambient color. /// get the ambient color.
...@@ -438,12 +469,22 @@ public: ...@@ -438,12 +469,22 @@ public:
void set_shininess(float _s) { material_.shininess(_s); } void set_shininess(float _s) { material_.shininess(_s); }
/// get shininess /// get shininess
float shininess() const { return material_.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 /// set reflectance
void set_reflectance(double _m) { material_.reflectance(_m); } void set_reflectance(double _m) { material_.reflectance(_m); }
/// get reflectance /// get reflectance
double reflectance() const { return material_.reflectance(); } double reflectance() const { return material_.reflectance(); }
/// set index of refraction
void set_indexOfRefraction(double _m) { material_.indexOfRefraction(_m); }
/// get index of refraction
double indexOfRefraction() const { return material_.indexOfRefraction(); }
/** @} */ /** @} */
//=========================================================================== //===========================================================================
...@@ -517,7 +558,7 @@ public: ...@@ -517,7 +558,7 @@ public:
/// enable blending with Parameters (_p1, _p2) /// enable blending with Parameters (_p1, _p2)
void enable_blending(GLenum _p1 = GL_SRC_ALPHA, void enable_blending(GLenum _p1 = GL_SRC_ALPHA,
GLenum _p2 = GL_ONE_MINUS_SRC_ALPHA) { GLenum _p2 = GL_ONE_MINUS_SRC_ALPHA) {
material_.enableBlending(_p1, _p2); material_.enableBlending(_p1, _p2);
} }
/// disable blending /// disable blending
...@@ -527,7 +568,7 @@ public: ...@@ -527,7 +568,7 @@ public:
/// enable backface culling (not active by default, see applyProperties) /// enable backface culling (not active by default, see applyProperties)
void enable_backface_culling() { material_.enableBackfaceCulling(); } void enable_backface_culling() { material_.enableBackfaceCulling(); }
/// disable backface culling (not active by default, see applyProperties) /// disable backface culling (not active by default, see applyProperties)
void disable_backface_culling() { material_.disableBackfaceCulling(); } void disable_backface_culling() { material_.disableBackfaceCulling(); }
...@@ -538,10 +579,10 @@ public: ...@@ -538,10 +579,10 @@ public:
void applyProperties(unsigned int _applyProperties) { void applyProperties(unsigned int _applyProperties) {
applyProperties_ = _applyProperties; applyProperties_ = _applyProperties;
} }
/// Get material object reference /// Get material object reference
ACG::SceneGraph::Material& material() { return material_; } ACG::SceneGraph::Material& material() { return material_; }
/// Set material object /// Set material object
void set_material(const ACG::SceneGraph::Material& _m) { material_ = _m; } void set_material(const ACG::SceneGraph::Material& _m) { material_ = _m; }
......
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