Browse Source

Merge branch 'master' into compatibility

Vladimír Vondruš 14 years ago
parent
commit
a1ff38bc86
  1. 9
      src/Platform/GlutApplication.h
  2. 9
      src/SceneGraph/AbstractObject.h
  3. 7
      src/SceneGraph/Object.h
  4. 9
      src/Shaders/PhongShader.cpp
  5. 11
      src/Shaders/PhongShader.frag
  6. 4
      src/Shaders/PhongShader.h
  7. 3
      src/Shaders/PhongShader.vert

9
src/Platform/GlutApplication.h

@ -91,10 +91,11 @@ class GlutApplication {
/** /**
* @brief Draw event * @brief Draw event
* *
* Here implement your drawing functions, such as calling * Called when the screen is redrawn. You should clean the framebuffer
* SceneGraph::AbstractCamera::draw(). After drawing is finished, call * using Framebuffer::clear() and then add your own drawing functions,
* swapBuffers(). If you want to draw immediately again, call also * such as calling SceneGraph::AbstractCamera::draw(). After drawing
* redraw(). * is finished, call swapBuffers(). If you want to draw immediately
* again, call also redraw().
*/ */
virtual void drawEvent() = 0; virtual void drawEvent() = 0;

9
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 implementation. This class is not directly instantiatable, use Object subclass
instead. See also @ref scenegraph for more information. 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 @see AbstractObject2D, AbstractObject3D
*/ */

7
src/SceneGraph/Object.h

@ -50,6 +50,13 @@ care of parent/children relationship and contains features. See @ref scenegraph
for introduction. for introduction.
Uses Corrade::Containers::LinkedList for parent/children relationship. 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 @section Object-explicit-specializations Explicit template specializations

9
src/Shaders/PhongShader.cpp

@ -58,8 +58,17 @@ PhongShader::PhongShader() {
shininessUniform = uniformLocation("shininess"); shininessUniform = uniformLocation("shininess");
transformationMatrixUniform = uniformLocation("transformationMatrix"); transformationMatrixUniform = uniformLocation("transformationMatrix");
projectionMatrixUniform = uniformLocation("projectionMatrix"); projectionMatrixUniform = uniformLocation("projectionMatrix");
normalMatrixUniform = uniformLocation("normalMatrix");
lightUniform = uniformLocation("light"); lightUniform = uniformLocation("light");
lightColorUniform = uniformLocation("lightColor"); 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
} }
}} }}

11
src/Shaders/PhongShader.frag

@ -3,11 +3,18 @@
#define color gl_FragColor #define color gl_FragColor
#endif #endif
uniform lowp vec3 ambientColor = vec3(0.0, 0.0, 0.0);
uniform lowp vec3 diffuseColor; 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 specularColor = vec3(1.0, 1.0, 1.0);
uniform lowp vec3 lightColor = vec3(1.0, 1.0, 1.0); uniform lowp vec3 lightColor = vec3(1.0, 1.0, 1.0);
uniform mediump float shininess = 80.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 mediump vec3 transformedNormal;
in highp vec3 lightDirection; in highp vec3 lightDirection;
@ -29,7 +36,7 @@ void main() {
color.rgb += diffuseColor*lightColor*intensity; color.rgb += diffuseColor*lightColor*intensity;
/* Add specular color, if needed */ /* Add specular color, if needed */
if(intensity != 0) { if(intensity > 0.001) {
highp vec3 reflection = reflect(-normalizedLightDirection, normalizedTransformedNormal); highp vec3 reflection = reflect(-normalizedLightDirection, normalizedTransformedNormal);
mediump float specularity = pow(max(0.0, dot(normalize(cameraDirection), reflection)), shininess); mediump float specularity = pow(max(0.0, dot(normalize(cameraDirection), reflection)), shininess);
color.rgb += specularColor*specularity; color.rgb += specularColor*specularity;

4
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) * @return Pointer to self (for method chaining)
*/ */
inline PhongShader* setTransformation(const Matrix4& matrix) { inline PhongShader* setTransformation(const Matrix4& matrix) {
setUniform(transformationMatrixUniform, matrix); setUniform(transformationMatrixUniform, matrix);
setUniform(normalMatrixUniform, matrix.rotation());
return this; return this;
} }
@ -128,6 +129,7 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram {
shininessUniform, shininessUniform,
transformationMatrixUniform, transformationMatrixUniform,
projectionMatrixUniform, projectionMatrixUniform,
normalMatrixUniform,
lightUniform, lightUniform,
lightColorUniform; lightColorUniform;
}; };

3
src/Shaders/PhongShader.vert

@ -5,6 +5,7 @@
uniform highp mat4 transformationMatrix; uniform highp mat4 transformationMatrix;
uniform highp mat4 projectionMatrix; uniform highp mat4 projectionMatrix;
uniform mediump mat3 normalMatrix;
uniform highp vec3 light; uniform highp vec3 light;
#ifdef EXPLICIT_ATTRIB_LOCATION #ifdef EXPLICIT_ATTRIB_LOCATION
@ -25,7 +26,7 @@ void main() {
highp vec3 transformedPosition = transformedPosition4.xyz/transformedPosition4.w; highp vec3 transformedPosition = transformedPosition4.xyz/transformedPosition4.w;
/* Transformed normal vector */ /* Transformed normal vector */
transformedNormal = normalize(mat3x3(transformationMatrix)*normal); transformedNormal = normalMatrix*normal;
/* Direction to the light */ /* Direction to the light */
lightDirection = normalize(light - transformedPosition); lightDirection = normalize(light - transformedPosition);

Loading…
Cancel
Save