mirror of
https://github.com/lubosz/overte.git
synced 2025-04-26 23:15:31 +02:00
Use shaders for eyes (like the ones for the iris).
This commit is contained in:
parent
7d14aaeea4
commit
736dae0c81
3 changed files with 46 additions and 3 deletions
interface
28
interface/resources/shaders/eye.vert
Normal file
28
interface/resources/shaders/eye.vert
Normal file
|
@ -0,0 +1,28 @@
|
|||
#version 120
|
||||
|
||||
//
|
||||
// eye.vert
|
||||
// vertex shader
|
||||
//
|
||||
// Created by Andrzej Kapolka on 9/25/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
// the interpolated normal
|
||||
varying vec4 normal;
|
||||
|
||||
void main(void) {
|
||||
|
||||
// transform and store the normal for interpolation
|
||||
normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0));
|
||||
|
||||
// compute standard diffuse lighting per-vertex
|
||||
gl_FrontColor = vec4(gl_Color.rgb * (gl_LightModel.ambient.rgb + gl_LightSource[0].ambient.rgb +
|
||||
gl_LightSource[0].diffuse.rgb * max(0.0, dot(normal, gl_LightSource[0].position))), gl_Color.a);
|
||||
|
||||
// pass along the texture coordinate
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
|
||||
// use standard pipeline transform
|
||||
gl_Position = ftransform();
|
||||
}
|
|
@ -27,10 +27,20 @@ BlendFace::~BlendFace() {
|
|||
deleteGeometry();
|
||||
}
|
||||
|
||||
GLuint BlendFace::_eyeTextureID = 0;
|
||||
ProgramObject BlendFace::_eyeProgram;
|
||||
GLuint BlendFace::_eyeTextureID;
|
||||
|
||||
void BlendFace::init() {
|
||||
if (_eyeTextureID == 0) {
|
||||
if (!_eyeProgram.isLinked()) {
|
||||
switchToResourcesParentIfRequired();
|
||||
_eyeProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/eye.vert");
|
||||
_eyeProgram.addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/iris.frag");
|
||||
_eyeProgram.link();
|
||||
|
||||
_eyeProgram.bind();
|
||||
_eyeProgram.setUniformValue("texture", 0);
|
||||
_eyeProgram.release();
|
||||
|
||||
_eyeTextureID = Application::getInstance()->getTextureCache()->getFileTextureID("resources/images/eye.png");
|
||||
}
|
||||
}
|
||||
|
@ -84,6 +94,8 @@ bool BlendFace::render(float alpha) {
|
|||
|
||||
glBindTexture(GL_TEXTURE_2D, _eyeTextureID);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
_eyeProgram.bind();
|
||||
}
|
||||
|
||||
// all meshes after the first are white
|
||||
|
@ -128,9 +140,10 @@ bool BlendFace::render(float alpha) {
|
|||
GL_UNSIGNED_INT, (void*)(mesh.quadIndices.size() * sizeof(int)));
|
||||
|
||||
if (mesh.isEye) {
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
_eyeProgram.release();
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "InterfaceConfig.h"
|
||||
#include "renderer/FBXReader.h"
|
||||
#include "renderer/ProgramObject.h"
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
|
@ -61,6 +62,7 @@ private:
|
|||
QVector<glm::vec3> _blendedVertices;
|
||||
QVector<glm::vec3> _blendedNormals;
|
||||
|
||||
static ProgramObject _eyeProgram;
|
||||
static GLuint _eyeTextureID;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue