History

Yet more heightfield spanner bits.

Andrzej Kapolka committed 12 years ago

Commit d05bb491 parent 16bf2a38 files · +187 −321Browse files

Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 8 files). Show all

Unified · Split

interface/src/MetavoxelSystem.cpp+95−22
@@ -2868,7 +2868,7 @@ void SphereRenderer::render(const glm::vec4& color, Mode mode) { · 2867 unmodified lines
2868 glm::vec3 axis = glm::axis(rotation);2868 glm::vec3 axis = glm::axis(rotation);
2869 glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);2869 glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
2870 2870
2871 Application::getInstance()->getGeometryCache()->renderSphere(sphere->getScale(), 10, 10);2871 Application::getInstance()->getDeferredLightingEffect()->renderSolidSphere(sphere->getScale(), 32, 32);
2872 2872
2873 glPopMatrix();2873 glPopMatrix();
2874}2874}
@@ -2889,7 +2889,7 @@ void CuboidRenderer::render(const glm::vec4& color, Mode mode) { · 14 unmodified lines
2889 glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);2889 glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
2890 glScalef(1.0f, cuboid->getAspectY(), cuboid->getAspectZ());2890 glScalef(1.0f, cuboid->getAspectY(), cuboid->getAspectZ());
2891 2891
2892 glutSolidCube(cuboid->getScale() * 2.0f);2892 Application::getInstance()->getDeferredLightingEffect()->renderSolidCube(cuboid->getScale() * 2.0f);
2893 2893
2894 glPopMatrix();2894 glPopMatrix();
2895}2895}
@@ -3038,12 +3038,12 @@ void HeightfieldRenderer::render(const glm::vec4& color, Mode mode) { · 142 unmodified lines
3038 float xStep = 1.0f / (innerWidth - 1);3038 float xStep = 1.0f / (innerWidth - 1);
3039 float zStep = 1.0f / (innerHeight - 1);3039 float zStep = 1.0f / (innerHeight - 1);
3040 float z = -zStep;3040 float z = -zStep;
3041 float sStep = 1.0f / innerWidth;3041 float sStep = 1.0f / width;
3042 float tStep = 1.0f / innerHeight;3042 float tStep = 1.0f / height;
3043 float t = -tStep / 2.0f;3043 float t = tStep / 2.0f;
3044 for (int i = 0; i < height; i++, z += zStep, t += tStep) {3044 for (int i = 0; i < height; i++, z += zStep, t += tStep) {
3045 float x = -xStep;3045 float x = -xStep;
3046 float s = -sStep / 2.0f;3046 float s = sStep / 2.0f;
3047 const float SKIRT_LENGTH = 0.25f;3047 const float SKIRT_LENGTH = 0.25f;
3048 float baseY = (i == 0 || i == height - 1) ? -SKIRT_LENGTH : 0.0f;3048 float baseY = (i == 0 || i == height - 1) ? -SKIRT_LENGTH : 0.0f;
3049 for (int j = 0; j < width; j++, point++, x += xStep, s += sStep) {3049 for (int j = 0; j < width; j++, point++, x += xStep, s += sStep) {
@@ -3086,8 +3086,8 @@ void HeightfieldRenderer::render(const glm::vec4& color, Mode mode) { · 36 unmodified lines
3086 glTranslatef(heightfield->getTranslation().x, heightfield->getTranslation().y, heightfield->getTranslation().z);3086 glTranslatef(heightfield->getTranslation().x, heightfield->getTranslation().y, heightfield->getTranslation().z);
3087 glm::vec3 axis = glm::axis(heightfield->getRotation());3087 glm::vec3 axis = glm::axis(heightfield->getRotation());
3088 glRotatef(glm::degrees(glm::angle(heightfield->getRotation())), axis.x, axis.y, axis.z);3088 glRotatef(glm::degrees(glm::angle(heightfield->getRotation())), axis.x, axis.y, axis.z);
3089 glScalef(heightfield->getScale(), heightfield->getScale() * heightfield->getAspectY(),3089 float xScale = heightfield->getScale(), zScale = xScale * heightfield->getAspectZ();
3090 heightfield->getScale() * heightfield->getAspectZ());3090 glScalef(xScale, xScale * heightfield->getAspectY(), zScale);
3091 3091
3092 Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, true);3092 Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, true);
3093 3093
@@ -3106,17 +3106,16 @@ void HeightfieldRenderer::render(const glm::vec4& color, Mode mode) { · 12 unmodified lines
3106 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);3106 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
3107 3107
3108 DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().bind();3108 DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().bind();
3109 float sDistance = 2.0f / (innerWidth - 1);
3110 float tDistance = 2.0f / (innerHeight - 1);
3111 float distanceProduct = -sDistance * tDistance;
3109 DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().setUniformValue(3112 DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().setUniformValue(
3110 DefaultMetavoxelRendererImplementation::getBaseHeightScaleLocation(), 1.0f / innerWidth, 1.0f / innerHeight,3113 DefaultMetavoxelRendererImplementation::getBaseHeightScaleLocation(), 1.0f / width, 1.0f / height,
3111 2.0f / (innerWidth * innerHeight));3114 sDistance / distanceProduct, tDistance / distanceProduct);
3112 if (heightfield->getColor()) {3115 DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().setUniformValue(
3113 int colorWidth = heightfield->getColor()->getWidth();3116 DefaultMetavoxelRendererImplementation::getBaseColorScaleLocation(), (float)width / innerWidth,
3114 int colorHeight = heightfield->getColor()->getContents().size() / (colorWidth * DataBlock::COLOR_BYTES);3117 (float)height / innerHeight);
3115 DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().setUniformValue(3118
3116 DefaultMetavoxelRendererImplementation::getBaseColorScaleLocation(), (float)innerWidth / colorWidth,
3117 (float)innerHeight / colorHeight);
3118 }
3119
3120 glBindTexture(GL_TEXTURE_2D, _heightTextureID);3119 glBindTexture(GL_TEXTURE_2D, _heightTextureID);
3121 3120
3122 glActiveTexture(GL_TEXTURE1);3121 glActiveTexture(GL_TEXTURE1);
@@ -3127,19 +3126,93 @@ void HeightfieldRenderer::render(const glm::vec4& color, Mode mode) { · 4 unmodified lines
3127 glBindTexture(GL_TEXTURE_2D, 0);3126 glBindTexture(GL_TEXTURE_2D, 0);
3128 glActiveTexture(GL_TEXTURE0); 3127 glActiveTexture(GL_TEXTURE0);
3129 3128
3130 glBindTexture(GL_TEXTURE_2D, 0);3129 Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false);
3131 3130
3132 DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().release();3131 DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().release();
3133 3132
3134 glDisable(GL_ALPHA_TEST);3133 glDisable(GL_ALPHA_TEST);
3135 glDisable(GL_CULL_FACE);
3136 glEnable(GL_BLEND);3134 glEnable(GL_BLEND);
3137 3135
3136 if (heightfield->getMaterial() && !_networkTextures.isEmpty()) {
3137 glDepthFunc(GL_LEQUAL);
3138 glDepthMask(false);
3139 glEnable(GL_POLYGON_OFFSET_FILL);
3140 glPolygonOffset(-1.0f, -1.0f);
3141
3142 DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().bind();
3143 const DefaultMetavoxelRendererImplementation::SplatLocations& locations =
3144 DefaultMetavoxelRendererImplementation::getSplatHeightfieldLocations();
3145 DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue(
3146 locations.heightScale, 1.0f / width, 1.0f / height);
3147 DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue(
3148 locations.textureScale, (float)width / innerWidth, (float)height / innerHeight);
3149 DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue(locations.splatTextureOffset,
3150 glm::dot(heightfield->getTranslation(), heightfield->getRotation() * glm::vec3(1.0f, 0.0f, 0.0f)) / xScale,
3151 glm::dot(heightfield->getTranslation(), heightfield->getRotation() * glm::vec3(0.0f, 0.0f, 1.0f)) / zScale);
3152
3153 glBindTexture(GL_TEXTURE_2D, _materialTextureID);
3154
3155 const QVector<SharedObjectPointer>& materials = heightfield->getMaterial()->getMaterials();
3156 for (int i = 0; i < materials.size(); i += SPLAT_COUNT) {
3157 QVector4D scalesS, scalesT;
3158
3159 for (int j = 0; j < SPLAT_COUNT; j++) {
3160 glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[j]);
3161 int index = i + j;
3162 if (index < _networkTextures.size()) {
3163 const NetworkTexturePointer& texture = _networkTextures.at(index);
3164 if (texture) {
3165 MaterialObject* material = static_cast<MaterialObject*>(materials.at(index).data());
3166 scalesS[j] = xScale / material->getScaleS();
3167 scalesT[j] = zScale / material->getScaleT();
3168 glBindTexture(GL_TEXTURE_2D, texture->getID());
3169 } else {
3170 glBindTexture(GL_TEXTURE_2D, 0);
3171 }
3172 } else {
3173 glBindTexture(GL_TEXTURE_2D, 0);
3174 }
3175 }
3176 const float QUARTER_STEP = 0.25f * EIGHT_BIT_MAXIMUM_RECIPROCAL;
3177 DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue(
3178 locations.splatTextureScalesS, scalesS);
3179 DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue(
3180 locations.splatTextureScalesT, scalesT);
3181 DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue(
3182 locations.textureValueMinima,
3183 (i + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, (i + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP,
3184 (i + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, (i + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP);
3185 DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue(
3186 locations.textureValueMaxima,
3187 (i + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, (i + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP,
3188 (i + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, (i + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP);
3189 glDrawRangeElements(GL_TRIANGLES, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0);
3190 }
3191
3192 for (int i = 0; i < SPLAT_COUNT; i++) {
3193 glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[i]);
3194 glBindTexture(GL_TEXTURE_2D, 0);
3195 }
3196
3197 glActiveTexture(GL_TEXTURE1);
3198 glBindTexture(GL_TEXTURE_2D, 0);
3199
3200 glActiveTexture(GL_TEXTURE0);
3201
3202 DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().release();
3203
3204 glDisable(GL_POLYGON_OFFSET_FILL);
3205 glDepthMask(true);
3206 glDepthFunc(GL_LESS);
3207 }
3208
3209 glBindTexture(GL_TEXTURE_2D, 0);
3210
3211 glDisable(GL_CULL_FACE);
3212
3138 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 3213 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
3139 glDisableClientState(GL_VERTEX_ARRAY); 3214 glDisableClientState(GL_VERTEX_ARRAY);
3140 3215
3141 Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true);
3142
3143 glPopMatrix();3216 glPopMatrix();
3144 3217
3145 bufferPair.first.release();3218 bufferPair.first.release();