mirror of
https://github.com/lubosz/overte.git
synced 2025-04-17 18:48:20 +02:00
Working on face rendering as point cloud.
This commit is contained in:
parent
763e6a2fa1
commit
411cb92300
6 changed files with 231 additions and 1 deletions
interface
17
interface/resources/shaders/face.frag
Normal file
17
interface/resources/shaders/face.frag
Normal file
|
@ -0,0 +1,17 @@
|
|||
#version 120
|
||||
|
||||
//
|
||||
// iris.frag
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Andrzej Kapolka on 6/13/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
// the color texture
|
||||
uniform sampler2D colorTexture;
|
||||
|
||||
void main(void) {
|
||||
// modulate texture by diffuse color and add specular contribution
|
||||
gl_FragColor = gl_Color * texture2D(colorTexture, gl_TexCoord[0].st);
|
||||
}
|
28
interface/resources/shaders/face.vert
Normal file
28
interface/resources/shaders/face.vert
Normal file
|
@ -0,0 +1,28 @@
|
|||
#version 120
|
||||
|
||||
//
|
||||
// face.vert
|
||||
// vertex shader
|
||||
//
|
||||
// Created by Andrzej Kapolka on 7/12/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
// the lower left texture coordinate
|
||||
uniform vec2 texCoordCorner;
|
||||
|
||||
// the texture coordinate vector from left to right
|
||||
uniform vec2 texCoordRight;
|
||||
|
||||
// the texture coordinate vector from bottom to the top
|
||||
uniform vec2 texCoordUp;
|
||||
|
||||
// the depth texture
|
||||
uniform sampler2D depthTexture;
|
||||
|
||||
void main(void) {
|
||||
gl_TexCoord[0] = vec4(texCoordCorner + gl_Vertex.x * texCoordRight + gl_Vertex.y * texCoordUp, 0.0, 1.0);
|
||||
gl_FrontColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vec4(0.5 - gl_Vertex.x,
|
||||
gl_Vertex.y * length(texCoordUp) / length(texCoordRight), -texture2D(depthTexture, gl_TexCoord[0].st).r, 1.0);
|
||||
}
|
|
@ -406,7 +406,7 @@ void FrameGrabber::grabFrame() {
|
|||
depth = Mat(_depthMetaData.YRes(), _depthMetaData.XRes(), CV_16UC1, (void*)_depthGenerator.GetDepthMap());
|
||||
const double EIGHT_BIT_MAX = 255;
|
||||
const double ELEVEN_BIT_MAX = 2047;
|
||||
depth.convertTo(_grayDepthFrame, CV_8UC1, EIGHT_BIT_MAX / ELEVEN_BIT_MAX);
|
||||
depth.convertTo(_grayDepthFrame, CV_8UC1, 1.0, -512);
|
||||
|
||||
_userID = 0;
|
||||
XnUInt16 userCount = 1;
|
||||
|
|
|
@ -310,6 +310,12 @@ void Avatar::updateFromGyrosAndOrWebcam(bool gyroLook,
|
|||
if (webcam->isActive()) {
|
||||
estimatedPosition = webcam->getEstimatedPosition();
|
||||
|
||||
// apply face data
|
||||
_head.getFace().setColorTextureID(webcam->getColorTextureID());
|
||||
_head.getFace().setDepthTextureID(webcam->getDepthTextureID());
|
||||
_head.getFace().setTextureSize(webcam->getTextureSize());
|
||||
_head.getFace().setTextureRect(webcam->getEstimatedFaceRect());
|
||||
|
||||
// compute and store the joint rotations
|
||||
const JointVector& joints = webcam->getEstimatedJoints();
|
||||
_joints.clear();
|
||||
|
@ -324,6 +330,8 @@ void Avatar::updateFromGyrosAndOrWebcam(bool gyroLook,
|
|||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_head.getFace().setColorTextureID(0);
|
||||
}
|
||||
_head.setPitch(estimatedRotation.x * amplifyAngle.x + pitchFromTouch);
|
||||
_head.setYaw(estimatedRotation.y * amplifyAngle.y + yawFromTouch);
|
||||
|
|
131
interface/src/avatar/Face.cpp
Normal file
131
interface/src/avatar/Face.cpp
Normal file
|
@ -0,0 +1,131 @@
|
|||
//
|
||||
// Face.cpp
|
||||
// interface
|
||||
//
|
||||
// Created by Andrzej Kapolka on 7/11/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
#include "Head.h"
|
||||
#include "Face.h"
|
||||
#include "renderer/ProgramObject.h"
|
||||
|
||||
using namespace cv;
|
||||
|
||||
ProgramObject* Face::_program = 0;
|
||||
int Face::_texCoordCornerLocation;
|
||||
int Face::_texCoordRightLocation;
|
||||
int Face::_texCoordUpLocation;
|
||||
GLuint Face::_vboID;
|
||||
|
||||
Face::Face(Head* owningHead) : _owningHead(owningHead), _colorTextureID(0), _depthTextureID(0) {
|
||||
}
|
||||
|
||||
bool Face::render(float alpha) {
|
||||
if (_colorTextureID == 0 || _textureRect.size.area() == 0) {
|
||||
return false;
|
||||
}
|
||||
glPushMatrix();
|
||||
|
||||
glTranslatef(_owningHead->getPosition().x, _owningHead->getPosition().y, _owningHead->getPosition().z);
|
||||
glm::quat orientation = _owningHead->getOrientation();
|
||||
glm::vec3 axis = glm::axis(orientation);
|
||||
//glRotatef(glm::angle(orientation), axis.x, axis.y, axis.z);
|
||||
glScalef(_owningHead->getScale(), _owningHead->getScale(), _owningHead->getScale());
|
||||
|
||||
glColor4f(1.0f, 1.0f, 1.0f, alpha);
|
||||
|
||||
Point2f points[4];
|
||||
_textureRect.points(points);
|
||||
|
||||
float aspect = _textureRect.size.height / _textureRect.size.width;
|
||||
|
||||
if (_depthTextureID != 0) {
|
||||
const int VERTEX_WIDTH = 100;
|
||||
const int VERTEX_HEIGHT = 100;
|
||||
const int VERTEX_COUNT = VERTEX_WIDTH * VERTEX_HEIGHT;
|
||||
const int ELEMENTS_PER_VERTEX = 2;
|
||||
const int BUFFER_ELEMENTS = VERTEX_COUNT * ELEMENTS_PER_VERTEX;
|
||||
|
||||
if (_program == 0) {
|
||||
_program = new ProgramObject();
|
||||
_program->addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/face.vert");
|
||||
_program->addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/face.frag");
|
||||
_program->link();
|
||||
|
||||
_program->bind();
|
||||
_program->setUniformValue("depthTexture", 0);
|
||||
_program->setUniformValue("colorTexture", 1);
|
||||
_program->release();
|
||||
|
||||
_texCoordCornerLocation = _program->uniformLocation("texCoordCorner");
|
||||
_texCoordRightLocation = _program->uniformLocation("texCoordRight");
|
||||
_texCoordUpLocation = _program->uniformLocation("texCoordUp");
|
||||
|
||||
glGenBuffers(1, &_vboID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboID);
|
||||
float* vertices = new float[BUFFER_ELEMENTS];
|
||||
float* vertexPosition = vertices;
|
||||
for (int i = 0; i < VERTEX_HEIGHT; i++) {
|
||||
for (int j = 0; j < VERTEX_WIDTH; j++) {
|
||||
*vertexPosition++ = j / (float)(VERTEX_WIDTH - 1);
|
||||
*vertexPosition++ = i / (float)(VERTEX_HEIGHT - 1);
|
||||
}
|
||||
}
|
||||
glBufferData(GL_ARRAY_BUFFER, BUFFER_ELEMENTS * sizeof(float), vertices, GL_STATIC_DRAW);
|
||||
delete[] vertices;
|
||||
|
||||
} else {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboID);
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, _depthTextureID);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + 1);
|
||||
glBindTexture(GL_TEXTURE_2D, _colorTextureID);
|
||||
|
||||
_program->bind();
|
||||
_program->setUniformValue(_texCoordCornerLocation,
|
||||
points[0].x / _textureSize.width, points[0].y / _textureSize.height);
|
||||
_program->setUniformValue(_texCoordRightLocation,
|
||||
(points[3].x - points[0].x) / _textureSize.width, (points[3].y - points[0].y) / _textureSize.height);
|
||||
_program->setUniformValue(_texCoordUpLocation,
|
||||
(points[1].x - points[0].x) / _textureSize.width, (points[1].y - points[0].y) / _textureSize.height);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 0, 0);
|
||||
glPointSize(3.0f);
|
||||
glDrawArrays(GL_POINTS, 0, VERTEX_COUNT);
|
||||
glPointSize(1.0f);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
_program->release();
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, _colorTextureID);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(points[0].x / _textureSize.width, points[0].y / _textureSize.height);
|
||||
glVertex3f(0.5f, 0, 0);
|
||||
glTexCoord2f(points[1].x / _textureSize.width, points[1].y / _textureSize.height);
|
||||
glVertex3f(0.5f, aspect, 0);
|
||||
glTexCoord2f(points[2].x / _textureSize.width, points[2].y / _textureSize.height);
|
||||
glVertex3f(-0.5f, aspect, 0);
|
||||
glTexCoord2f(points[3].x / _textureSize.width, points[3].y / _textureSize.height);
|
||||
glVertex3f(-0.5f, 0, 0);
|
||||
glEnd();
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
46
interface/src/avatar/Face.h
Normal file
46
interface/src/avatar/Face.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
//
|
||||
// Face.h
|
||||
// interface
|
||||
//
|
||||
// Created by Andrzej Kapolka on 7/11/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __interface__Face__
|
||||
#define __interface__Face__
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
#include "InterfaceConfig.h"
|
||||
|
||||
class Head;
|
||||
class ProgramObject;
|
||||
|
||||
class Face {
|
||||
public:
|
||||
|
||||
Face(Head* owningHead);
|
||||
|
||||
void setColorTextureID(GLuint colorTextureID) { _colorTextureID = colorTextureID; }
|
||||
void setDepthTextureID(GLuint depthTextureID) { _depthTextureID = depthTextureID; }
|
||||
void setTextureSize(const cv::Size2f& textureSize) { _textureSize = textureSize; }
|
||||
void setTextureRect(const cv::RotatedRect& textureRect) { _textureRect = textureRect; }
|
||||
|
||||
bool render(float alpha);
|
||||
|
||||
private:
|
||||
|
||||
Head* _owningHead;
|
||||
GLuint _colorTextureID;
|
||||
GLuint _depthTextureID;
|
||||
cv::Size2f _textureSize;
|
||||
cv::RotatedRect _textureRect;
|
||||
|
||||
static ProgramObject* _program;
|
||||
static int _texCoordCornerLocation;
|
||||
static int _texCoordRightLocation;
|
||||
static int _texCoordUpLocation;
|
||||
static GLuint _vboID;
|
||||
};
|
||||
|
||||
#endif /* defined(__interface__Face__) */
|
Loading…
Reference in a new issue