Added per-pixel specular highlight to irises.

This commit is contained in:
Andrzej Kapolka 2013-06-13 15:58:49 -07:00
parent 466c062bc1
commit e401663459
4 changed files with 72 additions and 20 deletions

View file

@ -0,0 +1,21 @@
#version 120
//
// iris.frag
// fragment shader
//
// Created by Andrzej Kapolka on 6/13/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
// the iris texture
uniform sampler2D texture;
// the interpolated normal
varying vec4 normal;
void main(void) {
float specular = max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), normalize(normal)));
gl_FragColor = vec4(gl_Color.rgb * texture2D(texture, gl_TexCoord[0].st).rgb +
pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb, 1.0);
}

View file

@ -0,0 +1,20 @@
#version 120
//
// iris.vert
// vertex shader
//
// Created by Andrzej Kapolka on 6/13/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
// the interpolated normal
varying vec4 normal;
void main(void) {
normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0));
gl_FrontColor = gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient +
gl_LightSource[0].diffuse * max(0.0, dot(normal, gl_LightSource[0].position)));
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}

View file

@ -8,13 +8,13 @@
#include <QImage> #include <QImage>
#include <AgentList.h>
#include "Application.h" #include "Application.h"
#include "Avatar.h" #include "Avatar.h"
#include "Head.h" #include "Head.h"
#include "Util.h" #include "Util.h"
#include <vector> #include "renderer/ProgramObject.h"
#include <lodepng.h>
#include <AgentList.h>
using namespace std; using namespace std;
@ -39,7 +39,8 @@ const float IRIS_RADIUS = 0.007;
const float IRIS_PROTRUSION = 0.0145f; const float IRIS_PROTRUSION = 0.0145f;
const char IRIS_TEXTURE_FILENAME[] = "resources/images/iris.png"; const char IRIS_TEXTURE_FILENAME[] = "resources/images/iris.png";
GLuint Head::_irisTextureID = 0; ProgramObject* Head::_irisProgram = 0;
GLuint Head::_irisTextureID;
Head::Head(Avatar* owningAvatar) : Head::Head(Avatar* owningAvatar) :
HeadData((AvatarData*)owningAvatar), HeadData((AvatarData*)owningAvatar),
@ -76,8 +77,15 @@ Head::Head(Avatar* owningAvatar) :
} }
void Head::init() { void Head::init() {
if (_irisTextureID == 0) { if (_irisProgram == 0) {
switchToResourcesParentIfRequired(); switchToResourcesParentIfRequired();
_irisProgram = new ProgramObject();
_irisProgram->addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/iris.vert");
_irisProgram->addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/iris.frag");
_irisProgram->link();
_irisProgram->setUniformValue("texture", 0);
QImage image = QImage(IRIS_TEXTURE_FILENAME).convertToFormat(QImage::Format_RGB888); QImage image = QImage(IRIS_TEXTURE_FILENAME).convertToFormat(QImage::Format_RGB888);
glGenTextures(1, &_irisTextureID); glGenTextures(1, &_irisTextureID);
@ -483,12 +491,11 @@ void Head::renderEyeBrows() {
void Head::renderEyeBalls() { void Head::renderEyeBalls() {
// setup the texutre to be used on each iris // setup the texture to be used on each iris
GLUquadric* irisQuadric = gluNewQuadric(); GLUquadric* irisQuadric = gluNewQuadric();
gluQuadricTexture(irisQuadric, GL_TRUE); gluQuadricTexture(irisQuadric, GL_TRUE);
gluQuadricOrientation(irisQuadric, GLU_OUTSIDE); gluQuadricOrientation(irisQuadric, GLU_OUTSIDE);
glBindTexture(GL_TEXTURE_2D, _irisTextureID);
// render white ball of left eyeball // render white ball of left eyeball
glPushMatrix(); glPushMatrix();
@ -497,6 +504,17 @@ void Head::renderEyeBalls() {
gluSphere(irisQuadric, EYEBALL_RADIUS, 30, 30); gluSphere(irisQuadric, EYEBALL_RADIUS, 30, 30);
glPopMatrix(); glPopMatrix();
//render white ball of right eyeball
glPushMatrix();
glColor3fv(EYEBALL_COLOR);
glTranslatef(_rightEyePosition.x, _rightEyePosition.y, _rightEyePosition.z);
gluSphere(irisQuadric, EYEBALL_RADIUS, 30, 30);
glPopMatrix();
_irisProgram->bind();
glBindTexture(GL_TEXTURE_2D, _irisTextureID);
glEnable(GL_TEXTURE_2D);
glm::vec3 front = getFrontDirection(); glm::vec3 front = getFrontDirection();
// render left iris // render left iris
@ -529,20 +547,11 @@ void Head::renderEyeBalls() {
glTranslatef( 0.0f, -IRIS_PROTRUSION, 0.0f);//push the iris out a bit (otherwise - inside of eyeball!) glTranslatef( 0.0f, -IRIS_PROTRUSION, 0.0f);//push the iris out a bit (otherwise - inside of eyeball!)
glScalef( 1.0f, 0.5f, 1.0f); // flatten the iris glScalef( 1.0f, 0.5f, 1.0f); // flatten the iris
glEnable(GL_TEXTURE_2D);
gluSphere(irisQuadric, IRIS_RADIUS, 15, 15); gluSphere(irisQuadric, IRIS_RADIUS, 15, 15);
glDisable(GL_TEXTURE_2D);
glPopMatrix(); glPopMatrix();
} }
glPopMatrix(); glPopMatrix();
//render white ball of right eyeball
glPushMatrix();
glColor3fv(EYEBALL_COLOR);
glTranslatef(_rightEyePosition.x, _rightEyePosition.y, _rightEyePosition.z);
gluSphere(irisQuadric, EYEBALL_RADIUS, 30, 30);
glPopMatrix();
// render right iris // render right iris
glPushMatrix(); { glPushMatrix(); {
glTranslatef(_rightEyePosition.x, _rightEyePosition.y, _rightEyePosition.z); //translate to eyeball position glTranslatef(_rightEyePosition.x, _rightEyePosition.y, _rightEyePosition.z); //translate to eyeball position
@ -574,17 +583,17 @@ void Head::renderEyeBalls() {
glTranslatef( 0.0f, -IRIS_PROTRUSION, 0.0f);//push the iris out a bit (otherwise - inside of eyeball!) glTranslatef( 0.0f, -IRIS_PROTRUSION, 0.0f);//push the iris out a bit (otherwise - inside of eyeball!)
glScalef( 1.0f, 0.5f, 1.0f); // flatten the iris glScalef( 1.0f, 0.5f, 1.0f); // flatten the iris
glEnable(GL_TEXTURE_2D);
gluSphere(irisQuadric, IRIS_RADIUS, 15, 15); gluSphere(irisQuadric, IRIS_RADIUS, 15, 15);
glDisable(GL_TEXTURE_2D);
glPopMatrix(); glPopMatrix();
} }
_irisProgram->release();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
// delete the iris quadric now that we're done with it // delete the iris quadric now that we're done with it
gluDeleteQuadric(irisQuadric); gluDeleteQuadric(irisQuadric);
glPopMatrix(); glPopMatrix();
glBindTexture(GL_TEXTURE_2D, 0);
} }
void Head::renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosition, glm::vec3 lookatPosition) { void Head::renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosition, glm::vec3 lookatPosition) {

View file

@ -26,6 +26,7 @@ enum eyeContactTargets
const int NUM_HAIR_TUFTS = 4; const int NUM_HAIR_TUFTS = 4;
class Avatar; class Avatar;
class ProgramObject;
class Head : public HeadData { class Head : public HeadData {
public: public:
@ -105,6 +106,7 @@ private:
glm::vec3* _mohawkTriangleFan; glm::vec3* _mohawkTriangleFan;
glm::vec3* _mohawkColors; glm::vec3* _mohawkColors;
static ProgramObject* _irisProgram;
static GLuint _irisTextureID; static GLuint _irisTextureID;
// private methods // private methods