diff --git a/src/Platform/GlutApplication.h b/src/Platform/GlutApplication.h index 56f0ff885..d476ebcc6 100644 --- a/src/Platform/GlutApplication.h +++ b/src/Platform/GlutApplication.h @@ -91,10 +91,11 @@ class GlutApplication { /** * @brief Draw event * - * Here implement your drawing functions, such as calling - * SceneGraph::AbstractCamera::draw(). After drawing is finished, call - * swapBuffers(). If you want to draw immediately again, call also - * redraw(). + * Called when the screen is redrawn. You should clean the framebuffer + * using Framebuffer::clear() and then add your own drawing functions, + * such as calling SceneGraph::AbstractCamera::draw(). After drawing + * is finished, call swapBuffers(). If you want to draw immediately + * again, call also redraw(). */ virtual void drawEvent() = 0; diff --git a/src/SceneGraph/AbstractObject.h b/src/SceneGraph/AbstractObject.h index 82b7514aa..e896314ec 100644 --- a/src/SceneGraph/AbstractObject.h +++ b/src/SceneGraph/AbstractObject.h @@ -35,7 +35,14 @@ Provides minimal interface for features, not depending on object transformation implementation. This class is not directly instantiatable, use Object subclass instead. See also @ref scenegraph for more information. -Uses Corrade::Containers::LinkedList for storing features. +Uses Corrade::Containers::LinkedList for storing features. Traversing through +the list is done like in the following code. It is also possible to go in +reverse order using lastFeature() and AbstractFeature::previousFeature(). +@code +for(AbstractFeature* feature = o->firstFeature(); feature; feature = feature->nextFeature()) { + // ... +} +@endcode @see AbstractObject2D, AbstractObject3D */ diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index afd256878..a9ea6f48c 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -50,6 +50,13 @@ care of parent/children relationship and contains features. See @ref scenegraph for introduction. Uses Corrade::Containers::LinkedList for parent/children relationship. +Traversing through the list is done like in the following code. It is also +possible to go in reverse order using lastChild() and previousSibling(). +@code +for(Object* child = o->firstChild(); child; child = child->nextSibling()) { + // ... +} +@endcode @section Object-explicit-specializations Explicit template specializations diff --git a/src/Shaders/PhongShader.cpp b/src/Shaders/PhongShader.cpp index 394243dcb..8ca78b44d 100644 --- a/src/Shaders/PhongShader.cpp +++ b/src/Shaders/PhongShader.cpp @@ -58,8 +58,17 @@ PhongShader::PhongShader() { shininessUniform = uniformLocation("shininess"); transformationMatrixUniform = uniformLocation("transformationMatrix"); projectionMatrixUniform = uniformLocation("projectionMatrix"); + normalMatrixUniform = uniformLocation("normalMatrix"); lightUniform = uniformLocation("light"); lightColorUniform = uniformLocation("lightColor"); + + /* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */ + #ifdef MAGNUM_TARGET_GLES + setAmbientColor({}); + setSpecularColor(Vector3(1.0f)); + setLightColor(Vector3(1.0f)); + setShininess(80.0f); + #endif } }} diff --git a/src/Shaders/PhongShader.frag b/src/Shaders/PhongShader.frag index aa8125401..3bb1080ac 100644 --- a/src/Shaders/PhongShader.frag +++ b/src/Shaders/PhongShader.frag @@ -3,11 +3,18 @@ #define color gl_FragColor #endif -uniform lowp vec3 ambientColor = vec3(0.0, 0.0, 0.0); uniform lowp vec3 diffuseColor; +#ifndef GL_ES +uniform lowp vec3 ambientColor = vec3(0.0, 0.0, 0.0); uniform lowp vec3 specularColor = vec3(1.0, 1.0, 1.0); uniform lowp vec3 lightColor = vec3(1.0, 1.0, 1.0); uniform mediump float shininess = 80.0; +#else +uniform lowp vec3 ambientColor; +uniform lowp vec3 specularColor; +uniform lowp vec3 lightColor; +uniform mediump float shininess; +#endif in mediump vec3 transformedNormal; in highp vec3 lightDirection; @@ -29,7 +36,7 @@ void main() { color.rgb += diffuseColor*lightColor*intensity; /* Add specular color, if needed */ - if(intensity != 0) { + if(intensity > 0.001) { highp vec3 reflection = reflect(-normalizedLightDirection, normalizedTransformedNormal); mediump float specularity = pow(max(0.0, dot(normalize(cameraDirection), reflection)), shininess); color.rgb += specularColor*specularity; diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index 5662c8f34..efccc6f88 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -84,11 +84,12 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { } /** - * @brief Set transformation matrix + * @brief Set transformation matrix and normal matrix * @return Pointer to self (for method chaining) */ inline PhongShader* setTransformation(const Matrix4& matrix) { setUniform(transformationMatrixUniform, matrix); + setUniform(normalMatrixUniform, matrix.rotation()); return this; } @@ -128,6 +129,7 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { shininessUniform, transformationMatrixUniform, projectionMatrixUniform, + normalMatrixUniform, lightUniform, lightColorUniform; }; diff --git a/src/Shaders/PhongShader.vert b/src/Shaders/PhongShader.vert index b544d63f8..066afd94d 100644 --- a/src/Shaders/PhongShader.vert +++ b/src/Shaders/PhongShader.vert @@ -5,6 +5,7 @@ uniform highp mat4 transformationMatrix; uniform highp mat4 projectionMatrix; +uniform mediump mat3 normalMatrix; uniform highp vec3 light; #ifdef EXPLICIT_ATTRIB_LOCATION @@ -25,7 +26,7 @@ void main() { highp vec3 transformedPosition = transformedPosition4.xyz/transformedPosition4.w; /* Transformed normal vector */ - transformedNormal = normalize(mat3x3(transformationMatrix)*normal); + transformedNormal = normalMatrix*normal; /* Direction to the light */ lightDirection = normalize(light - transformedPosition);