mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-24 06:40:04 +02:00
Per-pixel shading, material tweaks.
This commit is contained in:
parent
e97cfb8cf8
commit
d06acdd169
6 changed files with 26 additions and 38 deletions
|
@ -15,10 +15,15 @@ uniform sampler2D texture;
|
||||||
varying vec4 normal;
|
varying vec4 normal;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
// compute the specular component (sans exponent) based on the normal OpenGL lighting model
|
// compute the base color based on OpenGL lighting model
|
||||||
float specular = max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), normalize(normal)));
|
vec4 normalizedNormal = normalize(normal);
|
||||||
|
vec4 base = gl_FrontLightModelProduct.sceneColor + gl_FrontLightProduct[0].ambient +
|
||||||
|
gl_FrontLightProduct[0].diffuse * max(0.0, dot(normalizedNormal, gl_LightSource[0].position));
|
||||||
|
|
||||||
// modulate texture by diffuse color and add specular contribution
|
// compute the specular component (sans exponent)
|
||||||
gl_FragColor = gl_Color * texture2D(texture, gl_TexCoord[0].st) +
|
float specular = max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)), normalizedNormal));
|
||||||
|
|
||||||
|
// modulate texture by base color and add specular contribution
|
||||||
|
gl_FragColor = base * texture2D(texture, gl_TexCoord[0].st) +
|
||||||
pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular;
|
pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,6 @@ 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
|
|
||||||
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
|
// pass along the texture coordinate
|
||||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||||
|
|
||||||
|
|
|
@ -31,10 +31,6 @@ void main(void) {
|
||||||
position = gl_ModelViewProjectionMatrix * position;
|
position = gl_ModelViewProjectionMatrix * position;
|
||||||
normal = normalize(gl_ModelViewMatrix * normal);
|
normal = normalize(gl_ModelViewMatrix * normal);
|
||||||
|
|
||||||
// standard diffuse lighting
|
|
||||||
gl_FrontColor = (gl_LightModel.ambient + gl_LightSource[0].ambient +
|
|
||||||
gl_LightSource[0].diffuse * max(0.0, dot(normal, gl_LightSource[0].position)));
|
|
||||||
|
|
||||||
// pass along the texture coordinate
|
// pass along the texture coordinate
|
||||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ void BlendFace::simulate(float deltaTime) {
|
||||||
|
|
||||||
glm::quat orientation = static_cast<Avatar*>(_owningHead->_owningAvatar)->getOrientation();
|
glm::quat orientation = static_cast<Avatar*>(_owningHead->_owningAvatar)->getOrientation();
|
||||||
glm::vec3 scale = glm::vec3(-1.0f, 1.0f, -1.0f) * _owningHead->getScale() * MODEL_SCALE;
|
glm::vec3 scale = glm::vec3(-1.0f, 1.0f, -1.0f) * _owningHead->getScale() * MODEL_SCALE;
|
||||||
glm::vec3 offset = MODEL_TRANSLATION - _geometry->getFBXGeometry().neckPivot;
|
glm::vec3 offset = MODEL_TRANSLATION - geometry.neckPivot;
|
||||||
glm::mat4 baseTransform = glm::translate(_owningHead->getPosition()) * glm::mat4_cast(orientation) *
|
glm::mat4 baseTransform = glm::translate(_owningHead->getPosition()) * glm::mat4_cast(orientation) *
|
||||||
glm::scale(scale) * glm::translate(offset);
|
glm::scale(scale) * glm::translate(offset);
|
||||||
|
|
||||||
|
@ -239,14 +239,8 @@ bool BlendFace::render(float alpha) {
|
||||||
glEnableClientState(GL_NORMAL_ARRAY);
|
glEnableClientState(GL_NORMAL_ARRAY);
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
|
||||||
// enable normalization under the expectation that the GPU can do it faster
|
|
||||||
glEnable(GL_NORMALIZE);
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
glDisable(GL_COLOR_MATERIAL);
|
glDisable(GL_COLOR_MATERIAL);
|
||||||
|
|
||||||
// the eye shader uses the color state even though color material is disabled
|
|
||||||
glColor4f(1.0f, 1.0f, 1.0f, alpha);
|
|
||||||
|
|
||||||
for (int i = 0; i < networkMeshes.size(); i++) {
|
for (int i = 0; i < networkMeshes.size(); i++) {
|
||||||
const NetworkMesh& networkMesh = networkMeshes.at(i);
|
const NetworkMesh& networkMesh = networkMeshes.at(i);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, networkMesh.indexBufferID);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, networkMesh.indexBufferID);
|
||||||
|
@ -361,9 +355,6 @@ bool BlendFace::render(float alpha) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glDisable(GL_NORMALIZE);
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
|
||||||
|
|
||||||
// deactivate vertex arrays after drawing
|
// deactivate vertex arrays after drawing
|
||||||
glDisableClientState(GL_NORMAL_ARRAY);
|
glDisableClientState(GL_NORMAL_ARRAY);
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
|
|
|
@ -722,6 +722,13 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
||||||
joint.preRotation = model.preRotation;
|
joint.preRotation = model.preRotation;
|
||||||
joint.rotation = model.rotation;
|
joint.rotation = model.rotation;
|
||||||
joint.postRotation = model.postRotation;
|
joint.postRotation = model.postRotation;
|
||||||
|
if (joint.parentIndex == -1) {
|
||||||
|
joint.transform = geometry.offset * model.preRotation * glm::mat4_cast(model.rotation) * model.postRotation;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
joint.transform = geometry.joints.at(joint.parentIndex).transform *
|
||||||
|
model.preRotation * glm::mat4_cast(model.rotation) * model.postRotation;
|
||||||
|
}
|
||||||
geometry.joints.append(joint);
|
geometry.joints.append(joint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -730,6 +737,12 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
||||||
geometry.rightEyeJointIndex = modelIDs.indexOf(jointEyeRightID);
|
geometry.rightEyeJointIndex = modelIDs.indexOf(jointEyeRightID);
|
||||||
geometry.neckJointIndex = modelIDs.indexOf(jointNeckID);
|
geometry.neckJointIndex = modelIDs.indexOf(jointNeckID);
|
||||||
|
|
||||||
|
// extract the translation component of the neck transform
|
||||||
|
if (geometry.neckJointIndex != -1) {
|
||||||
|
const glm::mat4& transform = geometry.joints.at(geometry.neckJointIndex).transform;
|
||||||
|
geometry.neckPivot = glm::vec3(transform[3][0], transform[3][1], transform[3][2]);
|
||||||
|
}
|
||||||
|
|
||||||
QVariantHash springs = mapping.value("spring").toHash();
|
QVariantHash springs = mapping.value("spring").toHash();
|
||||||
QVariant defaultSpring = springs.value("default");
|
QVariant defaultSpring = springs.value("default");
|
||||||
for (QHash<qint64, FBXMesh>::iterator it = meshes.begin(); it != meshes.end(); it++) {
|
for (QHash<qint64, FBXMesh>::iterator it = meshes.begin(); it != meshes.end(); it++) {
|
||||||
|
@ -775,18 +788,11 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
||||||
if (jointID == jointEyeLeftID || jointID == jointEyeRightID) {
|
if (jointID == jointEyeLeftID || jointID == jointEyeRightID) {
|
||||||
mesh.isEye = true;
|
mesh.isEye = true;
|
||||||
}
|
}
|
||||||
|
// see http://stackoverflow.com/questions/13566608/loading-skinning-information-from-fbx for a discussion
|
||||||
|
// of skinning information in FBX
|
||||||
fbxCluster.jointIndex = modelIDs.indexOf(jointID);
|
fbxCluster.jointIndex = modelIDs.indexOf(jointID);
|
||||||
fbxCluster.inverseBindMatrix = glm::inverse(cluster.transformLink) * modelTransform;
|
fbxCluster.inverseBindMatrix = glm::inverse(cluster.transformLink) * modelTransform;
|
||||||
mesh.clusters.append(fbxCluster);
|
mesh.clusters.append(fbxCluster);
|
||||||
|
|
||||||
// see http://stackoverflow.com/questions/13566608/loading-skinning-information-from-fbx for a discussion
|
|
||||||
// of skinning information in FBX
|
|
||||||
glm::mat4 jointTransform = geometry.offset * getGlobalTransform(parentMap, models, jointID);
|
|
||||||
mesh.transform = jointTransform * glm::inverse(cluster.transformLink) * modelTransform;
|
|
||||||
|
|
||||||
// extract translation component for pivot
|
|
||||||
glm::mat4 jointTransformScaled = geometry.offset * getGlobalTransform(parentMap, models, jointID);
|
|
||||||
mesh.pivot = glm::vec3(jointTransformScaled[3][0], jointTransformScaled[3][1], jointTransformScaled[3][2]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -865,10 +871,6 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
||||||
geometry.meshes.append(mesh);
|
geometry.meshes.append(mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract translation component for neck pivot
|
|
||||||
glm::mat4 neckTransform = geometry.offset * getGlobalTransform(parentMap, models, jointNeckID);
|
|
||||||
geometry.neckPivot = glm::vec3(neckTransform[3][0], neckTransform[3][1], neckTransform[3][2]);
|
|
||||||
|
|
||||||
return geometry;
|
return geometry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ public:
|
||||||
glm::mat4 preRotation;
|
glm::mat4 preRotation;
|
||||||
glm::quat rotation;
|
glm::quat rotation;
|
||||||
glm::mat4 postRotation;
|
glm::mat4 postRotation;
|
||||||
|
glm::mat4 transform;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A single binding to a joint in an FBX document.
|
/// A single binding to a joint in an FBX document.
|
||||||
|
@ -69,9 +70,6 @@ public:
|
||||||
|
|
||||||
QVector<FBXCluster> clusters;
|
QVector<FBXCluster> clusters;
|
||||||
|
|
||||||
glm::vec3 pivot;
|
|
||||||
glm::mat4 transform;
|
|
||||||
|
|
||||||
bool isEye;
|
bool isEye;
|
||||||
|
|
||||||
glm::vec3 diffuseColor;
|
glm::vec3 diffuseColor;
|
||||||
|
|
Loading…
Reference in a new issue