From 3b3a1642120dbe20a21ac1207a7023c564b2cebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 19 Nov 2012 15:10:53 +0100 Subject: [PATCH 1/4] Doc++ --- src/Platform/GlutApplication.h | 9 +++++---- src/SceneGraph/AbstractObject.h | 9 ++++++++- src/SceneGraph/Object.h | 7 +++++++ 3 files changed, 20 insertions(+), 5 deletions(-) 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 005ea1687..898dce20c 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 From 57f3175b06c496147b3d7d0d0737dbfd5e8276cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 19 Nov 2012 15:38:13 +0100 Subject: [PATCH 2/4] Shaders: GLSL ES doesn't have default values for uniforms. If targetting GLSL ES the values are set on initialization explicitly from application. --- src/Shaders/PhongShader.cpp | 8 ++++++++ src/Shaders/PhongShader.frag | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Shaders/PhongShader.cpp b/src/Shaders/PhongShader.cpp index 394243dcb..60be3eb89 100644 --- a/src/Shaders/PhongShader.cpp +++ b/src/Shaders/PhongShader.cpp @@ -60,6 +60,14 @@ PhongShader::PhongShader() { projectionMatrixUniform = uniformLocation("projectionMatrix"); 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..41d756b0d 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; From 69ee2f3ebb064427e80c40df01148899d09968d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 19 Nov 2012 16:20:36 +0100 Subject: [PATCH 3/4] Shaders: don't compare ints and floats. Fails on GLSL ES. --- src/Shaders/PhongShader.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shaders/PhongShader.frag b/src/Shaders/PhongShader.frag index 41d756b0d..3bb1080ac 100644 --- a/src/Shaders/PhongShader.frag +++ b/src/Shaders/PhongShader.frag @@ -36,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; From 308a92a9119badb67875b10d036687cc69a88421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 19 Nov 2012 16:20:59 +0100 Subject: [PATCH 4/4] Shaders: pass normal matrix the right way. Besides that this was long overdue, GLSL ES doesn't have mat3x3(). --- src/Shaders/PhongShader.cpp | 1 + src/Shaders/PhongShader.h | 4 +++- src/Shaders/PhongShader.vert | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Shaders/PhongShader.cpp b/src/Shaders/PhongShader.cpp index 60be3eb89..8ca78b44d 100644 --- a/src/Shaders/PhongShader.cpp +++ b/src/Shaders/PhongShader.cpp @@ -58,6 +58,7 @@ PhongShader::PhongShader() { shininessUniform = uniformLocation("shininess"); transformationMatrixUniform = uniformLocation("transformationMatrix"); projectionMatrixUniform = uniformLocation("projectionMatrix"); + normalMatrixUniform = uniformLocation("normalMatrix"); lightUniform = uniformLocation("light"); lightColorUniform = uniformLocation("lightColor"); 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);