mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 23:40:11 +02:00
Added refraction to irises.
This commit is contained in:
parent
7d1679dab7
commit
790cdfb0bd
4 changed files with 38 additions and 45 deletions
Binary file not shown.
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 71 KiB |
|
@ -19,6 +19,6 @@ 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)));
|
float specular = max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), normalize(normal)));
|
||||||
|
|
||||||
// modulate texture by diffuse color and add specular contribution
|
// modulate texture by diffuse color and add specular contribution
|
||||||
gl_FragColor = vec4(gl_Color.rgb * texture2D(texture, gl_TexCoord[0].st).rgb +
|
gl_FragColor = gl_Color * texture2D(texture, gl_TexCoord[0].st) +
|
||||||
pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb, 1.0);
|
pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,17 +11,22 @@
|
||||||
// the interpolated normal
|
// the interpolated normal
|
||||||
varying vec4 normal;
|
varying vec4 normal;
|
||||||
|
|
||||||
|
// the ratio of the indices of refraction
|
||||||
|
const float refractionEta = 0.75;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
|
|
||||||
// transform and store the normal for interpolation
|
// transform and store the normal for interpolation
|
||||||
normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0));
|
normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0));
|
||||||
|
|
||||||
// compute standard diffuse lighting per-vertex
|
// compute standard diffuse lighting per-vertex
|
||||||
gl_FrontColor = gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient +
|
gl_FrontColor = vec4(gl_Color.rgb * (gl_LightModel.ambient.rgb + gl_LightSource[0].ambient.rgb +
|
||||||
gl_LightSource[0].diffuse * max(0.0, dot(normal, gl_LightSource[0].position)));
|
gl_LightSource[0].diffuse.rgb * max(0.0, dot(normal, gl_LightSource[0].position))), gl_Color.a);
|
||||||
|
|
||||||
// copy the tex coordinate for interpolation
|
// compute the texture coordinate based on where refracted vector hits z=0 in model space
|
||||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
vec4 incidence = normalize(gl_Vertex - gl_ModelViewMatrixInverse * vec4(0.0, 0.0, 0.0, 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);
|
||||||
|
|
||||||
// use standard pipeline transform
|
// use standard pipeline transform
|
||||||
gl_Position = ftransform();
|
gl_Position = ftransform();
|
||||||
|
|
|
@ -87,12 +87,14 @@ void Head::init() {
|
||||||
|
|
||||||
_irisProgram->setUniformValue("texture", 0);
|
_irisProgram->setUniformValue("texture", 0);
|
||||||
|
|
||||||
QImage image = QImage(IRIS_TEXTURE_FILENAME).convertToFormat(QImage::Format_RGB888);
|
QImage image = QImage(IRIS_TEXTURE_FILENAME).convertToFormat(QImage::Format_ARGB32);
|
||||||
|
|
||||||
glGenTextures(1, &_irisTextureID);
|
glGenTextures(1, &_irisTextureID);
|
||||||
glBindTexture(GL_TEXTURE_2D, _irisTextureID);
|
glBindTexture(GL_TEXTURE_2D, _irisTextureID);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width(), image.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, image.constBits());
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 1, GL_BGRA, GL_UNSIGNED_BYTE, image.constBits());
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -462,24 +464,18 @@ void Head::renderEyeBrows() {
|
||||||
|
|
||||||
void Head::renderEyeBalls() {
|
void Head::renderEyeBalls() {
|
||||||
|
|
||||||
// setup the texture to be used on each iris
|
|
||||||
GLUquadric* irisQuadric = gluNewQuadric();
|
|
||||||
gluQuadricTexture(irisQuadric, GL_TRUE);
|
|
||||||
|
|
||||||
gluQuadricOrientation(irisQuadric, GLU_OUTSIDE);
|
|
||||||
|
|
||||||
// render white ball of left eyeball
|
// render white ball of left eyeball
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glColor3fv(EYEBALL_COLOR);
|
glColor3fv(EYEBALL_COLOR);
|
||||||
glTranslatef(_leftEyePosition.x, _leftEyePosition.y, _leftEyePosition.z);
|
glTranslatef(_leftEyePosition.x, _leftEyePosition.y, _leftEyePosition.z);
|
||||||
gluSphere(irisQuadric, EYEBALL_RADIUS, 30, 30);
|
glutSolidSphere(EYEBALL_RADIUS, 30, 30);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
//render white ball of right eyeball
|
//render white ball of right eyeball
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glColor3fv(EYEBALL_COLOR);
|
glColor3fv(EYEBALL_COLOR);
|
||||||
glTranslatef(_rightEyePosition.x, _rightEyePosition.y, _rightEyePosition.z);
|
glTranslatef(_rightEyePosition.x, _rightEyePosition.y, _rightEyePosition.z);
|
||||||
gluSphere(irisQuadric, EYEBALL_RADIUS, 30, 30);
|
glutSolidSphere(EYEBALL_RADIUS, 30, 30);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
_irisProgram->bind();
|
_irisProgram->bind();
|
||||||
|
@ -492,44 +488,36 @@ void Head::renderEyeBalls() {
|
||||||
// render left iris
|
// render left iris
|
||||||
glPushMatrix(); {
|
glPushMatrix(); {
|
||||||
glTranslatef(_leftEyePosition.x, _leftEyePosition.y, _leftEyePosition.z); //translate to eyeball position
|
glTranslatef(_leftEyePosition.x, _leftEyePosition.y, _leftEyePosition.z); //translate to eyeball position
|
||||||
glPushMatrix();
|
|
||||||
//rotate the eyeball to aim towards the lookat position
|
//rotate the eyeball to aim towards the lookat position
|
||||||
glm::vec3 targetLookatVector = _lookAtPosition + _saccade - _leftEyePosition;
|
glm::vec3 targetLookatVector = _lookAtPosition + _saccade - _leftEyePosition;
|
||||||
glm::quat rotation = rotationBetween(front, targetLookatVector) * orientation;
|
glm::quat rotation = rotationBetween(front, targetLookatVector) * orientation;
|
||||||
glm::vec3 rotationAxis = glm::axis(rotation);
|
glm::vec3 rotationAxis = glm::axis(rotation);
|
||||||
glRotatef(glm::angle(rotation), rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
glRotatef(glm::angle(rotation), rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
||||||
glRotatef(90.0, 1.0f, 0.0f, 0.0f); // rotate to face Z-
|
glTranslatef(0.0f, 0.0f, -IRIS_PROTRUSION);
|
||||||
glTranslatef( 0.0f, -IRIS_PROTRUSION, 0.0f);
|
glScalef(IRIS_RADIUS * 2.0f, IRIS_RADIUS * 2.0f, IRIS_RADIUS); // flatten the iris
|
||||||
glScalef( 1.0f, 0.5f, 1.0f); // flatten the iris
|
glutSolidSphere(0.5f, 15, 15);
|
||||||
gluSphere(irisQuadric, IRIS_RADIUS, 15, 15);
|
|
||||||
glPopMatrix();
|
|
||||||
}
|
}
|
||||||
glPopMatrix();
|
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
|
||||||
glPushMatrix();
|
|
||||||
|
//rotate the eyeball to aim towards the lookat position
|
||||||
//rotate the eyeball to aim towards the lookat position
|
glm::vec3 targetLookatVector = _lookAtPosition + _saccade - _rightEyePosition;
|
||||||
glm::vec3 targetLookatVector = _lookAtPosition + _saccade - _rightEyePosition;
|
glm::quat rotation = rotationBetween(front, targetLookatVector) * orientation;
|
||||||
glm::quat rotation = rotationBetween(front, targetLookatVector) * orientation;
|
glm::vec3 rotationAxis = glm::axis(rotation);
|
||||||
glm::vec3 rotationAxis = glm::axis(rotation);
|
glRotatef(glm::angle(rotation), rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
||||||
glRotatef(glm::angle(rotation), rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
glTranslatef(0.0f, 0.0f, -IRIS_PROTRUSION);
|
||||||
glRotatef(90.0f, 1.0f, 0.0f, 0.0f); // rotate to face Z-
|
glScalef(IRIS_RADIUS * 2.0f, IRIS_RADIUS * 2.0f, IRIS_RADIUS); // flatten the iris
|
||||||
glTranslatef( 0.0f, -IRIS_PROTRUSION, 0.0f);
|
glutSolidSphere(0.5f, 15, 15);
|
||||||
glScalef( 1.0f, 0.5f, 1.0f); // flatten the iris
|
|
||||||
gluSphere(irisQuadric, IRIS_RADIUS, 15, 15);
|
|
||||||
glPopMatrix();
|
|
||||||
}
|
}
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
_irisProgram->release();
|
_irisProgram->release();
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
// delete the iris quadric now that we're done with it
|
|
||||||
gluDeleteQuadric(irisQuadric);
|
|
||||||
glPopMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Head::renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosition, glm::vec3 lookatPosition) {
|
void Head::renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosition, glm::vec3 lookatPosition) {
|
||||||
|
|
Loading…
Reference in a new issue