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
*
* 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;

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
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
*/

7
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

9
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
}
}}

11
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;

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)
*/
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;
};

3
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);

Loading…
Cancel
Save