From 8388255542bf7a340930a64e5a29ed857a520730 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 14 May 2014 15:29:16 -0700 Subject: [PATCH 1/7] Working on alternate IK mode. --- interface/src/Menu.cpp | 1 + interface/src/Menu.h | 1 + interface/src/avatar/SkeletonModel.cpp | 9 ++++++++- interface/src/avatar/SkeletonModel.h | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 2daf5b0240..7c8f1d75a9 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -351,6 +351,7 @@ Menu::Menu() : addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::HandsCollideWithSelf, 0, false); addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::ShowIKConstraints, 0, false); addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::AlignForearmsWithWrists, 0, true); + addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::AlternateIK, 0, false); addDisabledActionAndSeparator(developerMenu, "Testing"); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 230584bf07..2a521bf59c 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -267,6 +267,7 @@ private: namespace MenuOption { const QString AboutApp = "About Interface"; const QString AlignForearmsWithWrists = "Align Forearms with Wrists"; + const QString AlternateIK = "Alternate IK"; const QString AmbientOcclusion = "Ambient Occlusion"; const QString Atmosphere = "Atmosphere"; const QString Attachments = "Attachments..."; diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index e48ebfa63c..1e57481c66 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -176,7 +176,10 @@ void SkeletonModel::applyPalmData(int jointIndex, PalmData& palm) { palmRotation = rotationBetween(palmRotation * glm::vec3(-sign, 0.0f, 0.0f), direction) * palmRotation; // set hand position, rotation - if (Menu::getInstance()->isOptionChecked(MenuOption::AlignForearmsWithWrists)) { + if (Menu::getInstance()->isOptionChecked(MenuOption::AlternateIK)) { + setHandPosition(jointIndex, palm.getPosition(), palmRotation); + + } else if (Menu::getInstance()->isOptionChecked(MenuOption::AlignForearmsWithWrists)) { glm::vec3 forearmVector = palmRotation * glm::vec3(sign, 0.0f, 0.0f); setJointPosition(parentJointIndex, palm.getPosition() + forearmVector * geometry.joints.at(jointIndex).distanceToParent * extractUniformScale(_scale)); @@ -276,3 +279,7 @@ void SkeletonModel::renderJointConstraints(int jointIndex) { glLineWidth(1.0f); } +void SkeletonModel::setHandPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation) { + +} + diff --git a/interface/src/avatar/SkeletonModel.h b/interface/src/avatar/SkeletonModel.h index 20384829ea..77e6ea33d4 100644 --- a/interface/src/avatar/SkeletonModel.h +++ b/interface/src/avatar/SkeletonModel.h @@ -51,6 +51,7 @@ protected: private: void renderJointConstraints(int jointIndex); + void setHandPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation); Avatar* _owningAvatar; }; From 7bee0478be2f53fdb8016f5576c0a45fa3d458e7 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 15 May 2014 11:30:09 -0700 Subject: [PATCH 2/7] More work on integrating IK solution from Sixense. --- interface/src/avatar/SkeletonModel.cpp | 52 +++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 1e57481c66..1921094a0f 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -164,7 +164,8 @@ void SkeletonModel::applyPalmData(int jointIndex, PalmData& palm) { // rotate palm to align with its normal (normal points out of hand's palm) glm::quat palmRotation; - if (Menu::getInstance()->isOptionChecked(MenuOption::AlignForearmsWithWrists)) { + if (!Menu::getInstance()->isOptionChecked(MenuOption::AlternateIK) && + Menu::getInstance()->isOptionChecked(MenuOption::AlignForearmsWithWrists)) { getJointRotation(parentJointIndex, palmRotation, true); } else { getJointRotation(jointIndex, palmRotation, true); @@ -280,6 +281,55 @@ void SkeletonModel::renderJointConstraints(int jointIndex) { } void SkeletonModel::setHandPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation) { + // this algorithm is from sample code from sixense + const FBXGeometry& geometry = _geometry->getFBXGeometry(); + int elbowJointIndex = geometry.joints.at(jointIndex).parentIndex; + if (elbowJointIndex == -1) { + return; + } + int shoulderJointIndex = geometry.joints.at(elbowJointIndex).parentIndex; + glm::vec3 shoulderPosition; + if (!getJointPosition(shoulderJointIndex, shoulderPosition)) { + return; + } + // precomputed lengths + float scale = extractUniformScale(_scale); + float upperArmLength = geometry.joints.at(elbowJointIndex).distanceToParent * scale; + float lowerArmLength = geometry.joints.at(jointIndex).distanceToParent * scale; + // first set wrist position + glm::vec3 wristPosition = position; + + glm::vec3 shoulderToWrist = wristPosition - shoulderPosition; + float distanceToWrist = glm::length(shoulderToWrist); + + // prevent gimbal lock + if (distanceToWrist > upperArmLength + lowerArmLength - EPSILON) { + distanceToWrist = upperArmLength + lowerArmLength - EPSILON; + shoulderToWrist = glm::normalize(shoulderToWrist) * distanceToWrist; + wristPosition = shoulderPosition + shoulderToWrist; + } + + // cosine of angle from upper arm to hand vector + float cosA = (upperArmLength * upperArmLength + distanceToWrist * distanceToWrist - lowerArmLength * lowerArmLength) / + (2 * upperArmLength * distanceToWrist); + float mid = upperArmLength * cosA; + float height = sqrt(upperArmLength * upperArmLength + mid * mid - 2 * upperArmLength * mid * cosA); + + // direction of the elbow + glm::vec3 handNormal = glm::cross(rotation * glm::vec3(0.0f, 1.0f, 0.0f), shoulderToWrist); // elbow rotating with wrist + glm::vec3 relaxedNormal = glm::cross(glm::vec3(0.0f, 1.0f, 0.0f), shoulderToWrist); // elbow pointing straight down + const float NORMAL_WEIGHT = 0.5f; + glm::vec3 finalNormal = glm::mix(relaxedNormal, handNormal, NORMAL_WEIGHT); + + if((jointIndex == geometry.rightHandJointIndex && finalNormal.y > 0.0f) || + (jointIndex == geometry.leftHandJointIndex && finalNormal.y < 0)) { + finalNormal.y = 0.0f; // dont allow elbows to point inward (y is vertical axis) + } + + glm::vec3 tangent = glm::normalize(glm::cross(shoulderToWrist, finalNormal)); + + // ik solution + glm::vec3 elbowPosition = shoulderPosition + glm::normalize(shoulderToWrist) * mid - tangent * height; } From 3eefb6a93ee73d45c1f0ed4cfa1dd2078fd54b9b Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 15 May 2014 15:32:32 -0700 Subject: [PATCH 3/7] Rotation bits for alternate IK. --- interface/src/avatar/SkeletonModel.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 1921094a0f..540565f5b8 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -322,8 +322,8 @@ void SkeletonModel::setHandPosition(int jointIndex, const glm::vec3& position, c const float NORMAL_WEIGHT = 0.5f; glm::vec3 finalNormal = glm::mix(relaxedNormal, handNormal, NORMAL_WEIGHT); - if((jointIndex == geometry.rightHandJointIndex && finalNormal.y > 0.0f) || - (jointIndex == geometry.leftHandJointIndex && finalNormal.y < 0)) { + bool rightHand = (jointIndex == geometry.rightHandJointIndex); + if (rightHand ? (finalNormal.y > 0.0f) : (finalNormal.y < 0.0f)) { finalNormal.y = 0.0f; // dont allow elbows to point inward (y is vertical axis) } @@ -331,5 +331,17 @@ void SkeletonModel::setHandPosition(int jointIndex, const glm::vec3& position, c // ik solution glm::vec3 elbowPosition = shoulderPosition + glm::normalize(shoulderToWrist) * mid - tangent * height; + + glm::vec3 forwardVector(rightHand ? -1.0f : 1.0f, 0.0f, 0.0f); + + glm::quat shoulderRotation; + getJointRotation(shoulderJointIndex, shoulderRotation, true); + applyRotationDelta(shoulderJointIndex, rotationBetween(shoulderRotation * forwardVector, elbowPosition - shoulderPosition), false); + + glm::quat elbowRotation; + getJointRotation(elbowJointIndex, elbowRotation, true); + applyRotationDelta(elbowJointIndex, rotationBetween(elbowRotation * forwardVector, wristPosition - elbowPosition), false); + + setJointRotation(jointIndex, rotation, true); } From 301234a39773208192066d0903ea4836fbf79bc4 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 15 May 2014 15:34:01 -0700 Subject: [PATCH 4/7] Tabs -> spaces. --- interface/src/avatar/SkeletonModel.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 540565f5b8..3786280a3c 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -320,16 +320,16 @@ void SkeletonModel::setHandPosition(int jointIndex, const glm::vec3& position, c glm::vec3 handNormal = glm::cross(rotation * glm::vec3(0.0f, 1.0f, 0.0f), shoulderToWrist); // elbow rotating with wrist glm::vec3 relaxedNormal = glm::cross(glm::vec3(0.0f, 1.0f, 0.0f), shoulderToWrist); // elbow pointing straight down const float NORMAL_WEIGHT = 0.5f; - glm::vec3 finalNormal = glm::mix(relaxedNormal, handNormal, NORMAL_WEIGHT); + glm::vec3 finalNormal = glm::mix(relaxedNormal, handNormal, NORMAL_WEIGHT); bool rightHand = (jointIndex == geometry.rightHandJointIndex); if (rightHand ? (finalNormal.y > 0.0f) : (finalNormal.y < 0.0f)) { finalNormal.y = 0.0f; // dont allow elbows to point inward (y is vertical axis) } - glm::vec3 tangent = glm::normalize(glm::cross(shoulderToWrist, finalNormal)); - - // ik solution + glm::vec3 tangent = glm::normalize(glm::cross(shoulderToWrist, finalNormal)); + + // ik solution glm::vec3 elbowPosition = shoulderPosition + glm::normalize(shoulderToWrist) * mid - tangent * height; glm::vec3 forwardVector(rightHand ? -1.0f : 1.0f, 0.0f, 0.0f); From 61fd09e0bd16e985bfc8dfdd490d46ff5ff77b29 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 15 May 2014 16:24:31 -0700 Subject: [PATCH 5/7] Add ability to anchor an overlay --- examples/editModels.js | 39 +++++++++++++++----------- interface/src/ui/overlays/Overlay.cpp | 12 ++++++-- interface/src/ui/overlays/Overlay.h | 8 ++++++ interface/src/ui/overlays/Overlays.cpp | 12 ++++++++ 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/examples/editModels.js b/examples/editModels.js index 70a2e178ae..9a20a7db27 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -76,38 +76,42 @@ function controller(wichSide) { this.oldModelRadius; this.laser = Overlays.addOverlay("line3d", { - position: this.palmPosition, - end: this.tipPosition, + position: { x: 0, y: 0, z: 0 }, + end: { x: 0, y: 0, z: 0 }, color: LASER_COLOR, alpha: 1, visible: false, - lineWidth: LASER_WIDTH + lineWidth: LASER_WIDTH, + anchor: "MyAvatar" }); this.guideScale = 0.02; this.ball = Overlays.addOverlay("sphere", { - position: this.palmPosition, + position: { x: 0, y: 0, z: 0 }, size: this.guideScale, solid: true, color: { red: 0, green: 255, blue: 0 }, alpha: 1, visible: false, + anchor: "MyAvatar" }); this.leftRight = Overlays.addOverlay("line3d", { - position: this.palmPosition, - end: this.tipPosition, + position: { x: 0, y: 0, z: 0 }, + end: { x: 0, y: 0, z: 0 }, color: { red: 0, green: 0, blue: 255 }, alpha: 1, visible: false, - lineWidth: LASER_WIDTH + lineWidth: LASER_WIDTH, + anchor: "MyAvatar" }); this.topDown = Overlays.addOverlay("line3d", { - position: this.palmPosition, - end: this.tipPosition, + position: { x: 0, y: 0, z: 0 }, + end: { x: 0, y: 0, z: 0 }, color: { red: 0, green: 0, blue: 255 }, alpha: 1, visible: false, - lineWidth: LASER_WIDTH + lineWidth: LASER_WIDTH, + anchor: "MyAvatar" }); @@ -170,10 +174,11 @@ function controller(wichSide) { } this.moveLaser = function () { - var endPosition = Vec3.sum(this.palmPosition, Vec3.multiply(this.front, LASER_LENGTH_FACTOR)); + var startPosition = Vec3.subtract(this.palmPosition, MyAvatar.position); + var endPosition = Vec3.sum(startPosition, Vec3.multiply(this.front, LASER_LENGTH_FACTOR)); Overlays.editOverlay(this.laser, { - position: this.palmPosition, + position: startPosition, end: endPosition, visible: true }); @@ -219,11 +224,11 @@ function controller(wichSide) { position: newPosition, modelRotation: newRotation }); - print("Moving " + this.modelID.id); +// print("Moving " + this.modelID.id); // Vec3.print("Old Position: ", this.oldModelPosition); // Vec3.print("Sav Position: ", newPosition); - Quat.print("Old Rotation: ", this.oldModelRotation); - Quat.print("New Rotation: ", newRotation); +// Quat.print("Old Rotation: ", this.oldModelRotation); +// Quat.print("New Rotation: ", newRotation); this.oldModelRotation = newRotation; this.oldModelPosition = newPosition; @@ -301,7 +306,7 @@ var rightController = new controller(RIGHT); function moveModels() { if (leftController.grabbing && rightController.grabbing && rightController.modelID.id == leftController.modelID.id) { - print("Both controllers"); + //print("Both controllers"); var oldLeftPoint = Vec3.sum(leftController.oldPalmPosition, Vec3.multiply(leftController.oldFront, leftController.x)); var oldRightPoint = Vec3.sum(rightController.oldPalmPosition, Vec3.multiply(rightController.oldFront, rightController.x)); @@ -319,7 +324,7 @@ function moveModels() { var newPosition = Vec3.sum(middle, Vec3.multiply(Vec3.subtract(leftController.oldModelPosition, oldMiddle), ratio)); - Vec3.print("Ratio : " + ratio + " New position: ", newPosition); + //Vec3.print("Ratio : " + ratio + " New position: ", newPosition); var rotation = Quat.multiply(leftController.rotation, Quat.inverse(leftController.oldRotation)); rotation = Quat.multiply(rotation, leftController.oldModelRotation); diff --git a/interface/src/ui/overlays/Overlay.cpp b/interface/src/ui/overlays/Overlay.cpp index 3b38addb76..8ec7cbace1 100644 --- a/interface/src/ui/overlays/Overlay.cpp +++ b/interface/src/ui/overlays/Overlay.cpp @@ -23,7 +23,8 @@ Overlay::Overlay() : _parent(NULL), _alpha(DEFAULT_ALPHA), _color(DEFAULT_BACKGROUND_COLOR), - _visible(true) + _visible(true), + _anchor(NO_ANCHOR) { } @@ -51,8 +52,15 @@ void Overlay::setProperties(const QScriptValue& properties) { if (properties.property("alpha").isValid()) { setAlpha(properties.property("alpha").toVariant().toFloat()); } - + if (properties.property("visible").isValid()) { setVisible(properties.property("visible").toVariant().toBool()); } + + if (properties.property("anchor").isValid()) { + QString property = properties.property("anchor").toVariant().toString(); + if (property == "MyAvatar") { + setAnchor(MY_AVATAR); + } + } } diff --git a/interface/src/ui/overlays/Overlay.h b/interface/src/ui/overlays/Overlay.h index 6feb159e05..7667b3d3fd 100644 --- a/interface/src/ui/overlays/Overlay.h +++ b/interface/src/ui/overlays/Overlay.h @@ -28,6 +28,11 @@ class Overlay : public QObject { Q_OBJECT public: + enum Anchor { + NO_ANCHOR, + MY_AVATAR + }; + Overlay(); ~Overlay(); void init(QGLWidget* parent); @@ -38,11 +43,13 @@ public: bool getVisible() const { return _visible; } const xColor& getColor() const { return _color; } float getAlpha() const { return _alpha; } + Anchor getAnchor() const { return _anchor; } // setters void setVisible(bool visible) { _visible = visible; } void setColor(const xColor& color) { _color = color; } void setAlpha(float alpha) { _alpha = alpha; } + void setAnchor(Anchor anchor) { _anchor = anchor; } virtual void setProperties(const QScriptValue& properties); @@ -51,6 +58,7 @@ protected: float _alpha; xColor _color; bool _visible; // should the overlay be drawn at all + Anchor _anchor; }; diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 4eb4f030ac..78fe54b267 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -8,6 +8,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include "Cube3DOverlay.h" #include "ImageOverlay.h" @@ -57,8 +58,19 @@ void Overlays::render2D() { } void Overlays::render3D() { + glm::vec3 myAvatarPosition = Application::getInstance()->getAvatar()->getPosition(); + foreach(Overlay* thisOverlay, _overlays3D) { + glPushMatrix(); + switch (thisOverlay->getAnchor()) { + case Overlay::MY_AVATAR: + glTranslatef(myAvatarPosition.x, myAvatarPosition.y, myAvatarPosition.z); + break; + default: + break; + } thisOverlay->render(); + glPopMatrix(); } } From e8937852bc2661aef72c9a61d56e7f2bb77c99df Mon Sep 17 00:00:00 2001 From: Kai Ludwig Date: Fri, 16 May 2014 15:12:49 +0200 Subject: [PATCH 6/7] MenuOption::Visage now default to false. --- interface/src/Menu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 2daf5b0240..3c0ebe4cd2 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -331,7 +331,7 @@ Menu::Menu() : #endif #ifdef HAVE_VISAGE - addCheckableActionToQMenuAndActionHash(avatarOptionsMenu, MenuOption::Visage, 0, true, + addCheckableActionToQMenuAndActionHash(avatarOptionsMenu, MenuOption::Visage, 0, false, appInstance->getVisage(), SLOT(updateEnabled())); #endif From 51965fd283e43ea299d5d592175aec96eb7bb996 Mon Sep 17 00:00:00 2001 From: Kai Ludwig Date: Fri, 16 May 2014 15:44:07 +0200 Subject: [PATCH 7/7] changed float specular = max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), normalizedNormal)); to float specular = max(0.0, dot(gl_LightSource[0].position, normalizedNormal)); Calculation for specular value has to be done like in all other shaders with the unmodified unnormalized lightsource position. Otherwise the specular effect will have weird behaviour. --- interface/resources/shaders/model.frag | 2 +- interface/resources/shaders/model_normal_map.frag | 2 +- interface/resources/shaders/model_normal_specular_map.frag | 2 +- interface/resources/shaders/model_specular_map.frag | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/resources/shaders/model.frag b/interface/resources/shaders/model.frag index 29579d07ac..3964bd5b97 100644 --- a/interface/resources/shaders/model.frag +++ b/interface/resources/shaders/model.frag @@ -24,7 +24,7 @@ void main(void) { gl_FrontLightProduct[0].diffuse * max(0.0, dot(normalizedNormal, gl_LightSource[0].position))); // compute the specular component (sans exponent) - float specular = max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), normalizedNormal)); + float specular = max(0.0, dot(gl_LightSource[0].position, normalizedNormal)); // modulate texture by base color and add specular contribution gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + diff --git a/interface/resources/shaders/model_normal_map.frag b/interface/resources/shaders/model_normal_map.frag index 2a4af2073a..a4f7a887c5 100644 --- a/interface/resources/shaders/model_normal_map.frag +++ b/interface/resources/shaders/model_normal_map.frag @@ -36,7 +36,7 @@ void main(void) { gl_FrontLightProduct[0].diffuse * max(0.0, dot(viewNormal, gl_LightSource[0].position))); // compute the specular component (sans exponent) - float specular = max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), viewNormal)); + float specular = max(0.0, dot(gl_LightSource[0].position, viewNormal)); // modulate texture by base color and add specular contribution gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + diff --git a/interface/resources/shaders/model_normal_specular_map.frag b/interface/resources/shaders/model_normal_specular_map.frag index 79761446b1..f5b9d2b06b 100644 --- a/interface/resources/shaders/model_normal_specular_map.frag +++ b/interface/resources/shaders/model_normal_specular_map.frag @@ -39,7 +39,7 @@ void main(void) { gl_FrontLightProduct[0].diffuse * max(0.0, dot(viewNormal, gl_LightSource[0].position))); // compute the specular component (sans exponent) - float specular = max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), viewNormal)); + float specular = max(0.0, dot(gl_LightSource[0].position, viewNormal)); // modulate texture by base color and add specular contribution gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + vec4(pow(specular, gl_FrontMaterial.shininess) * diff --git a/interface/resources/shaders/model_specular_map.frag b/interface/resources/shaders/model_specular_map.frag index 972a8e2de6..4e2f3d0c98 100644 --- a/interface/resources/shaders/model_specular_map.frag +++ b/interface/resources/shaders/model_specular_map.frag @@ -27,7 +27,7 @@ void main(void) { gl_FrontLightProduct[0].diffuse * max(0.0, dot(normalizedNormal, gl_LightSource[0].position))); // compute the specular component (sans exponent) - float specular = max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), normalizedNormal)); + float specular = max(0.0, dot(gl_LightSource[0].position, normalizedNormal)); // modulate texture by base color and add specular contribution gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + vec4(pow(specular, gl_FrontMaterial.shininess) *