mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 14:54:29 +02:00
Working on model rendering modes.
This commit is contained in:
parent
38022d2440
commit
a0c7e4d3cc
11 changed files with 50 additions and 37 deletions
|
@ -183,7 +183,7 @@ Menu::Menu() :
|
|||
#ifdef HAVE_QXMPP
|
||||
_chatAction = addActionToQMenuAndActionHash(toolsMenu,
|
||||
MenuOption::Chat,
|
||||
Qt::Key_Return,
|
||||
0,
|
||||
this,
|
||||
SLOT(showChat()));
|
||||
|
||||
|
|
|
@ -228,7 +228,7 @@ MetavoxelSystem::RenderVisitor::RenderVisitor() :
|
|||
}
|
||||
|
||||
bool MetavoxelSystem::RenderVisitor::visit(Spanner* spanner, const glm::vec3& clipMinimum, float clipSize) {
|
||||
spanner->getRenderer()->render(1.0f, clipMinimum, clipSize);
|
||||
spanner->getRenderer()->render(1.0f, SpannerRenderer::DEFAULT_MODE, clipMinimum, clipSize);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -345,9 +345,9 @@ static void enableClipPlane(GLenum plane, float x, float y, float z, float w) {
|
|||
glEnable(plane);
|
||||
}
|
||||
|
||||
void ClippedRenderer::render(float alpha, const glm::vec3& clipMinimum, float clipSize) {
|
||||
void ClippedRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimum, float clipSize) {
|
||||
if (clipSize == 0.0f) {
|
||||
renderUnclipped(alpha);
|
||||
renderUnclipped(alpha, mode);
|
||||
return;
|
||||
}
|
||||
enableClipPlane(GL_CLIP_PLANE0, -1.0f, 0.0f, 0.0f, clipMinimum.x + clipSize);
|
||||
|
@ -357,7 +357,7 @@ void ClippedRenderer::render(float alpha, const glm::vec3& clipMinimum, float cl
|
|||
enableClipPlane(GL_CLIP_PLANE4, 0.0f, 0.0f, -1.0f, clipMinimum.z + clipSize);
|
||||
enableClipPlane(GL_CLIP_PLANE5, 0.0f, 0.0f, 1.0f, -clipMinimum.z);
|
||||
|
||||
renderUnclipped(alpha);
|
||||
renderUnclipped(alpha, mode);
|
||||
|
||||
glDisable(GL_CLIP_PLANE0);
|
||||
glDisable(GL_CLIP_PLANE1);
|
||||
|
@ -370,9 +370,9 @@ void ClippedRenderer::render(float alpha, const glm::vec3& clipMinimum, float cl
|
|||
SphereRenderer::SphereRenderer() {
|
||||
}
|
||||
|
||||
void SphereRenderer::render(float alpha, const glm::vec3& clipMinimum, float clipSize) {
|
||||
void SphereRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimum, float clipSize) {
|
||||
if (clipSize == 0.0f) {
|
||||
renderUnclipped(alpha);
|
||||
renderUnclipped(alpha, mode);
|
||||
return;
|
||||
}
|
||||
// slight performance optimization: don't render if clip bounds are entirely within sphere
|
||||
|
@ -381,13 +381,13 @@ void SphereRenderer::render(float alpha, const glm::vec3& clipMinimum, float cli
|
|||
for (int i = 0; i < Box::VERTEX_COUNT; i++) {
|
||||
const float CLIP_PROPORTION = 0.95f;
|
||||
if (glm::distance(sphere->getTranslation(), clipBox.getVertex(i)) >= sphere->getScale() * CLIP_PROPORTION) {
|
||||
ClippedRenderer::render(alpha, clipMinimum, clipSize);
|
||||
ClippedRenderer::render(alpha, mode, clipMinimum, clipSize);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SphereRenderer::renderUnclipped(float alpha) {
|
||||
void SphereRenderer::renderUnclipped(float alpha, Mode mode) {
|
||||
Sphere* sphere = static_cast<Sphere*>(parent());
|
||||
const QColor& color = sphere->getColor();
|
||||
glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF() * alpha);
|
||||
|
@ -435,7 +435,7 @@ void StaticModelRenderer::simulate(float deltaTime) {
|
|||
_model->simulate(deltaTime);
|
||||
}
|
||||
|
||||
void StaticModelRenderer::renderUnclipped(float alpha) {
|
||||
void StaticModelRenderer::renderUnclipped(float alpha, Mode mode) {
|
||||
_model->render(alpha);
|
||||
}
|
||||
|
||||
|
|
|
@ -147,11 +147,11 @@ class ClippedRenderer : public SpannerRenderer {
|
|||
|
||||
public:
|
||||
|
||||
virtual void render(float alpha, const glm::vec3& clipMinimum, float clipSize);
|
||||
virtual void render(float alpha, Mode mode, const glm::vec3& clipMinimum, float clipSize);
|
||||
|
||||
protected:
|
||||
|
||||
virtual void renderUnclipped(float alpha) = 0;
|
||||
virtual void renderUnclipped(float alpha, Mode mode) = 0;
|
||||
};
|
||||
|
||||
/// Renders spheres.
|
||||
|
@ -162,11 +162,11 @@ public:
|
|||
|
||||
Q_INVOKABLE SphereRenderer();
|
||||
|
||||
virtual void render(float alpha, const glm::vec3& clipMinimum, float clipSize);
|
||||
virtual void render(float alpha, Mode mode, const glm::vec3& clipMinimum, float clipSize);
|
||||
|
||||
protected:
|
||||
|
||||
virtual void renderUnclipped(float alpha);
|
||||
virtual void renderUnclipped(float alpha, Mode mode);
|
||||
};
|
||||
|
||||
/// Renders static models.
|
||||
|
@ -184,7 +184,7 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
virtual void renderUnclipped(float alpha);
|
||||
virtual void renderUnclipped(float alpha, Mode mode);
|
||||
|
||||
private slots:
|
||||
|
||||
|
|
|
@ -179,8 +179,8 @@ void Head::relaxLean(float deltaTime) {
|
|||
_deltaLeanForward *= relaxationFactor;
|
||||
}
|
||||
|
||||
void Head::render(float alpha, bool forShadowMap) {
|
||||
if (_faceModel.render(alpha, forShadowMap) && _renderLookatVectors) {
|
||||
void Head::render(float alpha, Model::RenderMode mode) {
|
||||
if (_faceModel.render(alpha, mode) && _renderLookatVectors) {
|
||||
renderLookatVectors(_leftEyePosition, _rightEyePosition, _lookAtPosition);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
void init();
|
||||
void reset();
|
||||
void simulate(float deltaTime, bool isMine, bool billboard = false);
|
||||
void render(float alpha, bool forShadowMap);
|
||||
void render(float alpha, Model::RenderMode mode);
|
||||
void setScale(float scale);
|
||||
void setPosition(glm::vec3 position) { _position = position; }
|
||||
void setGravity(glm::vec3 gravity) { _gravity = gravity; }
|
||||
|
|
|
@ -281,7 +281,7 @@ bool Model::updateGeometry() {
|
|||
return needFullUpdate;
|
||||
}
|
||||
|
||||
bool Model::render(float alpha, bool forShadowMap) {
|
||||
bool Model::render(float alpha, RenderMode mode) {
|
||||
// render the attachments
|
||||
foreach (Model* attachment, _attachments) {
|
||||
attachment->render(alpha);
|
||||
|
@ -305,20 +305,20 @@ bool Model::render(float alpha, bool forShadowMap) {
|
|||
|
||||
glDisable(GL_COLOR_MATERIAL);
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
// glEnable(GL_CULL_FACE);
|
||||
|
||||
// render opaque meshes with alpha testing
|
||||
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glAlphaFunc(GL_GREATER, 0.5f * alpha);
|
||||
|
||||
renderMeshes(alpha, forShadowMap, false);
|
||||
renderMeshes(alpha, mode, false);
|
||||
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
|
||||
// render translucent meshes afterwards, with back face culling
|
||||
|
||||
renderMeshes(alpha, forShadowMap, true);
|
||||
renderMeshes(alpha, mode, true);
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
|
@ -1112,7 +1112,7 @@ void Model::deleteGeometry() {
|
|||
}
|
||||
}
|
||||
|
||||
void Model::renderMeshes(float alpha, bool forShadowMap, bool translucent) {
|
||||
void Model::renderMeshes(float alpha, RenderMode mode, bool translucent) {
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
const QVector<NetworkMesh>& networkMeshes = _geometry->getMeshes();
|
||||
|
||||
|
@ -1137,7 +1137,7 @@ void Model::renderMeshes(float alpha, bool forShadowMap, bool translucent) {
|
|||
ProgramObject* program = &_program;
|
||||
ProgramObject* skinProgram = &_skinProgram;
|
||||
SkinLocations* skinLocations = &_skinLocations;
|
||||
if (forShadowMap) {
|
||||
if (mode == SHADOW_MAP_MODE) {
|
||||
program = &_shadowProgram;
|
||||
skinProgram = &_skinShadowProgram;
|
||||
skinLocations = &_skinShadowLocations;
|
||||
|
@ -1175,7 +1175,7 @@ void Model::renderMeshes(float alpha, bool forShadowMap, bool translucent) {
|
|||
}
|
||||
|
||||
if (mesh.blendshapes.isEmpty()) {
|
||||
if (!(mesh.tangents.isEmpty() || forShadowMap)) {
|
||||
if (!(mesh.tangents.isEmpty() || mode == SHADOW_MAP_MODE)) {
|
||||
activeProgram->setAttributeBuffer(tangentLocation, GL_FLOAT, vertexCount * 2 * sizeof(glm::vec3), 3);
|
||||
activeProgram->enableAttributeArray(tangentLocation);
|
||||
}
|
||||
|
@ -1185,7 +1185,7 @@ void Model::renderMeshes(float alpha, bool forShadowMap, bool translucent) {
|
|||
(mesh.tangents.size() + mesh.colors.size()) * sizeof(glm::vec3)));
|
||||
|
||||
} else {
|
||||
if (!(mesh.tangents.isEmpty() || forShadowMap)) {
|
||||
if (!(mesh.tangents.isEmpty() || mode == SHADOW_MAP_MODE)) {
|
||||
activeProgram->setAttributeBuffer(tangentLocation, GL_FLOAT, 0, 3);
|
||||
activeProgram->enableAttributeArray(tangentLocation);
|
||||
}
|
||||
|
@ -1214,7 +1214,7 @@ void Model::renderMeshes(float alpha, bool forShadowMap, bool translucent) {
|
|||
continue;
|
||||
}
|
||||
// apply material properties
|
||||
if (forShadowMap) {
|
||||
if (mode == SHADOW_MAP_MODE) {
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
} else {
|
||||
|
@ -1255,7 +1255,7 @@ void Model::renderMeshes(float alpha, bool forShadowMap, bool translucent) {
|
|||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
|
||||
if (!(mesh.tangents.isEmpty() || forShadowMap)) {
|
||||
if (!(mesh.tangents.isEmpty() || mode == SHADOW_MAP_MODE)) {
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
|
|
@ -57,7 +57,10 @@ public:
|
|||
void init();
|
||||
void reset();
|
||||
virtual void simulate(float deltaTime, bool fullUpdate = true);
|
||||
bool render(float alpha = 1.0f, bool forShadowMap = false);
|
||||
|
||||
enum RenderMode { DEFAULT_MODE, SHADOW_MAP_MODE, DIFFUSE_MODE, NORMAL_MODE };
|
||||
|
||||
bool render(float alpha = 1.0f, RenderMode mode = DEFAULT_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
|
||||
|
@ -254,7 +257,7 @@ private:
|
|||
|
||||
void applyNextGeometry();
|
||||
void deleteGeometry();
|
||||
void renderMeshes(float alpha, bool forShadowMap, bool translucent);
|
||||
void renderMeshes(float alpha, RenderMode mode, bool translucent);
|
||||
QVector<JointState> createJointStates(const FBXGeometry& geometry);
|
||||
|
||||
QSharedPointer<NetworkGeometry> _baseGeometry; ///< reference required to prevent collection of base
|
||||
|
|
|
@ -569,7 +569,7 @@ void PlaceSpannerTool::render() {
|
|||
}
|
||||
Spanner* spanner = static_cast<Spanner*>(_editor->getValue().value<SharedObjectPointer>().data());
|
||||
const float SPANNER_ALPHA = 0.25f;
|
||||
spanner->getRenderer()->render(SPANNER_ALPHA, glm::vec3(), 0.0f);
|
||||
spanner->getRenderer()->render(SPANNER_ALPHA, SpannerRenderer::DEFAULT_MODE, glm::vec3(), 0.0f);
|
||||
}
|
||||
|
||||
bool PlaceSpannerTool::appliesTo(const AttributePointer& attribute) const {
|
||||
|
@ -773,6 +773,7 @@ int VoxelizationVisitor::visit(MetavoxelInfo& info) {
|
|||
int y = qMax(qMin((int)glm::round(relative.y), images.color.height() - 1), 0);
|
||||
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) {
|
||||
info.outputValues[0] = AttributeValue(_outputs.at(0));
|
||||
return STOP_RECURSION;
|
||||
|
@ -838,8 +839,9 @@ void SetSpannerTool::applyEdit(const AttributePointer& attribute, const SharedOb
|
|||
minima = glm::min(minima, rotated);
|
||||
maxima = glm::max(maxima, rotated);
|
||||
}
|
||||
int width = glm::round((maxima.x - minima.x) / spannerData->getVoxelizationGranularity());
|
||||
int height = glm::round((maxima.y - minima.y) / spannerData->getVoxelizationGranularity());
|
||||
float renderGranularity = spannerData->getVoxelizationGranularity() / 4.0f;
|
||||
int width = glm::round((maxima.x - minima.x) / renderGranularity);
|
||||
int height = glm::round((maxima.y - minima.y) / renderGranularity);
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
glScissor(0, 0, width, height);
|
||||
|
@ -857,7 +859,7 @@ void SetSpannerTool::applyEdit(const AttributePointer& attribute, const SharedOb
|
|||
|
||||
Application::getInstance()->updateUntranslatedViewMatrix();
|
||||
|
||||
spannerData->getRenderer()->render(1.0f, glm::vec3(), 0.0f);
|
||||
spannerData->getRenderer()->render(1.0f, SpannerRenderer::DIFFUSE_MODE, glm::vec3(), 0.0f);
|
||||
|
||||
DirectionImages images = { QImage(width, height, QImage::Format_ARGB32),
|
||||
QVector<float>(width * height), minima, maxima, glm::vec3(width / (maxima.x - minima.x),
|
||||
|
@ -866,6 +868,8 @@ void SetSpannerTool::applyEdit(const AttributePointer& attribute, const SharedOb
|
|||
glReadPixels(0, 0, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, images.depth.data());
|
||||
directionImages.append(images);
|
||||
|
||||
images.color.save(QString::number(i) + ".png");
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
}
|
||||
glPopMatrix();
|
||||
|
|
|
@ -869,7 +869,11 @@ Bitstream& Bitstream::operator>(SharedObjectPointer& object) {
|
|||
*this >> rawObject;
|
||||
}
|
||||
pointer = static_cast<SharedObject*>(rawObject);
|
||||
pointer->setRemoteID(id);
|
||||
if (pointer) {
|
||||
pointer->setRemoteID(id);
|
||||
} else {
|
||||
qDebug() << "Null object" << pointer << reference;
|
||||
}
|
||||
}
|
||||
object = static_cast<SharedObject*>(pointer.data());
|
||||
return *this;
|
||||
|
|
|
@ -1527,7 +1527,7 @@ void SpannerRenderer::simulate(float deltaTime) {
|
|||
// nothing by default
|
||||
}
|
||||
|
||||
void SpannerRenderer::render(float alpha, const glm::vec3& clipMinimum, float clipSize) {
|
||||
void SpannerRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimum, float clipSize) {
|
||||
// nothing by default
|
||||
}
|
||||
|
||||
|
|
|
@ -518,11 +518,13 @@ class SpannerRenderer : public QObject {
|
|||
|
||||
public:
|
||||
|
||||
enum Mode { DEFAULT_MODE, DIFFUSE_MODE, NORMAL_MODE };
|
||||
|
||||
Q_INVOKABLE SpannerRenderer();
|
||||
|
||||
virtual void init(Spanner* spanner);
|
||||
virtual void simulate(float deltaTime);
|
||||
virtual void render(float alpha, const glm::vec3& clipMinimum, float clipSize);
|
||||
virtual void render(float alpha, Mode mode, const glm::vec3& clipMinimum, float clipSize);
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
const glm::vec3& clipMinimum, float clipSize, float& distance) const;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue