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
28682868 glm::vec3 axis = glm::axis(rotation);
28692869 glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
28702870
2871− Application::getInstance()->getGeometryCache()->renderSphere(sphere->getScale(), 10, 10);
2871+ Application::getInstance()->getDeferredLightingEffect()->renderSolidSphere(sphere->getScale(), 32, 32);
28722872
28732873 glPopMatrix();
28742874 }
@@ -2889,7 +2889,7 @@ void CuboidRenderer::render(const glm::vec4& color, Mode mode) { · 14 unmodified lines
28892889 glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
28902890 glScalef(1.0f, cuboid->getAspectY(), cuboid->getAspectZ());
28912891
2892− glutSolidCube(cuboid->getScale() * 2.0f);
2892+ Application::getInstance()->getDeferredLightingEffect()->renderSolidCube(cuboid->getScale() * 2.0f);
28932893
28942894 glPopMatrix();
28952895 }
@@ -3038,12 +3038,12 @@ void HeightfieldRenderer::render(const glm::vec4& color, Mode mode) { · 142 unmodified lines
30383038 float xStep = 1.0f / (innerWidth - 1);
30393039 float zStep = 1.0f / (innerHeight - 1);
30403040 float z = -zStep;
3041− float sStep = 1.0f / innerWidth;
3042− float tStep = 1.0f / innerHeight;
3043− float t = -tStep / 2.0f;
3041+ float sStep = 1.0f / width;
3042+ float tStep = 1.0f / height;
3043+ float t = tStep / 2.0f;
30443044 for (int i = 0; i < height; i++, z += zStep, t += tStep) {
30453045 float x = -xStep;
3046− float s = -sStep / 2.0f;
3046+ float s = sStep / 2.0f;
30473047 const float SKIRT_LENGTH = 0.25f;
30483048 float baseY = (i == 0 || i == height - 1) ? -SKIRT_LENGTH : 0.0f;
30493049 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
30863086 glTranslatef(heightfield->getTranslation().x, heightfield->getTranslation().y, heightfield->getTranslation().z);
30873087 glm::vec3 axis = glm::axis(heightfield->getRotation());
30883088 glRotatef(glm::degrees(glm::angle(heightfield->getRotation())), axis.x, axis.y, axis.z);
3089− glScalef(heightfield->getScale(), heightfield->getScale() * heightfield->getAspectY(),
3090− heightfield->getScale() * heightfield->getAspectZ());
3089+ float xScale = heightfield->getScale(), zScale = xScale * heightfield->getAspectZ();
3090+ glScalef(xScale, xScale * heightfield->getAspectY(), zScale);
30913091
30923092 Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, true);
30933093
@@ -3106,17 +3106,16 @@ void HeightfieldRenderer::render(const glm::vec4& color, Mode mode) { · 12 unmodified lines
31063106 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
31073107
31083108 DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().bind();
3109+ float sDistance = 2.0f / (innerWidth - 1);
3110+ float tDistance = 2.0f / (innerHeight - 1);
3111+ float distanceProduct = -sDistance * tDistance;
31093112 DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().setUniformValue(
3110− DefaultMetavoxelRendererImplementation::getBaseHeightScaleLocation(), 1.0f / innerWidth, 1.0f / innerHeight,
3111− 2.0f / (innerWidth * innerHeight));
3112− if (heightfield->getColor()) {
3113− int colorWidth = heightfield->getColor()->getWidth();
3114− int colorHeight = heightfield->getColor()->getContents().size() / (colorWidth * DataBlock::COLOR_BYTES);
3115− DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().setUniformValue(
3116− DefaultMetavoxelRendererImplementation::getBaseColorScaleLocation(), (float)innerWidth / colorWidth,
3117− (float)innerHeight / colorHeight);
3118− }
3119−
3113+ DefaultMetavoxelRendererImplementation::getBaseHeightScaleLocation(), 1.0f / width, 1.0f / height,
3114+ sDistance / distanceProduct, tDistance / distanceProduct);
3115+ DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().setUniformValue(
3116+ DefaultMetavoxelRendererImplementation::getBaseColorScaleLocation(), (float)width / innerWidth,
3117+ (float)height / innerHeight);
3118+
31203119 glBindTexture(GL_TEXTURE_2D, _heightTextureID);
31213120
31223121 glActiveTexture(GL_TEXTURE1);
@@ -3127,19 +3126,93 @@ void HeightfieldRenderer::render(const glm::vec4& color, Mode mode) { · 4 unmodified lines
31273126 glBindTexture(GL_TEXTURE_2D, 0);
31283127 glActiveTexture(GL_TEXTURE0);
31293128
3130− glBindTexture(GL_TEXTURE_2D, 0);
3129+ Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false);
31313130
31323131 DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().release();
31333132
31343133 glDisable(GL_ALPHA_TEST);
3135− glDisable(GL_CULL_FACE);
31363134 glEnable(GL_BLEND);
31373135
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+
31383213 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
31393214 glDisableClientState(GL_VERTEX_ARRAY);
31403215
3141− Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true);
3142−
31433216 glPopMatrix();
31443217
31453218 bufferPair.first.release();