mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
Merge pull request #541 from ey6es/master
Fix for irises on OS X: compute and pass in the model space eye position as a uniform.
This commit is contained in:
commit
d80e55a995
3 changed files with 21 additions and 1 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -109,6 +109,7 @@ private:
|
|||
|
||||
static ProgramObject* _irisProgram;
|
||||
static GLuint _irisTextureID;
|
||||
static int _eyePositionLocation;
|
||||
|
||||
// private methods
|
||||
void createMohawk();
|
||||
|
|
Loading…
Reference in a new issue