Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEvan Goers <mega@osirion.org>2012-01-24 06:44:19 +0000
committerEvan Goers <mega@osirion.org>2012-01-24 06:44:19 +0000
commit5d4e993e485ae3432eabb45caf4e4d43c9bc54e6 (patch)
tree2369f024c56e9211d95d10bc86d3220f21443137 /src
parentd20adb868fe02e9e7aa8a262b3cd4c5dd01d5eea (diff)
Added a 'specular' material parameter. Defaults to 'color' values.
Tweaked lighting a bit.
Diffstat (limited to 'src')
-rw-r--r--src/model/material.cc20
-rw-r--r--src/model/material.h6
-rw-r--r--src/render/draw.cc6
-rw-r--r--src/render/gl.cc5
-rw-r--r--src/render/gl.h3
-rw-r--r--src/render/state.cc34
-rwxr-xr-xsrc/ui/modelview.cc12
7 files changed, 56 insertions, 30 deletions
diff --git a/src/model/material.cc b/src/model/material.cc
index b76be02..ff9a257 100644
--- a/src/model/material.cc
+++ b/src/model/material.cc
@@ -21,6 +21,7 @@ Material::Registry Material::material_registry;
Material::Material(const std::string &name) :
material_name(name),
material_color(1.0f) ,
+ material_specular(1.0f) ,
material_size(64.0f, 64.0f)
{
aux::to_lowercase(material_name);
@@ -90,6 +91,11 @@ void Material::set_color(const math::Color &color)
//material_color.a = 1.0f;
}
+void Material::set_specular(const math::Color &color)
+{
+ material_specular.assign(color);
+}
+
void Material::set_texture(const std::string &texture)
{
if (texture.size()) {
@@ -227,6 +233,20 @@ void Material::load_shader(const std::string &shadername)
a = 1.0f;
}
material->set_color(math::Color(r, g, b, a));
+ // set specular too, preserving the old behavior
+ material->set_specular(math::Color(r, g, b, a));
+ }
+ } else if (firstword.compare("specular") == 0) {
+ if (linestream >> r >> g >> b) {
+ if (math::max(r, math::max(g, b)) > 1.0f) {
+ r /= 255.0f;
+ g /= 255.0f;
+ b /= 255.0f;
+ }
+ if (!(linestream >> a)) {
+ a = 1.0f;
+ }
+ material->set_specular(math::Color(r, g, b, a));
}
} else if (firstword.compare("engine") == 0) {
material->set_flags(Engine);
diff --git a/src/model/material.h b/src/model/material.h
index b128954..2c66aae 100644
--- a/src/model/material.h
+++ b/src/model/material.h
@@ -45,6 +45,10 @@ public:
return material_color;
}
+ inline const math::Color &specular() const {
+ return material_specular;
+ }
+
inline const unsigned int flags() const {
return material_flags;
}
@@ -90,6 +94,7 @@ public:
/* ---- mutators ------------------------------------------- */
void set_color(const math::Color &color);
+ void set_specular(const math::Color &specular);
/**
* @brief set the material texture name
*/
@@ -157,6 +162,7 @@ private:
std::string material_name;
math::Color material_color;
+ math::Color material_specular;
unsigned int material_flags;
std::string material_texture;
size_t material_texture_id;
diff --git a/src/render/draw.cc b/src/render/draw.cc
index e40e3cc..ec4f386 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -124,15 +124,15 @@ void pass_prepare(float seconds)
zone_light[i] = globe->location()[i];
zone_color[i] = globe->color()[i];
ambient_light[i] = globe->color()[i] * 0.1;
- diffuse_light[i] = globe->color()[i] * 0.8;
- specular_light[i] = globe->color()[i] * 0.4;
+ diffuse_light[i] = globe->color()[i] * 0.75;
+ specular_light[i] = globe->color()[i] * 0.75;
}
zone_light[3] = 1.0f;
ambient_light[3] = 1.0f;
diffuse_light[3] = 1.0f;
specular_light[3] = 1.0f;
- glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, ((globe->color()[0] + globe->color()[1] + globe->color()[2]) / 3.0f) * 0.0001f);
+ glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, ((globe->color()[0] + globe->color()[1] + globe->color()[2]) / 3.0f) * 0.00025f);
glLightfv(GL_LIGHT0, GL_POSITION, zone_light);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light);
diff --git a/src/render/gl.cc b/src/render/gl.cc
index 3c672cd..48b9b52 100644
--- a/src/render/gl.cc
+++ b/src/render/gl.cc
@@ -223,6 +223,11 @@ void color(Color const & color)
glColor4fv(color.ptr());
}
+void specular(Color const & specular)
+{
+ glMaterialfv(GL_FRONT, GL_SPECULAR, specular.ptr());
+}
+
void matrixmode(GLenum mode)
{
glMatrixMode(mode);
diff --git a/src/render/gl.h b/src/render/gl.h
index 31609ad..4dea544 100644
--- a/src/render/gl.h
+++ b/src/render/gl.h
@@ -235,6 +235,9 @@ void color(math::Color const & color);
*/
void color(const float r, const float g, const float b, const float a = 1.0f);
+/// specify the specular reflectivity color
+void specular(math::Color const & specular);
+
/// Push the current transformation matrix to the stack
void push();
diff --git a/src/render/state.cc b/src/render/state.cc
index dcf62f3..8d1f3b0 100644
--- a/src/render/state.cc
+++ b/src/render/state.cc
@@ -207,16 +207,18 @@ void State::set_power(const bool power)
void State::use_material(const model::Material * material) {
math::Color color;
+ math::Color specular;
reset();
- // material settings
+ // default specular shininess setting
glMateriali(GL_FRONT, GL_SHININESS, 8);
- GLfloat specular_reflectance[3];
if (!material) {
color.assign(1.0f, 0.0f, 1.0f);
+ specular.assign(1.0f, 0.0f, 1.0f);
gl::color(color);
+ gl::specular(specular);
return;
}
@@ -233,28 +235,37 @@ void State::use_material(const model::Material * material) {
// use current engine color
color.assign(state_color_engine);
+ specular.assign(0.0f);
} else if (material->flags() & model::Material::Tertiary) {
// use entity colors
if ((material->flags() & model::Material::Tertiary) == model::Material::Tertiary) {
- for (size_t i = 0; i < 3; i++)
+ for (size_t i = 0; i < 3; i++) {
color[i] = (state_color_primary[i] + state_color_secondary[i]) / 2;
+ specular[i] = (state_color_primary[i] + state_color_secondary[i]) / 2;
+ }
} else if ((material->flags() & model::Material::Secondary) == model::Material::Secondary) {
color.assign(state_color_secondary);
+ specular.assign(state_color_secondary);
} else if ((material->flags() & model::Material::Primary) == model::Material::Primary) {
color.assign(state_color_primary);
+ specular.assign(state_color_primary);
}
color.r *= material->color().r;
color.g *= material->color().g;
color.b *= material->color().b;
-
+ specular.r *= material->specular().r;
+ specular.g *= material->specular().g;
+ specular.b *= material->specular().b;
+
} else {
// use material color
color.assign(material->color());
+ specular.assign(material->specular());
}
// lighted or fullbright
@@ -298,25 +309,12 @@ void State::use_material(const model::Material * material) {
} else {
color.assign(0.0f, 0.0f, 0.0f);
}
- specular_reflectance[0] = 1.0f;
- specular_reflectance[1] = 1.0f;
- specular_reflectance[2] = 1.0f;
-
glMateriali(GL_FRONT, GL_SHININESS, 4);
- glMaterialfv(GL_FRONT, GL_SPECULAR, specular_reflectance);
-
- gl::color(color);
- return;
}
}
- specular_reflectance[0] = color.r;
- specular_reflectance[1] = color.g;
- specular_reflectance[2] = color.b;
-
- glMaterialfv(GL_FRONT, GL_SPECULAR, specular_reflectance);
-
gl::color(color);
+ gl::specular(specular);
}
void State::reset() {
diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc
index ec840c1..65954d8 100755
--- a/src/ui/modelview.cc
+++ b/src/ui/modelview.cc
@@ -190,21 +190,15 @@ void ModelView::draw()
// we set up the light in camera space
GLfloat modelview_light[] = { -10.0f * model->radius(), 0, 0, 1.0f };
GLfloat ambient_light[] = { 0.1f, 0.1f, 0.1f, 1.0f };
- GLfloat diffuse_light[4];
- GLfloat specular_light[4];
- for (size_t i = 0; i < 3; i++) {
- diffuse_light[i] = 0.8f;
- specular_light[i] = 0.4f;
- }
- diffuse_light[3] = 1.0f;
- specular_light[3] = 1.0f;
+ GLfloat diffuse_light[] = { 0.75f, 0.75f, 0.75f, 1.0f };
+ GLfloat specular_light[] = { 0.75f, 0.75f, 0.75f, 1.0f };
glLightfv(GL_LIGHT1, GL_POSITION, modelview_light);
glLightfv(GL_LIGHT1, GL_AMBIENT, ambient_light);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_light);
glLightfv(GL_LIGHT1, GL_SPECULAR, specular_light);
- glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.05f);
+ glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.75f);
gl::enable(GL_LIGHT1);