From c3c2265ddd3e89ae3f66596f82c553b4fc085bd2 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 30 Jul 2014 18:14:11 -0700 Subject: [PATCH] Hide the unset (black) bits. --- .../resources/shaders/metavoxel_heightfield.vert | 10 +++++----- interface/src/MetavoxelSystem.cpp | 15 +++++++++++++-- libraries/metavoxels/src/AttributeRegistry.cpp | 3 ++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/interface/resources/shaders/metavoxel_heightfield.vert b/interface/resources/shaders/metavoxel_heightfield.vert index a5e7ec66c1..3cf43e87cd 100644 --- a/interface/resources/shaders/metavoxel_heightfield.vert +++ b/interface/resources/shaders/metavoxel_heightfield.vert @@ -21,13 +21,13 @@ void main(void) { // transform and store the normal for interpolation normal = normalize(gl_ModelViewMatrix * vec4(0.0, 1.0, 0.0, 0.0)); - // pass along the vertex color - gl_FrontColor = gl_Color; - // pass along the texture coordinates gl_TexCoord[0] = gl_MultiTexCoord0; // add the height to the position - gl_Position = gl_ModelViewProjectionMatrix * (gl_Vertex + - vec4(0.0, texture2D(heightMap, gl_MultiTexCoord0.st).r, 0.0, 0.0)); + float height = texture2D(heightMap, gl_MultiTexCoord0.st).r; + gl_Position = gl_ModelViewProjectionMatrix * (gl_Vertex + vec4(0.0, height, 0.0, 0.0)); + + // the zero height should be invisible + gl_FrontColor = vec4(1.0, 1.0, 1.0, step(height, 0.0)); } diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index d357ab5ce4..16ce98c65c 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -397,7 +397,11 @@ void HeightfieldBuffer::render() { QHash HeightfieldBuffer::_bufferPairs; void HeightfieldPreview::render(const glm::vec3& translation, float scale) const { - glColor4f(1.0f, 1.0f, 1.0f, 0.75f); + glDisable(GL_BLEND); + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_EQUAL, 0.0f); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); @@ -418,6 +422,9 @@ void HeightfieldPreview::render(const glm::vec3& translation, float scale) const glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); + + glDisable(GL_ALPHA_TEST); + glEnable(GL_BLEND); } BufferDataAttribute::BufferDataAttribute(const QString& name) : @@ -695,7 +702,10 @@ void DefaultMetavoxelRendererImplementation::render(MetavoxelData& data, Metavox _pointProgram.release(); - glColor4f(1.0f, 1.0f, 1.0f, 0.0f); + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_EQUAL, 0.0f); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); _heightfieldProgram.bind(); @@ -710,6 +720,7 @@ void DefaultMetavoxelRendererImplementation::render(MetavoxelData& data, Metavox glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); + glDisable(GL_ALPHA_TEST); glEnable(GL_BLEND); } diff --git a/libraries/metavoxels/src/AttributeRegistry.cpp b/libraries/metavoxels/src/AttributeRegistry.cpp index 499f8146cf..7219e9da41 100644 --- a/libraries/metavoxels/src/AttributeRegistry.cpp +++ b/libraries/metavoxels/src/AttributeRegistry.cpp @@ -578,7 +578,8 @@ bool HeightfieldAttribute::merge(void*& parent, void* children[], bool postRead) int childSizePlusOne = childSize + 1; for (int z = 0; z < halfSize; z++) { for (char* end = dest + halfSize; dest != end; src += 2) { - *dest++ = yOffset + (qMax(qMax(src[0], src[1]), qMax(src[childSize], src[childSizePlusOne])) >> 1); + int max = qMax(qMax(src[0], src[1]), qMax(src[childSize], src[childSizePlusOne])); + *dest++ = (max == 0) ? 0 : (yOffset + (max >> 1)); } dest += halfSize; src += childSize;