Working on render modes.

This commit is contained in:
Andrzej Kapolka 2014-04-04 14:22:01 -07:00
parent 550a8fdb99
commit a2b94aa433
6 changed files with 37 additions and 16 deletions

View file

@ -436,6 +436,19 @@ void StaticModelRenderer::simulate(float deltaTime) {
}
void StaticModelRenderer::renderUnclipped(float alpha, Mode mode) {
switch (mode) {
case DIFFUSE_MODE:
_model->render(alpha, Model::DIFFUSE_RENDER_MODE);
break;
case NORMAL_MODE:
_model->render(alpha, Model::NORMAL_RENDER_MODE);
break;
default:
_model->render(alpha);
break;
}
_model->render(alpha);
}

View file

@ -326,8 +326,10 @@ void Avatar::renderBody(RenderMode renderMode) {
renderBillboard();
return;
}
_skeletonModel.render(1.0f, renderMode == SHADOW_RENDER_MODE);
getHead()->render(1.0f, renderMode == SHADOW_RENDER_MODE);
Model::RenderMode modelRenderMode = (renderMode == SHADOW_RENDER_MODE) ?
Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE;
_skeletonModel.render(1.0f, modelRenderMode);
getHead()->render(1.0f, modelRenderMode);
getHand()->render(false);
}

View file

@ -642,14 +642,16 @@ void MyAvatar::renderBody(RenderMode renderMode) {
}
// Render the body's voxels and head
_skeletonModel.render(1.0f, renderMode == SHADOW_RENDER_MODE);
Model::RenderMode modelRenderMode = (renderMode == SHADOW_RENDER_MODE) ?
Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE;
_skeletonModel.render(1.0f, modelRenderMode);
// Render head so long as the camera isn't inside it
const float RENDER_HEAD_CUTOFF_DISTANCE = 0.40f;
Camera* myCamera = Application::getInstance()->getCamera();
if (renderMode != NORMAL_RENDER_MODE || (glm::length(myCamera->getPosition() - getHead()->calculateAverageEyePosition()) >
RENDER_HEAD_CUTOFF_DISTANCE * _scale)) {
getHead()->render(1.0f, renderMode == SHADOW_RENDER_MODE);
getHead()->render(1.0f, modelRenderMode);
}
getHand()->render(true);
}

View file

@ -284,7 +284,7 @@ bool Model::updateGeometry() {
bool Model::render(float alpha, RenderMode mode) {
// render the attachments
foreach (Model* attachment, _attachments) {
attachment->render(alpha);
attachment->render(alpha, mode);
}
if (_meshStates.isEmpty()) {
return false;
@ -305,7 +305,11 @@ bool Model::render(float alpha, RenderMode mode) {
glDisable(GL_COLOR_MATERIAL);
// glEnable(GL_CULL_FACE);
if (mode == DIFFUSE_RENDER_MODE || mode == NORMAL_RENDER_MODE) {
glDisable(GL_CULL_FACE);
} else {
glEnable(GL_CULL_FACE);
}
// render opaque meshes with alpha testing
@ -316,7 +320,7 @@ bool Model::render(float alpha, RenderMode mode) {
glDisable(GL_ALPHA_TEST);
// render translucent meshes afterwards, with back face culling
// render translucent meshes afterwards
renderMeshes(alpha, mode, true);
@ -1137,7 +1141,7 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent) {
ProgramObject* program = &_program;
ProgramObject* skinProgram = &_skinProgram;
SkinLocations* skinLocations = &_skinLocations;
if (mode == SHADOW_MAP_MODE) {
if (mode == SHADOW_RENDER_MODE) {
program = &_shadowProgram;
skinProgram = &_skinShadowProgram;
skinLocations = &_skinShadowLocations;
@ -1175,7 +1179,7 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent) {
}
if (mesh.blendshapes.isEmpty()) {
if (!(mesh.tangents.isEmpty() || mode == SHADOW_MAP_MODE)) {
if (!(mesh.tangents.isEmpty() || mode == SHADOW_RENDER_MODE)) {
activeProgram->setAttributeBuffer(tangentLocation, GL_FLOAT, vertexCount * 2 * sizeof(glm::vec3), 3);
activeProgram->enableAttributeArray(tangentLocation);
}
@ -1185,7 +1189,7 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent) {
(mesh.tangents.size() + mesh.colors.size()) * sizeof(glm::vec3)));
} else {
if (!(mesh.tangents.isEmpty() || mode == SHADOW_MAP_MODE)) {
if (!(mesh.tangents.isEmpty() || mode == SHADOW_RENDER_MODE)) {
activeProgram->setAttributeBuffer(tangentLocation, GL_FLOAT, 0, 3);
activeProgram->enableAttributeArray(tangentLocation);
}
@ -1214,7 +1218,7 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent) {
continue;
}
// apply material properties
if (mode == SHADOW_MAP_MODE) {
if (mode == SHADOW_RENDER_MODE) {
glBindTexture(GL_TEXTURE_2D, 0);
} else {
@ -1255,7 +1259,7 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent) {
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
if (!(mesh.tangents.isEmpty() || mode == SHADOW_MAP_MODE)) {
if (!(mesh.tangents.isEmpty() || mode == SHADOW_RENDER_MODE)) {
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE0);

View file

@ -58,9 +58,9 @@ public:
void reset();
virtual void simulate(float deltaTime, bool fullUpdate = true);
enum RenderMode { DEFAULT_MODE, SHADOW_MAP_MODE, DIFFUSE_MODE, NORMAL_MODE };
enum RenderMode { DEFAULT_RENDER_MODE, SHADOW_RENDER_MODE, DIFFUSE_RENDER_MODE, NORMAL_RENDER_MODE };
bool render(float alpha = 1.0f, RenderMode mode = DEFAULT_MODE);
bool render(float alpha = 1.0f, RenderMode mode = DEFAULT_RENDER_MODE);
/// Sets the URL of the model to render.
/// \param fallback the URL of a fallback model to render if the requested model fails to load

View file

@ -774,12 +774,12 @@ int VoxelizationVisitor::visit(MetavoxelInfo& info) {
float depth = 1.0f - images.depth.at(y * images.color.width() + x);
float distance = depth - relative.z;
float extent = images.scale.z * halfSize;
if (distance < 0.0f) {
if (distance < -extent - EPSILON) {
info.outputValues[0] = AttributeValue(_outputs.at(0));
return STOP_RECURSION;
}
QRgb color = images.color.pixel(x, y);
if (distance < EPSILON) {
if (distance < extent + EPSILON) {
info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline<QRgb>(color));
return STOP_RECURSION;
}