From c11ab45474592b86d6d7f5b242dfb5728da854f8 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 14 Jun 2013 17:21:35 -0700 Subject: [PATCH] It seems gl_ModelViewMatrixInverse is problematic on OS X; let's try passing in the camera's position as transformed into model space. --- interface/resources/shaders/iris.vert | 5 ++++- interface/src/Head.cpp | 16 ++++++++++++++++ interface/src/Head.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/interface/resources/shaders/iris.vert b/interface/resources/shaders/iris.vert index 8dbc56d66a..66906a93c3 100644 --- a/interface/resources/shaders/iris.vert +++ b/interface/resources/shaders/iris.vert @@ -8,6 +8,9 @@ // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. // +// the location of the eye in model space +uniform vec3 eyePosition; + // the interpolated normal varying vec4 normal; @@ -24,7 +27,7 @@ void main(void) { gl_LightSource[0].diffuse.rgb * max(0.0, dot(normal, gl_LightSource[0].position))), gl_Color.a); // compute the texture coordinate based on where refracted vector hits z=0 in model space - vec4 incidence = normalize(gl_Vertex - gl_ModelViewMatrixInverse * vec4(0.0, 0.0, 0.0, 1.0)); + vec4 incidence = normalize(gl_Vertex - vec4(eyePosition, 1.0)); vec4 refracted = refract(incidence, normalize(vec4(gl_Normal, 0.0)), refractionEta); gl_TexCoord[0] = (gl_Vertex - (gl_Vertex.z / refracted.z) * refracted) + vec4(0.5, 0.5, 0.0, 0.0); diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 26ba8879ca..aebb8837a5 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -41,6 +41,7 @@ const char IRIS_TEXTURE_FILENAME[] = "resources/images/iris.png"; ProgramObject* Head::_irisProgram = 0; GLuint Head::_irisTextureID; +int Head::_eyePositionLocation; Head::Head(Avatar* owningAvatar) : HeadData((AvatarData*)owningAvatar), @@ -86,6 +87,7 @@ void Head::init() { _irisProgram->link(); _irisProgram->setUniformValue("texture", 0); + _eyePositionLocation = _irisProgram->uniformLocation("eyePosition"); QImage image = QImage(IRIS_TEXTURE_FILENAME).convertToFormat(QImage::Format_ARGB32); @@ -496,6 +498,13 @@ void Head::renderEyeBalls() { glRotatef(glm::angle(rotation), rotationAxis.x, rotationAxis.y, rotationAxis.z); glTranslatef(0.0f, 0.0f, -IRIS_PROTRUSION); glScalef(IRIS_RADIUS * 2.0f, IRIS_RADIUS * 2.0f, IRIS_RADIUS); // flatten the iris + + // this ugliness is simply to invert the model transform and get the eye position in model space + _irisProgram->setUniform(_eyePositionLocation, (glm::inverse(rotation) * + (Application::getInstance()->getCamera()->getPosition() - _leftEyePosition) + + glm::vec3(0.0f, 0.0f, IRIS_PROTRUSION)) * glm::vec3(1.0f / (IRIS_RADIUS * 2.0f), + 1.0f / (IRIS_RADIUS * 2.0f), 1.0f / IRIS_RADIUS)); + glutSolidSphere(0.5f, 15, 15); } glPopMatrix(); @@ -511,6 +520,13 @@ void Head::renderEyeBalls() { glRotatef(glm::angle(rotation), rotationAxis.x, rotationAxis.y, rotationAxis.z); glTranslatef(0.0f, 0.0f, -IRIS_PROTRUSION); glScalef(IRIS_RADIUS * 2.0f, IRIS_RADIUS * 2.0f, IRIS_RADIUS); // flatten the iris + + // this ugliness is simply to invert the model transform and get the eye position in model space + _irisProgram->setUniform(_eyePositionLocation, (glm::inverse(rotation) * + (Application::getInstance()->getCamera()->getPosition() - _rightEyePosition) + + glm::vec3(0.0f, 0.0f, IRIS_PROTRUSION)) * glm::vec3(1.0f / (IRIS_RADIUS * 2.0f), + 1.0f / (IRIS_RADIUS * 2.0f), 1.0f / IRIS_RADIUS)); + glutSolidSphere(0.5f, 15, 15); } glPopMatrix(); diff --git a/interface/src/Head.h b/interface/src/Head.h index 30636c37fe..840954b0b9 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -109,6 +109,7 @@ private: static ProgramObject* _irisProgram; static GLuint _irisTextureID; + static int _eyePositionLocation; // private methods void createMohawk();