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