Commit 3b79dc5f authored by Jan Möbius's avatar Jan Möbius

Merge branch 'featurephysicallyBasedMaterial' into 'master'

extend the materialNode class with refractive materials

See merge request !47
parents 9f14f881 51538514
......@@ -134,7 +134,7 @@ GLState::GLState(bool _updateGL, bool _compatibilityProfile)
glheight_(2),
near_plane_(1.0),
far_plane_(100.0),
multisampling_(false),
multisampling_(false),
allow_multisampling_(true),
mipmapping_(true),
updateGL_(_updateGL),
......@@ -198,9 +198,9 @@ void GLState::initialize()
// Get max number of texture units
GLint value;
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &value);
num_texture_units_ = value;
// lighting
set_twosided_lighting(true);
}
......@@ -399,8 +399,8 @@ void GLState::set_modelview(const GLMatrixd& _m, const GLMatrixd& _inv_m)
void GLState::ortho( double _left, double _right,
double _bottom, double _top,
double _n, double _f )
double _bottom, double _top,
double _n, double _f )
{
near_plane_ = _n;
far_plane_ = _f;
......@@ -422,8 +422,8 @@ void GLState::ortho( double _left, double _right,
void GLState::frustum( double _left, double _right,
double _bottom, double _top,
double _n, double _f )
double _bottom, double _top,
double _n, double _f )
{
near_plane_ = _n;
far_plane_ = _f;
......@@ -445,7 +445,7 @@ void GLState::frustum( double _left, double _right,
void GLState::perspective( double _fovY, double _aspect,
double _n, double _f )
double _n, double _f )
{
near_plane_ = _n;
far_plane_ = _f;
......@@ -467,8 +467,8 @@ void GLState::perspective( double _fovY, double _aspect,
void GLState::viewport( int _left, int _bottom,
int _width, int _height,
int _glwidth, int _glheight)
int _width, int _height,
int _glwidth, int _glheight)
{
left_ = _left;
bottom_ = _bottom;
......@@ -512,8 +512,8 @@ void GLState::viewport( int _left, int _bottom,
void GLState::lookAt( const Vec3d& _eye,
const Vec3d& _center,
const Vec3d& _up )
const Vec3d& _center,
const Vec3d& _up )
{
modelview_.lookAt(_eye, _center, _up);
inverse_modelview_.inverse_lookAt(_eye, _center, _up);
......@@ -530,7 +530,7 @@ void GLState::lookAt( const Vec3d& _eye,
void GLState::translate( double _x, double _y, double _z,
MultiplyFrom _mult_from )
MultiplyFrom _mult_from )
{
if (_mult_from == MULT_FROM_RIGHT)
{
......@@ -561,7 +561,7 @@ void GLState::translate( Vec3d _vector,
void GLState::rotate( double _angle, double _x, double _y, double _z,
MultiplyFrom _mult_from )
MultiplyFrom _mult_from )
{
if (_mult_from == MULT_FROM_RIGHT)
{
......@@ -586,7 +586,7 @@ void GLState::rotate( double _angle, double _x, double _y, double _z,
void GLState::scale( double _sx, double _sy, double _sz,
MultiplyFrom _mult_from )
MultiplyFrom _mult_from )
{
if (_mult_from == MULT_FROM_RIGHT)
{
......@@ -611,7 +611,7 @@ void GLState::scale( double _sx, double _sy, double _sz,
void GLState::mult_matrix( const GLMatrixd& _m, const GLMatrixd& _inv_m,
MultiplyFrom _mult_from )
MultiplyFrom _mult_from )
{
if (_mult_from == MULT_FROM_RIGHT)
{
......@@ -891,7 +891,7 @@ Vec3d GLState::eye() const
Vec3d GLState::viewing_direction(int _x, int _y) const
{
Vec3d dir = ( unproject(Vec3d(_x, _y, 1.0)) -
unproject(Vec3d(_x, _y, 0.0)) );
unproject(Vec3d(_x, _y, 0.0)) );
dir.normalize();
return dir;
}
......@@ -903,7 +903,7 @@ Vec3d GLState::viewing_direction(int _x, int _y) const
Vec3d GLState::up() const
{
Vec3d dir( unproject(Vec3d(0.5*width_, height_-1, 0.0)) -
unproject(Vec3d(0.5*width_, 0.5*height_, 0.0)) );
unproject(Vec3d(0.5*width_, 0.5*height_, 0.0)) );
dir.normalize();
return dir;
}
......@@ -915,7 +915,7 @@ Vec3d GLState::up() const
Vec3d GLState::right() const
{
Vec3d dir( unproject(Vec3d(width_-1, 0.5*height_, 0.0)) -
unproject(Vec3d(0.5*width_, 0.5*height_, 0.0)) );
unproject(Vec3d(0.5*width_, 0.5*height_, 0.0)) );
dir.normalize();
return dir;
}
......@@ -925,7 +925,7 @@ Vec3d GLState::right() const
void GLState::viewing_ray( int _x, int _y,
Vec3d& _origin, Vec3d& _direction) const
Vec3d& _origin, Vec3d& _direction) const
{
_origin = unproject(Vec3d(_x, _y, 0.0));
_direction = unproject(Vec3d(_x, _y, 1.0)) - _origin;
......@@ -1338,7 +1338,7 @@ void GLState::syncFromGL()
if (glIsEnabled(caps[i])) stateStack_.back().glStateEnabled_.set(caps[i]);
else stateStack_.back().glStateEnabled_.reset(caps[i]);
}
GLint getparam;
#ifdef GL_VERSION_1_4
......@@ -1364,9 +1364,9 @@ void GLState::syncFromGL()
glGetIntegerv(GL_BLEND_EQUATION_RGB, &getparam);
stateStack_.back().blendEquationState_ = getparam;
glGetFloatv(GL_BLEND_COLOR, stateStack_.back().blendColorState_);
glGetIntegerv(GL_ALPHA_TEST_FUNC, &getparam);
stateStack_.back().alphaFuncState_ = getparam;
......@@ -1381,7 +1381,7 @@ void GLState::syncFromGL()
GLenum bufGets[8] = {
GL_ARRAY_BUFFER_BINDING, GL_ARRAY_BUFFER,
GL_ELEMENT_ARRAY_BUFFER_BINDING, GL_ELEMENT_ARRAY_BUFFER,
GL_ELEMENT_ARRAY_BUFFER_BINDING, GL_ELEMENT_ARRAY_BUFFER,
GL_PIXEL_PACK_BUFFER_BINDING, GL_PIXEL_PACK_BUFFER,
GL_PIXEL_UNPACK_BUFFER_BINDING, GL_PIXEL_UNPACK_BUFFER};
......@@ -1452,7 +1452,7 @@ void GLState::syncFromGL()
GL_TEXTURE_COORD_ARRAY_SIZE, GL_TEXTURE_COORD_ARRAY_TYPE,
GL_TEXTURE_COORD_ARRAY_STRIDE, GL_TEXTURE_COORD_ARRAY_POINTER};
GLStateContext::GLVertexPointer* ptrs[] = {&stateStack_.back().vertexPointer_,
GLStateContext::GLVertexPointer* ptrs[] = {&stateStack_.back().vertexPointer_,
&stateStack_.back().colorPointer_, &stateStack_.back().texcoordPointer_};
for (int i = 0; i < 3 ; ++i)
......@@ -1743,7 +1743,7 @@ void GLState::depthRange(GLclampd _zNear, GLclampd _zFar)
{
if (!depthRangeLock_)
{
#ifdef GLSTATE_AVOID_REDUNDANT_GLCALLS
#ifdef GLSTATE_AVOID_REDUNDANT_GLCALLS
if (abs(_zNear - stateStack_.back().depthRange_[0]) > 1e-6 ||
abs(_zFar - stateStack_.back().depthRange_[1]) > 1e-6)
#endif
......
......@@ -142,6 +142,8 @@ QString Material::serializeToJson() const {
matMap["overlayColor"] = col2vl(overlayColor_);
matMap["shininess"] = shininess_;
matMap["reflectance"] = reflectance_;
matMap["indexOfRefraction"] = indexOfRefraction_;
matMap["isRefractive"] = isRefractive_;
matMap["pointSize"] = pointSize_;
matMap["lineWidth"] = lineWidth_;
matMap["roundPoints"] = roundPoints_;
......@@ -178,6 +180,8 @@ void Material::deserializeFromVariantMap(const QVariantMap &matMap) {
if (matMap.contains("overlayColor")) overlayColor_ = vl2col(matMap["overlayColor"].toList());
if (matMap.contains("shininess")) shininess_ = matMap["shininess"].toFloat();
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();
......@@ -217,11 +221,11 @@ void MaterialNode::enter(GLState& _state, const DrawModes::DrawMode& _drawmode
if (applyProperties_ & Material)
{
materialBackup_.ambientColor_ = _state.ambient_color();
materialBackup_.diffuseColor_ = _state.diffuse_color();
materialBackup_.specularColor_ = _state.specular_color();
materialBackup_.overlayColor_ = _state.overlay_color();
materialBackup_.shininess_ = _state.shininess();
materialBackup_.ambientColor_ = _state.ambient_color();
materialBackup_.diffuseColor_ = _state.diffuse_color();
materialBackup_.specularColor_ = _state.specular_color();
materialBackup_.overlayColor_ = _state.overlay_color();
materialBackup_.shininess_ = _state.shininess();
_state.set_ambient_color(material_.ambientColor_);
_state.set_diffuse_color(material_.diffuseColor_);
......@@ -480,6 +484,7 @@ MaterialNode::read(std::istream& _is)
char s[200];
float x, y, z, u;
bool b;
while (_is && (!_is.eof()) && _is.getline(s,200) ) {
std::istringstream buffer(s);
......@@ -541,6 +546,22 @@ MaterialNode::read(std::istream& _is)
material_.shininess(x);
}
}
// Refractive
else if (specifier == "isRefractive") {
buffer >> b;
if (buffer.good()) {
material_.set_refractive(b);
}
}
// Refraction Index
else if (specifier == "indexOfRefraction") {
buffer >> x;
if (buffer.good()) {
material_.indexOfRefraction(x);
}
}
// PointSize
else if (specifier == "PointSize") {
buffer >> x;
......
......@@ -83,9 +83,9 @@ namespace SceneGraph {
**/
class ACGDLLEXPORT Material {
friend class MaterialNode;
public:
/// Default constructor
Material() :
......@@ -96,6 +96,8 @@ public:
overlayColor_(GLState::default_overlay_color),
shininess_(GLState::default_shininess),
reflectance_(0.0),
indexOfRefraction_(1.0),
isRefractive_(false),
pointSize_(1.0),
lineWidth_(1.0),
roundPoints_(false),
......@@ -108,10 +110,10 @@ public:
colorMaterial_(true),
backfaceCulling_(false),
multiSampling_(true) {};
/// Deconstructor
virtual ~Material() {};
/// Copy constructor
Material(const Material& _m) :
baseColor_(_m.baseColor_),
......@@ -121,6 +123,8 @@ public:
overlayColor_(_m.overlayColor_),
shininess_(_m.shininess_),
reflectance_(_m.reflectance_),
indexOfRefraction_(_m.indexOfRefraction_),
isRefractive_(_m.isRefractive_),
pointSize_(_m.pointSize_),
lineWidth_(_m.lineWidth_),
roundPoints_(_m.roundPoints_),
......@@ -138,7 +142,7 @@ public:
QString serializeToJson() const;
void deserializeFromJson(const QString &json);
void deserializeFromVariantMap(const QVariantMap &matMap);
/** \brief Set color based on _c
*
* Basecolor (which is the emitted color is set to zero)
......@@ -154,7 +158,7 @@ public:
c = _c * 0.6f; c[3]=_c[3]; diffuseColor(c);
c = _c * 0.8f; c[3]=_c[3]; specularColor(c);
}
/// Creates a randomized color and sets it
void generateRandomColor() {
color( Vec4f(0.2 + double(rand())/double(RAND_MAX)*0.8,
......@@ -163,11 +167,16 @@ public:
1.0));
}
/// set the base color
/// set the base color (Sets the baseColor which is the same as the emission(const Vec4f& _c) )
void baseColor(const Vec4f& _c) { baseColor_ = _c;}
/// get the base color
/// get the base color ( Same as emission() )
const Vec4f& baseColor() const { return baseColor_; }
/// set emission ( Same as baseColor( const Vec4f& _c )) )
void emissionColor(const Vec4f& _c) { baseColor_ = _c;}
/// get emission ( Same as baseColor() )
const Vec4f& emissionColor() const { return baseColor_; }
/// set the ambient color.
void ambientColor(const Vec4f& _a) { ambientColor_ = _a; }
/// get the ambient color.
......@@ -201,12 +210,22 @@ public:
void shininess(float _s) { shininess_ = _s; }
/// get shininess
float shininess() const { return shininess_; }
/// 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_; }
/// set refractive flag
void setRefractive(bool _r) { isRefractive_ = _r; }
/// get refractive flag
bool isRefractive() const {return isRefractive_;}
/// set point size (default: 1.0)
void pointSize(float _sz) { pointSize_ = _sz; }
/// get point size
......@@ -226,7 +245,7 @@ public:
void lineSmooth(bool _b) { linesSmooth_ = _b; }
/// get: rsmooth lines enabled
bool lineSmooth() const { return linesSmooth_; }
/// enable alpha test (draw pixels if alpha >= _clip)
void enableAlphaTest(float _clip) {
alphaTest_ = true; alphaClip_ = _clip;
......@@ -237,7 +256,7 @@ public:
/// Return state of Alpha test
bool alphaTest() const { return alphaTest_; };
/// Enable Multisampling
void enableMultisampling() {
multiSampling_ = true;
......@@ -280,32 +299,36 @@ 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); }
protected:
Vec4f baseColor_;
Vec4f ambientColor_;
Vec4f diffuseColor_;
Vec4f specularColor_;
Vec4f overlayColor_;
float shininess_;
double reflectance_;
double indexOfRefraction_;
bool isRefractive_;
float pointSize_;
float lineWidth_;
bool roundPoints_;
bool linesSmooth_;
bool alphaTest_;
float alphaClip_;
bool blending_;
GLenum blendParam1_;
GLenum blendParam2_;
bool colorMaterial_;
bool backfaceCulling_;
bool multiSampling_;
};
......@@ -355,8 +378,8 @@ public:
/// Default constructor. Applies all properties.
MaterialNode( BaseNode* _parent = 0,
const std::string& _name = "<MaterialNode>",
unsigned int _applyProperties = (All & ~BackFaceCulling));
const std::string& _name = "<MaterialNode>",
unsigned int _applyProperties = (All & ~BackFaceCulling));
/// Destructor.
virtual ~MaterialNode() {};
......@@ -394,17 +417,22 @@ public:
void set_color(const Vec4f& _c) {
material_.color(_c);
}
/// Generates a random color and sets it
void set_random_color() {
material_.generateRandomColor();
}
/// set the base color
/// set the base color ( Same as set_emission(const Vec4f& _c) )
void set_base_color(const Vec4f& _c) { material_.baseColor(_c); }
/// get the base color
/// get the base color ( same as emission() )
const Vec4f& base_color() const { return material_.baseColor(); }
/// set emission ( same as set_base_color(const Vec4f& _c) )
void set_emission(const Vec4f& _c) { material_.baseColor(_c); }
/// get emission ( same as base_color() )
const Vec4f& emission() const { return material_.baseColor(); }
/// set the ambient color.
void set_ambient_color(const Vec4f& _a) { material_.ambientColor(_a); }
/// get the ambient color.
......@@ -438,12 +466,22 @@ public:
void set_shininess(float _s) { material_.shininess(_s); }
/// get shininess
float shininess() const { return material_.shininess(); }
/// set reflectance
void set_reflectance(double _m) { material_.reflectance(_m); }
/// get 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(); }
/// set refractive flag
void set_refractive(bool _r) { material_.isRefractive_ = _r; }
/// get refractive flag
bool isRefractive() const {return material_.isRefractive_;}
/** @} */
//===========================================================================
......@@ -517,7 +555,7 @@ public:
/// enable blending with Parameters (_p1, _p2)
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);
}
/// disable blending
......@@ -527,7 +565,7 @@ public:
/// enable backface culling (not active by default, see applyProperties)
void enable_backface_culling() { material_.enableBackfaceCulling(); }
/// disable backface culling (not active by default, see applyProperties)
void disable_backface_culling() { material_.disableBackfaceCulling(); }
......@@ -538,10 +576,10 @@ public:
void applyProperties(unsigned int _applyProperties) {
applyProperties_ = _applyProperties;
}
/// Get material object reference
ACG::SceneGraph::Material& material() { return material_; }
/// Set material object
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