Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 22 files). Show all
Unified · Split
| @@ -9,7 +9,11 @@ · 8 unmodified lines | ||
| 9 | 9 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html |
| 10 | 10 | // |
| 11 | 11 | |
| 12 | +// include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL | |
| 13 | +#include "InterfaceConfig.h" | |
| 14 | + | |
| 12 | 15 | #include <QMutexLocker> |
| 16 | +#include <QOpenGLFramebufferObject> | |
| 13 | 17 | #include <QReadLocker> |
| 14 | 18 | #include <QWriteLocker> |
| 15 | 19 | #include <QtDebug> |
| @@ -24,6 +28,7 @@ · 8 unmodified lines | ||
| 24 | 28 | #include "Application.h" |
| 25 | 29 | #include "MetavoxelSystem.h" |
| 26 | 30 | #include "renderer/Model.h" |
| 31 | +#include "renderer/RenderUtil.h" | |
| 27 | 32 | |
| 28 | 33 | REGISTER_META_OBJECT(DefaultMetavoxelRendererImplementation) |
| 29 | 34 | REGISTER_META_OBJECT(SphereRenderer) |
| @@ -46,6 +51,12 @@ void MetavoxelSystem::init() { · 16 unmodified lines | ||
| 46 | 51 | new BufferDataAttribute("voxelBuffer")); |
| 47 | 52 | _voxelBufferAttribute->setLODThresholdMultiplier( |
| 48 | 53 | AttributeRegistry::getInstance()->getVoxelColorAttribute()->getLODThresholdMultiplier()); |
| 54 | + | |
| 55 | + loadLightProgram("shaders/directional_light.frag", _directionalLight, _directionalLightLocations); | |
| 56 | + loadLightProgram("shaders/directional_light_shadow_map.frag", _directionalLightShadowMap, | |
| 57 | + _directionalLightShadowMapLocations); | |
| 58 | + loadLightProgram("shaders/directional_light_cascaded_shadow_map.frag", _directionalLightCascadedShadowMap, | |
| 59 | + _directionalLightCascadedShadowMapLocations); | |
| 49 | 60 | } |
| 50 | 61 | |
| 51 | 62 | MetavoxelLOD MetavoxelSystem::getLOD() { |
| @@ -116,6 +127,10 @@ int RenderVisitor::visit(MetavoxelInfo& info) { · 64 unmodified lines | ||
| 116 | 127 | return STOP_RECURSION; |
| 117 | 128 | } |
| 118 | 129 | |
| 130 | +const GLenum COLOR_DRAW_BUFFERS[] = { GL_COLOR_ATTACHMENT0 }; | |
| 131 | +const GLenum NORMAL_DRAW_BUFFERS[] = { GL_COLOR_ATTACHMENT1 }; | |
| 132 | +const GLenum COLOR_NORMAL_DRAW_BUFFERS[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 }; | |
| 133 | + | |
| 119 | 134 | void MetavoxelSystem::render() { |
| 120 | 135 | // update the frustum |
| 121 | 136 | ViewFrustum* viewFrustum = Application::getInstance()->getViewFrustum(); |
| @@ -123,8 +138,128 @@ void MetavoxelSystem::render() { · 1 unmodified line | ||
| 123 | 138 | viewFrustum->getFarBottomRight(), viewFrustum->getNearTopLeft(), viewFrustum->getNearTopRight(), |
| 124 | 139 | viewFrustum->getNearBottomLeft(), viewFrustum->getNearBottomRight()); |
| 125 | 140 | |
| 141 | + _needToLight = false; | |
| 142 | + | |
| 143 | + // clear the normal buffer | |
| 144 | + glDrawBuffers(sizeof(NORMAL_DRAW_BUFFERS) / sizeof(NORMAL_DRAW_BUFFERS[0]), NORMAL_DRAW_BUFFERS); | |
| 145 | + glClear(GL_COLOR_BUFFER_BIT); | |
| 146 | + | |
| 147 | + glDrawBuffers(sizeof(COLOR_DRAW_BUFFERS) / sizeof(COLOR_DRAW_BUFFERS[0]), COLOR_DRAW_BUFFERS); | |
| 148 | + | |
| 126 | 149 | RenderVisitor renderVisitor(getLOD()); |
| 127 | 150 | guideToAugmented(renderVisitor, true); |
| 151 | + | |
| 152 | + // give external parties a chance to join in | |
| 153 | + emit rendering(); | |
| 154 | + | |
| 155 | + if (!_needToLight) { | |
| 156 | + return; // skip lighting if not needed | |
| 157 | + } | |
| 158 | + | |
| 159 | + // perform deferred lighting, rendering to free fbo | |
| 160 | + glPushMatrix(); | |
| 161 | + glLoadIdentity(); | |
| 162 | + | |
| 163 | + glMatrixMode(GL_PROJECTION); | |
| 164 | + glPushMatrix(); | |
| 165 | + glLoadIdentity(); | |
| 166 | + | |
| 167 | + glDisable(GL_BLEND); | |
| 168 | + glDisable(GL_LIGHTING); | |
| 169 | + glDisable(GL_DEPTH_TEST); | |
| 170 | + glDepthMask(false); | |
| 171 | + | |
| 172 | + QOpenGLFramebufferObject* primaryFBO = Application::getInstance()->getTextureCache()->getPrimaryFramebufferObject(); | |
| 173 | + primaryFBO->release(); | |
| 174 | + | |
| 175 | + QOpenGLFramebufferObject* freeFBO = Application::getInstance()->getGlowEffect()->getFreeFramebufferObject(); | |
| 176 | + freeFBO->bind(); | |
| 177 | + glClear(GL_COLOR_BUFFER_BIT); | |
| 178 | + | |
| 179 | + glBindTexture(GL_TEXTURE_2D, primaryFBO->texture()); | |
| 180 | + | |
| 181 | + glActiveTexture(GL_TEXTURE1); | |
| 182 | + glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getPrimaryNormalTextureID()); | |
| 183 | + | |
| 184 | + if (Menu::getInstance()->getShadowsEnabled()) { | |
| 185 | + glActiveTexture(GL_TEXTURE2); | |
| 186 | + glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getPrimaryDepthTextureID()); | |
| 187 | + | |
| 188 | + glActiveTexture(GL_TEXTURE3); | |
| 189 | + glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getShadowDepthTextureID()); | |
| 190 | + | |
| 191 | + ProgramObject* program = &_directionalLightShadowMap; | |
| 192 | + const LightLocations* locations = &_directionalLightShadowMapLocations; | |
| 193 | + if (Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows)) { | |
| 194 | + program = &_directionalLightCascadedShadowMap; | |
| 195 | + locations = &_directionalLightCascadedShadowMapLocations; | |
| 196 | + _directionalLightCascadedShadowMap.bind(); | |
| 197 | + _directionalLightCascadedShadowMap.setUniform(locations->shadowDistances, | |
| 198 | + Application::getInstance()->getShadowDistances()); | |
| 199 | + | |
| 200 | + } else { | |
| 201 | + program->bind(); | |
| 202 | + } | |
| 203 | + program->setUniformValue(locations->shadowScale, | |
| 204 | + 1.0f / Application::getInstance()->getTextureCache()->getShadowFramebufferObject()->width()); | |
| 205 | + | |
| 206 | + float left, right, bottom, top, nearVal, farVal; | |
| 207 | + glm::vec4 nearClipPlane, farClipPlane; | |
| 208 | + Application::getInstance()->computeOffAxisFrustum( | |
| 209 | + left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); | |
| 210 | + program->setUniformValue(locations->near, nearVal); | |
| 211 | + program->setUniformValue(locations->depthScale, (farVal - nearVal) / farVal); | |
| 212 | + float nearScale = -1.0f / nearVal; | |
| 213 | + program->setUniformValue(locations->depthTexCoordOffset, left * nearScale, bottom * nearScale); | |
| 214 | + program->setUniformValue(locations->depthTexCoordScale, (right - left) * nearScale, (top - bottom) * nearScale); | |
| 215 | + | |
| 216 | + renderFullscreenQuad(); | |
| 217 | + | |
| 218 | + program->release(); | |
| 219 | + | |
| 220 | + glBindTexture(GL_TEXTURE_2D, 0); | |
| 221 | + | |
| 222 | + glActiveTexture(GL_TEXTURE2); | |
| 223 | + glBindTexture(GL_TEXTURE_2D, 0); | |
| 224 | + | |
| 225 | + glActiveTexture(GL_TEXTURE1); | |
| 226 | + | |
| 227 | + } else { | |
| 228 | + _directionalLight.bind(); | |
| 229 | + renderFullscreenQuad(); | |
| 230 | + _directionalLight.release(); | |
| 231 | + } | |
| 232 | + | |
| 233 | + glBindTexture(GL_TEXTURE_2D, 0); | |
| 234 | + glActiveTexture(GL_TEXTURE0); | |
| 235 | + | |
| 236 | + freeFBO->release(); | |
| 237 | + | |
| 238 | + // now transfer the lit region to the primary fbo | |
| 239 | + glEnable(GL_BLEND); | |
| 240 | + | |
| 241 | + primaryFBO->bind(); | |
| 242 | + | |
| 243 | + glBindTexture(GL_TEXTURE_2D, freeFBO->texture()); | |
| 244 | + glEnable(GL_TEXTURE_2D); | |
| 245 | + | |
| 246 | + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | |
| 247 | + | |
| 248 | + renderFullscreenQuad(); | |
| 249 | + | |
| 250 | + glBindTexture(GL_TEXTURE_2D, 0); | |
| 251 | + glDisable(GL_TEXTURE_2D); | |
| 252 | + | |
| 253 | + glEnable(GL_LIGHTING); | |
| 254 | + glEnable(GL_DEPTH_TEST); | |
| 255 | + glDepthMask(true); | |
| 256 | + | |
| 257 | + glDisable(GL_ALPHA_TEST); | |
| 258 | + | |
| 259 | + glPopMatrix(); | |
| 260 | + | |
| 261 | + glMatrixMode(GL_MODELVIEW); | |
| 262 | + glPopMatrix(); | |
| 128 | 263 | } |
| 129 | 264 | |
| 130 | 265 | class RayHeightfieldIntersectionVisitor : public RayIntersectionVisitor { |
| @@ -484,6 +619,24 @@ void MetavoxelSystem::guideToAugmented(MetavoxelVisitor& visitor, bool render) { · 353 unmodified lines | ||
| 484 | 619 | } |
| 485 | 620 | } |
| 486 | 621 | |
| 622 | +void MetavoxelSystem::loadLightProgram(const char* name, ProgramObject& program, LightLocations& locations) { | |
| 623 | + program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + name); | |
| 624 | + program.link(); | |
| 625 | + | |
| 626 | + program.bind(); | |
| 627 | + program.setUniformValue("diffuseMap", 0); | |
| 628 | + program.setUniformValue("normalMap", 1); | |
| 629 | + program.setUniformValue("depthMap", 2); | |
| 630 | + program.setUniformValue("shadowMap", 3); | |
| 631 | + locations.shadowDistances = program.uniformLocation("shadowDistances"); | |
| 632 | + locations.shadowScale = program.uniformLocation("shadowScale"); | |
| 633 | + locations.near = program.uniformLocation("near"); | |
| 634 | + locations.depthScale = program.uniformLocation("depthScale"); | |
| 635 | + locations.depthTexCoordOffset = program.uniformLocation("depthTexCoordOffset"); | |
| 636 | + locations.depthTexCoordScale = program.uniformLocation("depthTexCoordScale"); | |
| 637 | + program.release(); | |
| 638 | +} | |
| 639 | + | |
| 487 | 640 | MetavoxelSystemClient::MetavoxelSystemClient(const SharedNodePointer& node, MetavoxelUpdater* updater) : |
| 488 | 641 | MetavoxelClient(node, updater) { |
| 489 | 642 | } |
| @@ -807,7 +960,6 @@ void HeightfieldBuffer::render(bool cursor) { · 317 unmodified lines | ||
| 807 | 960 | glDrawRangeElements(GL_TRIANGLES, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0); |
| 808 | 961 | |
| 809 | 962 | } else if (!_materials.isEmpty()) { |
| 810 | − DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().bind(); | |
| 811 | 963 | DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().setUniformValue( |
| 812 | 964 | DefaultMetavoxelRendererImplementation::getBaseHeightScaleLocation(), 1.0f / _heightSize); |
| 813 | 965 | DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().setUniformValue( |
| @@ -817,6 +969,8 @@ void HeightfieldBuffer::render(bool cursor) { · 3 unmodified lines | ||
| 817 | 969 | |
| 818 | 970 | glDrawRangeElements(GL_TRIANGLES, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0); |
| 819 | 971 | |
| 972 | + glDrawBuffers(sizeof(COLOR_DRAW_BUFFERS) / sizeof(COLOR_DRAW_BUFFERS[0]), COLOR_DRAW_BUFFERS); | |
| 973 | + | |
| 820 | 974 | glDepthFunc(GL_LEQUAL); |
| 821 | 975 | glDepthMask(false); |
| 822 | 976 | glEnable(GL_BLEND); |
| @@ -825,18 +979,18 @@ void HeightfieldBuffer::render(bool cursor) { · 2 unmodified lines | ||
| 825 | 979 | glPolygonOffset(-1.0f, -1.0f); |
| 826 | 980 | |
| 827 | 981 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().bind(); |
| 982 | + const DefaultMetavoxelRendererImplementation::SplatLocations& locations = | |
| 983 | + DefaultMetavoxelRendererImplementation::getSplatHeightfieldLocations(); | |
| 828 | 984 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue( |
| 829 | − DefaultMetavoxelRendererImplementation::getSplatHeightScaleLocation(), 1.0f / _heightSize); | |
| 985 | + locations.heightScale, 1.0f / _heightSize); | |
| 830 | 986 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue( |
| 831 | − DefaultMetavoxelRendererImplementation::getSplatTextureScaleLocation(), (float)_heightSize / innerSize); | |
| 987 | + locations.textureScale, (float)_heightSize / innerSize); | |
| 832 | 988 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue( |
| 833 | − DefaultMetavoxelRendererImplementation::getSplatTextureOffsetLocation(), | |
| 834 | − _translation.x / _scale, _translation.z / _scale); | |
| 989 | + locations.splatTextureOffset, _translation.x / _scale, _translation.z / _scale); | |
| 835 | 990 | |
| 836 | 991 | glBindTexture(GL_TEXTURE_2D, _materialTextureID); |
| 837 | 992 | |
| 838 | − const int TEXTURES_PER_SPLAT = 4; | |
| 839 | − for (int i = 0; i < _materials.size(); i += TEXTURES_PER_SPLAT) { | |
| 993 | + for (int i = 0; i < _materials.size(); i += SPLAT_COUNT) { | |
| 840 | 994 | QVector4D scalesS, scalesT; |
| 841 | 995 | |
| 842 | 996 | for (int j = 0; j < SPLAT_COUNT; j++) { |
| @@ -858,23 +1012,20 @@ void HeightfieldBuffer::render(bool cursor) { · 15 unmodified lines | ||
| 858 | 1012 | } |
| 859 | 1013 | const float QUARTER_STEP = 0.25f * EIGHT_BIT_MAXIMUM_RECIPROCAL; |
| 860 | 1014 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue( |
| 861 | − DefaultMetavoxelRendererImplementation::getSplatTextureScalesSLocation(), scalesS); | |
| 1015 | + locations.splatTextureScalesS, scalesS); | |
| 862 | 1016 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue( |
| 863 | − DefaultMetavoxelRendererImplementation::getSplatTextureScalesTLocation(), scalesT); | |
| 1017 | + locations.splatTextureScalesT, scalesT); | |
| 864 | 1018 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue( |
| 865 | − DefaultMetavoxelRendererImplementation::getSplatTextureValueMinimaLocation(), | |
| 1019 | + locations.textureValueMinima, | |
| 866 | 1020 | (i + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, (i + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, |
| 867 | 1021 | (i + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, (i + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP); |
| 868 | 1022 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue( |
| 869 | − DefaultMetavoxelRendererImplementation::getSplatTextureValueMaximaLocation(), | |
| 1023 | + locations.textureValueMaxima, | |
| 870 | 1024 | (i + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, (i + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, |
| 871 | 1025 | (i + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, (i + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP); |
| 872 | 1026 | glDrawRangeElements(GL_TRIANGLES, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0); |
| 873 | 1027 | } |
| 874 | 1028 | |
| 875 | − glEnable(GL_ALPHA_TEST); | |
| 876 | − glBlendFunc(GL_DST_COLOR, GL_ZERO); | |
| 877 | − | |
| 878 | 1029 | for (int i = 0; i < SPLAT_COUNT; i++) { |
| 879 | 1030 | glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[i]); |
| 880 | 1031 | glBindTexture(GL_TEXTURE_2D, 0); |
| @@ -882,53 +1033,24 @@ void HeightfieldBuffer::render(bool cursor) { · 1 unmodified line | ||
| 882 | 1033 | |
| 883 | 1034 | glActiveTexture(GL_TEXTURE1); |
| 884 | 1035 | glBindTexture(GL_TEXTURE_2D, 0); |
| 885 | − | |
| 886 | − if (Menu::getInstance()->isOptionChecked(MenuOption::SimpleShadows)) { | |
| 887 | − DefaultMetavoxelRendererImplementation::getShadowLightHeightfieldProgram().bind(); | |
| 888 | − DefaultMetavoxelRendererImplementation::getShadowLightHeightfieldProgram().setUniformValue( | |
| 889 | − DefaultMetavoxelRendererImplementation::getShadowLightHeightScaleLocation(), 1.0f / _heightSize); | |
| 890 | − glDrawRangeElements(GL_TRIANGLES, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0); | |
| 891 | − DefaultMetavoxelRendererImplementation::getShadowMapHeightfieldProgram().bind(); | |
| 892 | − | |
| 893 | − } else if (Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows)) { | |
| 894 | − DefaultMetavoxelRendererImplementation::getCascadedShadowLightHeightfieldProgram().bind(); | |
| 895 | − DefaultMetavoxelRendererImplementation::getCascadedShadowLightHeightfieldProgram().setUniformValue( | |
| 896 | − DefaultMetavoxelRendererImplementation::getCascadedShadowLightHeightScaleLocation(), 1.0f / _heightSize); | |
| 897 | − glDrawRangeElements(GL_TRIANGLES, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0); | |
| 898 | − DefaultMetavoxelRendererImplementation::getCascadedShadowMapHeightfieldProgram().bind(); | |
| 899 | − | |
| 900 | − } else { | |
| 901 | − DefaultMetavoxelRendererImplementation::getLightHeightfieldProgram().bind(); | |
| 902 | − DefaultMetavoxelRendererImplementation::getLightHeightfieldProgram().setUniformValue( | |
| 903 | − DefaultMetavoxelRendererImplementation::getLightHeightScaleLocation(), 1.0f / _heightSize); | |
| 904 | − glDrawRangeElements(GL_TRIANGLES, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0); | |
| 905 | − DefaultMetavoxelRendererImplementation::getHeightfieldProgram().bind(); | |
| 906 | − } | |
| 1036 | + | |
| 1037 | + glActiveTexture(GL_TEXTURE0); | |
| 907 | 1038 | |
| 908 | 1039 | glDisable(GL_POLYGON_OFFSET_FILL); |
| 1040 | + glEnable(GL_ALPHA_TEST); | |
| 909 | 1041 | glDisable(GL_BLEND); |
| 910 | − glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE); | |
| 911 | − glDepthFunc(GL_LESS); | |
| 912 | 1042 | glDepthMask(true); |
| 1043 | + glDepthFunc(GL_LESS); | |
| 913 | 1044 | |
| 914 | − glActiveTexture(GL_TEXTURE0); | |
| 1045 | + glDrawBuffers(sizeof(COLOR_NORMAL_DRAW_BUFFERS) / sizeof(COLOR_NORMAL_DRAW_BUFFERS[0]), COLOR_NORMAL_DRAW_BUFFERS); | |
| 1046 | + | |
| 1047 | + DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().bind(); | |
| 915 | 1048 | |
| 916 | 1049 | } else { |
| 917 | − int heightScaleLocation = DefaultMetavoxelRendererImplementation::getHeightScaleLocation(); | |
| 918 | − int colorScaleLocation = DefaultMetavoxelRendererImplementation::getColorScaleLocation(); | |
| 919 | − ProgramObject* program = &DefaultMetavoxelRendererImplementation::getHeightfieldProgram(); | |
| 920 | − if (Menu::getInstance()->isOptionChecked(MenuOption::SimpleShadows)) { | |
| 921 | − heightScaleLocation = DefaultMetavoxelRendererImplementation::getShadowMapHeightScaleLocation(); | |
| 922 | − colorScaleLocation = DefaultMetavoxelRendererImplementation::getShadowMapColorScaleLocation(); | |
| 923 | − program = &DefaultMetavoxelRendererImplementation::getShadowMapHeightfieldProgram(); | |
| 924 | − | |
| 925 | − } else if (Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows)) { | |
| 926 | − heightScaleLocation = DefaultMetavoxelRendererImplementation::getCascadedShadowMapHeightScaleLocation(); | |
| 927 | − colorScaleLocation = DefaultMetavoxelRendererImplementation::getCascadedShadowMapColorScaleLocation(); | |
| 928 | − program = &DefaultMetavoxelRendererImplementation::getCascadedShadowMapHeightfieldProgram(); | |
| 929 | − } | |
| 930 | − program->setUniformValue(heightScaleLocation, 1.0f / _heightSize); | |
| 931 | − program->setUniformValue(colorScaleLocation, (float)_heightSize / innerSize); | |
| 1050 | + DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().setUniformValue( | |
| 1051 | + DefaultMetavoxelRendererImplementation::getBaseHeightScaleLocation(), 1.0f / _heightSize); | |
| 1052 | + DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().setUniformValue( | |
| 1053 | + DefaultMetavoxelRendererImplementation::getBaseColorScaleLocation(), (float)_heightSize / innerSize); | |
| 932 | 1054 | glActiveTexture(GL_TEXTURE1); |
| 933 | 1055 | glBindTexture(GL_TEXTURE_2D, _colorTextureID); |
| 934 | 1056 | |
| @@ -944,6 +1066,8 @@ void HeightfieldBuffer::render(bool cursor) { · 9 unmodified lines | ||
| 944 | 1066 | |
| 945 | 1067 | bufferPair.first.release(); |
| 946 | 1068 | bufferPair.second.release(); |
| 1069 | + | |
| 1070 | + Application::getInstance()->getMetavoxels()->noteNeedToLight(); | |
| 947 | 1071 | } |
| 948 | 1072 | |
| 949 | 1073 | QHash<int, HeightfieldBuffer::BufferPair> HeightfieldBuffer::_bufferPairs; |
| @@ -959,7 +1083,7 @@ void HeightfieldPreview::render(const glm::vec3& translation, float scale) const · 9 unmodified lines | ||
| 959 | 1083 | glEnableClientState(GL_VERTEX_ARRAY); |
| 960 | 1084 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 961 | 1085 | |
| 962 | − DefaultMetavoxelRendererImplementation::getHeightfieldProgram().bind(); | |
| 1086 | + DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().bind(); | |
| 963 | 1087 | |
| 964 | 1088 | glPushMatrix(); |
| 965 | 1089 | glTranslatef(translation.x, translation.y, translation.z); |
| @@ -971,7 +1095,7 @@ void HeightfieldPreview::render(const glm::vec3& translation, float scale) const · 5 unmodified lines | ||
| 971 | 1095 | |
| 972 | 1096 | glPopMatrix(); |
| 973 | 1097 | |
| 974 | − DefaultMetavoxelRendererImplementation::getHeightfieldProgram().release(); | |
| 1098 | + DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().release(); | |
| 975 | 1099 | |
| 976 | 1100 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
| 977 | 1101 | glDisableClientState(GL_VERTEX_ARRAY); |
| @@ -1025,8 +1149,89 @@ void VoxelBuffer::render(bool cursor) { · 47 unmodified lines | ||
| 1025 | 1149 | |
| 1026 | 1150 | glDrawRangeElements(GL_QUADS, 0, _vertexCount - 1, _indexCount, GL_UNSIGNED_INT, 0); |
| 1027 | 1151 | |
| 1152 | + if (!_materials.isEmpty()) { | |
| 1153 | + glDrawBuffers(sizeof(COLOR_DRAW_BUFFERS) / sizeof(COLOR_DRAW_BUFFERS[0]), COLOR_DRAW_BUFFERS); | |
| 1154 | + | |
| 1155 | + glDepthFunc(GL_LEQUAL); | |
| 1156 | + glDepthMask(false); | |
| 1157 | + glEnable(GL_BLEND); | |
| 1158 | + glDisable(GL_ALPHA_TEST); | |
| 1159 | + glEnable(GL_POLYGON_OFFSET_FILL); | |
| 1160 | + glPolygonOffset(-1.0f, -1.0f); | |
| 1161 | + | |
| 1162 | + DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().bind(); | |
| 1163 | + const DefaultMetavoxelRendererImplementation::SplatLocations& locations = | |
| 1164 | + DefaultMetavoxelRendererImplementation::getSplatVoxelLocations(); | |
| 1165 | + | |
| 1166 | + DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().setAttributeBuffer(locations.materials, | |
| 1167 | + GL_UNSIGNED_BYTE, (qint64)&point->materials, SPLAT_COUNT, sizeof(VoxelPoint)); | |
| 1168 | + DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().enableAttributeArray(locations.materials); | |
| 1169 | + | |
| 1170 | + DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().setAttributeBuffer(locations.materialWeights, | |
| 1171 | + GL_UNSIGNED_BYTE, (qint64)&point->materialWeights, SPLAT_COUNT, sizeof(VoxelPoint)); | |
| 1172 | + DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().enableAttributeArray(locations.materialWeights); | |
| 1173 | + | |
| 1174 | + for (int i = 0; i < _materials.size(); i += SPLAT_COUNT) { | |
| 1175 | + QVector4D scalesS, scalesT; | |
| 1176 | + | |
| 1177 | + for (int j = 0; j < SPLAT_COUNT; j++) { | |
| 1178 | + glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[j]); | |
| 1179 | + int index = i + j; | |
| 1180 | + if (index < _networkTextures.size()) { | |
| 1181 | + const NetworkTexturePointer& texture = _networkTextures.at(index); | |
| 1182 | + if (texture) { | |
| 1183 | + MaterialObject* material = static_cast<MaterialObject*>(_materials.at(index).data()); | |
| 1184 | + scalesS[j] = 1.0f / material->getScaleS(); | |
| 1185 | + scalesT[j] = 1.0f / material->getScaleT(); | |
| 1186 | + glBindTexture(GL_TEXTURE_2D, texture->getID()); | |
| 1187 | + } else { | |
| 1188 | + glBindTexture(GL_TEXTURE_2D, 0); | |
| 1189 | + } | |
| 1190 | + } else { | |
| 1191 | + glBindTexture(GL_TEXTURE_2D, 0); | |
| 1192 | + } | |
| 1193 | + } | |
| 1194 | + const float QUARTER_STEP = 0.25f * EIGHT_BIT_MAXIMUM_RECIPROCAL; | |
| 1195 | + DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().setUniformValue( | |
| 1196 | + locations.splatTextureScalesS, scalesS); | |
| 1197 | + DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().setUniformValue( | |
| 1198 | + locations.splatTextureScalesT, scalesT); | |
| 1199 | + DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().setUniformValue( | |
| 1200 | + locations.textureValueMinima, | |
| 1201 | + (i + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, (i + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, | |
| 1202 | + (i + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, (i + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP); | |
| 1203 | + DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().setUniformValue( | |
| 1204 | + locations.textureValueMaxima, | |
| 1205 | + (i + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, (i + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, | |
| 1206 | + (i + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, (i + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP); | |
| 1207 | + glDrawRangeElements(GL_QUADS, 0, _vertexCount - 1, _indexCount, GL_UNSIGNED_INT, 0); | |
| 1208 | + } | |
| 1209 | + | |
| 1210 | + for (int i = 0; i < SPLAT_COUNT; i++) { | |
| 1211 | + glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[i]); | |
| 1212 | + glBindTexture(GL_TEXTURE_2D, 0); | |
| 1213 | + } | |
| 1214 | + | |
| 1215 | + glActiveTexture(GL_TEXTURE0); | |
| 1216 | + | |
| 1217 | + glDisable(GL_POLYGON_OFFSET_FILL); | |
| 1218 | + glEnable(GL_ALPHA_TEST); | |
| 1219 | + glDisable(GL_BLEND); | |
| 1220 | + glDepthMask(true); | |
| 1221 | + glDepthFunc(GL_LESS); | |
| 1222 | + | |
| 1223 | + glDrawBuffers(sizeof(COLOR_NORMAL_DRAW_BUFFERS) / sizeof(COLOR_NORMAL_DRAW_BUFFERS[0]), COLOR_NORMAL_DRAW_BUFFERS); | |
| 1224 | + | |
| 1225 | + DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().disableAttributeArray(locations.materials); | |
| 1226 | + DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().disableAttributeArray(locations.materialWeights); | |
| 1227 | + | |
| 1228 | + DefaultMetavoxelRendererImplementation::getBaseVoxelProgram().bind(); | |
| 1229 | + } | |
| 1230 | + | |
| 1028 | 1231 | _vertexBuffer.release(); |
| 1029 | 1232 | _indexBuffer.release(); |
| 1233 | + | |
| 1234 | + Application::getInstance()->getMetavoxels()->noteNeedToLight(); | |
| 1030 | 1235 | } |
| 1031 | 1236 | |
| 1032 | 1237 | BufferDataAttribute::BufferDataAttribute(const QString& name) : |
| @@ -1056,48 +1261,6 @@ void DefaultMetavoxelRendererImplementation::init() { · 23 unmodified lines | ||
| 1056 | 1261 | _pointScaleLocation = _pointProgram.uniformLocation("pointScale"); |
| 1057 | 1262 | _pointProgram.release(); |
| 1058 | 1263 | |
| 1059 | − _heightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | |
| 1060 | − "shaders/metavoxel_heightfield.vert"); | |
| 1061 | − _heightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | |
| 1062 | − "shaders/metavoxel_heightfield.frag"); | |
| 1063 | − _heightfieldProgram.link(); | |
| 1064 | − | |
| 1065 | − _heightfieldProgram.bind(); | |
| 1066 | − _heightfieldProgram.setUniformValue("heightMap", 0); | |
| 1067 | − _heightfieldProgram.setUniformValue("diffuseMap", 1); | |
| 1068 | − _heightScaleLocation = _heightfieldProgram.uniformLocation("heightScale"); | |
| 1069 | − _colorScaleLocation = _heightfieldProgram.uniformLocation("colorScale"); | |
| 1070 | − _heightfieldProgram.release(); | |
| 1071 | − | |
| 1072 | − _shadowMapHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | |
| 1073 | − "shaders/metavoxel_heightfield.vert"); | |
| 1074 | − _shadowMapHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | |
| 1075 | − "shaders/metavoxel_heightfield_shadow_map.frag"); | |
| 1076 | − _shadowMapHeightfieldProgram.link(); | |
| 1077 | − | |
| 1078 | − _shadowMapHeightfieldProgram.bind(); | |
| 1079 | − _shadowMapHeightfieldProgram.setUniformValue("heightMap", 0); | |
| 1080 | − _shadowMapHeightfieldProgram.setUniformValue("diffuseMap", 1); | |
| 1081 | − _shadowMapHeightfieldProgram.setUniformValue("shadowMap", 2); | |
| 1082 | − _shadowMapHeightScaleLocation = _shadowMapHeightfieldProgram.uniformLocation("heightScale"); | |
| 1083 | − _shadowMapColorScaleLocation = _shadowMapHeightfieldProgram.uniformLocation("colorScale"); | |
| 1084 | − _shadowMapHeightfieldProgram.release(); | |
| 1085 | − | |
| 1086 | − _cascadedShadowMapHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | |
| 1087 | − "shaders/metavoxel_heightfield.vert"); | |
| 1088 | − _cascadedShadowMapHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | |
| 1089 | − "shaders/metavoxel_heightfield_cascaded_shadow_map.frag"); | |
| 1090 | − _cascadedShadowMapHeightfieldProgram.link(); | |
| 1091 | − | |
| 1092 | − _cascadedShadowMapHeightfieldProgram.bind(); | |
| 1093 | − _cascadedShadowMapHeightfieldProgram.setUniformValue("heightMap", 0); | |
| 1094 | − _cascadedShadowMapHeightfieldProgram.setUniformValue("diffuseMap", 1); | |
| 1095 | − _cascadedShadowMapHeightfieldProgram.setUniformValue("shadowMap", 2); | |
| 1096 | − _cascadedShadowMapHeightScaleLocation = _cascadedShadowMapHeightfieldProgram.uniformLocation("heightScale"); | |
| 1097 | − _cascadedShadowMapColorScaleLocation = _cascadedShadowMapHeightfieldProgram.uniformLocation("colorScale"); | |
| 1098 | − _shadowDistancesLocation = _cascadedShadowMapHeightfieldProgram.uniformLocation("shadowDistances"); | |
| 1099 | − _cascadedShadowMapHeightfieldProgram.release(); | |
| 1100 | − | |
| 1101 | 1264 | _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + |
| 1102 | 1265 | "shaders/metavoxel_heightfield_base.vert"); |
| 1103 | 1266 | _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + |
| @@ -1111,60 +1274,7 @@ void DefaultMetavoxelRendererImplementation::init() { · 7 unmodified lines | ||
| 1111 | 1274 | _baseColorScaleLocation = _baseHeightfieldProgram.uniformLocation("colorScale"); |
| 1112 | 1275 | _baseHeightfieldProgram.release(); |
| 1113 | 1276 | |
| 1114 | − _splatHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | |
| 1115 | − "shaders/metavoxel_heightfield_splat.vert"); | |
| 1116 | − _splatHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | |
| 1117 | − "shaders/metavoxel_heightfield_splat.frag"); | |
| 1118 | − _splatHeightfieldProgram.link(); | |
| 1119 | − | |
| 1120 | − _splatHeightfieldProgram.bind(); | |
| 1121 | − _splatHeightfieldProgram.setUniformValue("heightMap", 0); | |
| 1122 | − _splatHeightfieldProgram.setUniformValue("textureMap", 1); | |
| 1123 | − _splatHeightfieldProgram.setUniformValueArray("diffuseMaps", SPLAT_TEXTURE_UNITS, SPLAT_COUNT); | |
| 1124 | − _splatHeightScaleLocation = _splatHeightfieldProgram.uniformLocation("heightScale"); | |
| 1125 | − _splatTextureScaleLocation = _splatHeightfieldProgram.uniformLocation("textureScale"); | |
| 1126 | − _splatTextureOffsetLocation = _splatHeightfieldProgram.uniformLocation("splatTextureOffset"); | |
| 1127 | − _splatTextureScalesSLocation = _splatHeightfieldProgram.uniformLocation("splatTextureScalesS"); | |
| 1128 | − _splatTextureScalesTLocation = _splatHeightfieldProgram.uniformLocation("splatTextureScalesT"); | |
| 1129 | − _splatTextureValueMinimaLocation = _splatHeightfieldProgram.uniformLocation("textureValueMinima"); | |
| 1130 | − _splatTextureValueMaximaLocation = _splatHeightfieldProgram.uniformLocation("textureValueMaxima"); | |
| 1131 | − _splatHeightfieldProgram.release(); | |
| 1132 | − | |
| 1133 | − _lightHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | |
| 1134 | − "shaders/metavoxel_heightfield_light.vert"); | |
| 1135 | − _lightHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | |
| 1136 | − "shaders/metavoxel_heightfield_light.frag"); | |
| 1137 | − _lightHeightfieldProgram.link(); | |
| 1138 | − | |
| 1139 | − _lightHeightfieldProgram.bind(); | |
| 1140 | − _lightHeightfieldProgram.setUniformValue("heightMap", 0); | |
| 1141 | − _lightHeightScaleLocation = _lightHeightfieldProgram.uniformLocation("heightScale"); | |
| 1142 | − _lightHeightfieldProgram.release(); | |
| 1143 | − | |
| 1144 | − _shadowLightHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | |
| 1145 | − "shaders/metavoxel_heightfield_light.vert"); | |
| 1146 | − _shadowLightHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | |
| 1147 | − "shaders/metavoxel_heightfield_light_shadow_map.frag"); | |
| 1148 | − _shadowLightHeightfieldProgram.link(); | |
| 1149 | − | |
| 1150 | − _shadowLightHeightfieldProgram.bind(); | |
| 1151 | − _shadowLightHeightfieldProgram.setUniformValue("heightMap", 0); | |
| 1152 | − _shadowLightHeightfieldProgram.setUniformValue("shadowMap", 2); | |
| 1153 | − _shadowLightHeightScaleLocation = _shadowLightHeightfieldProgram.uniformLocation("heightScale"); | |
| 1154 | − _shadowLightHeightfieldProgram.release(); | |
| 1155 | − | |
| 1156 | − _cascadedShadowLightHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | |
| 1157 | − "shaders/metavoxel_heightfield_light.vert"); | |
| 1158 | − _cascadedShadowLightHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | |
| 1159 | − "shaders/metavoxel_heightfield_light_cascaded_shadow_map.frag"); | |
| 1160 | − _cascadedShadowLightHeightfieldProgram.link(); | |
| 1161 | − | |
| 1162 | − _cascadedShadowLightHeightfieldProgram.bind(); | |
| 1163 | − _cascadedShadowLightHeightfieldProgram.setUniformValue("heightMap", 0); | |
| 1164 | − _cascadedShadowLightHeightfieldProgram.setUniformValue("shadowMap", 2); | |
| 1165 | − _cascadedShadowLightHeightScaleLocation = _cascadedShadowLightHeightfieldProgram.uniformLocation("heightScale"); | |
| 1166 | − _shadowLightDistancesLocation = _cascadedShadowLightHeightfieldProgram.uniformLocation("shadowDistances"); | |
| 1167 | − _cascadedShadowLightHeightfieldProgram.release(); | |
| 1277 | + loadSplatProgram("heightfield", _splatHeightfieldProgram, _splatHeightfieldLocations); | |
| 1168 | 1278 | |
| 1169 | 1279 | _heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + |
| 1170 | 1280 | "shaders/metavoxel_heightfield_cursor.vert"); |
| @@ -1175,6 +1285,14 @@ void DefaultMetavoxelRendererImplementation::init() { · 4 unmodified lines | ||
| 1175 | 1285 | _heightfieldCursorProgram.bind(); |
| 1176 | 1286 | _heightfieldCursorProgram.setUniformValue("heightMap", 0); |
| 1177 | 1287 | _heightfieldCursorProgram.release(); |
| 1288 | + | |
| 1289 | + _baseVoxelProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | |
| 1290 | + "shaders/metavoxel_voxel_base.vert"); | |
| 1291 | + _baseVoxelProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | |
| 1292 | + "shaders/metavoxel_voxel_base.frag"); | |
| 1293 | + _baseVoxelProgram.link(); | |
| 1294 | + | |
| 1295 | + loadSplatProgram("voxel", _splatVoxelProgram, _splatVoxelLocations); | |
| 1178 | 1296 | } |
| 1179 | 1297 | } |
| 1180 | 1298 | |
| @@ -1844,7 +1962,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 663 unmodified lines | ||
| 1844 | 1962 | glm::vec3 center; |
| 1845 | 1963 | glm::vec3 normal; |
| 1846 | 1964 | const int MAX_MATERIALS_PER_VERTEX = 4; |
| 1847 | − quint8 materials[4]; | |
| 1965 | + quint8 materials[] = { 0, 0, 0, 0 }; | |
| 1848 | 1966 | glm::vec4 materialWeights; |
| 1849 | 1967 | float totalWeight = 0.0f; |
| 1850 | 1968 | int red = 0, green = 0, blue = 0; |
| @@ -1865,7 +1983,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 14 unmodified lines | ||
| 1865 | 1983 | totalWeight += 1.0f; |
| 1866 | 1984 | break; |
| 1867 | 1985 | |
| 1868 | − } else if (materials[j] == 0.0f) { | |
| 1986 | + } else if (materials[j] == 0) { | |
| 1869 | 1987 | materials[j] = crossing.material; |
| 1870 | 1988 | materialWeights[j] = 1.0f; |
| 1871 | 1989 | totalWeight += 1.0f; |
| @@ -2149,38 +2267,22 @@ void DefaultMetavoxelRendererImplementation::render(MetavoxelData& data, Metavox · 277 unmodified lines | ||
| 2149 | 2267 | |
| 2150 | 2268 | _pointProgram.release(); |
| 2151 | 2269 | |
| 2270 | + glDrawBuffers(sizeof(COLOR_NORMAL_DRAW_BUFFERS) / sizeof(COLOR_NORMAL_DRAW_BUFFERS[0]), COLOR_NORMAL_DRAW_BUFFERS); | |
| 2271 | + | |
| 2152 | 2272 | glEnable(GL_CULL_FACE); |
| 2153 | 2273 | glEnable(GL_ALPHA_TEST); |
| 2154 | 2274 | glAlphaFunc(GL_EQUAL, 0.0f); |
| 2155 | 2275 | |
| 2156 | 2276 | glColor4f(1.0f, 1.0f, 1.0f, 1.0f); |
| 2157 | 2277 | |
| 2158 | − ProgramObject* program = &_heightfieldProgram; | |
| 2159 | − if (Menu::getInstance()->getShadowsEnabled()) { | |
| 2160 | − if (Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows)) { | |
| 2161 | − _cascadedShadowLightHeightfieldProgram.bind(); | |
| 2162 | − _cascadedShadowLightHeightfieldProgram.setUniform(_shadowLightDistancesLocation, | |
| 2163 | − Application::getInstance()->getShadowDistances()); | |
| 2164 | − program = &_cascadedShadowMapHeightfieldProgram; | |
| 2165 | − program->bind(); | |
| 2166 | − program->setUniform(_shadowDistancesLocation, Application::getInstance()->getShadowDistances()); | |
| 2167 | − | |
| 2168 | − } else { | |
| 2169 | − program = &_shadowMapHeightfieldProgram; | |
| 2170 | − } | |
| 2171 | − glActiveTexture(GL_TEXTURE2); | |
| 2172 | − glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getShadowDepthTextureID()); | |
| 2173 | − glActiveTexture(GL_TEXTURE0); | |
| 2174 | − } | |
| 2175 | − | |
| 2176 | − program->bind(); | |
| 2278 | + _baseHeightfieldProgram.bind(); | |
| 2177 | 2279 | |
| 2178 | 2280 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 2179 | 2281 | |
| 2180 | 2282 | BufferRenderVisitor heightfieldRenderVisitor(Application::getInstance()->getMetavoxels()->getHeightfieldBufferAttribute()); |
| 2181 | 2283 | data.guide(heightfieldRenderVisitor); |
| 2182 | 2284 | |
| 2183 | − program->release(); | |
| 2285 | + _baseHeightfieldProgram.release(); | |
| 2184 | 2286 | |
| 2185 | 2287 | glActiveTexture(GL_TEXTURE2); |
| 2186 | 2288 | glBindTexture(GL_TEXTURE_2D, 0); |
| @@ -2189,57 +2291,63 @@ void DefaultMetavoxelRendererImplementation::render(MetavoxelData& data, Metavox · 2 unmodified lines | ||
| 2189 | 2291 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
| 2190 | 2292 | glDisableClientState(GL_VERTEX_ARRAY); |
| 2191 | 2293 | |
| 2192 | − glDisable(GL_ALPHA_TEST); | |
| 2193 | − glDisable(GL_CULL_FACE); | |
| 2194 | − glEnable(GL_BLEND); | |
| 2195 | − | |
| 2196 | 2294 | glEnableClientState(GL_VERTEX_ARRAY); |
| 2197 | 2295 | glEnableClientState(GL_COLOR_ARRAY); |
| 2198 | 2296 | glEnableClientState(GL_NORMAL_ARRAY); |
| 2199 | 2297 | |
| 2200 | − glEnable(GL_CULL_FACE); | |
| 2298 | + _baseVoxelProgram.bind(); | |
| 2201 | 2299 | |
| 2202 | 2300 | BufferRenderVisitor voxelRenderVisitor(Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute()); |
| 2203 | 2301 | data.guide(voxelRenderVisitor); |
| 2204 | 2302 | |
| 2303 | + _baseVoxelProgram.release(); | |
| 2304 | + | |
| 2305 | + glDisable(GL_ALPHA_TEST); | |
| 2205 | 2306 | glDisable(GL_CULL_FACE); |
| 2307 | + glEnable(GL_BLEND); | |
| 2206 | 2308 | |
| 2207 | 2309 | glDisableClientState(GL_VERTEX_ARRAY); |
| 2208 | 2310 | glDisableClientState(GL_COLOR_ARRAY); |
| 2209 | 2311 | glDisableClientState(GL_NORMAL_ARRAY); |
| 2312 | + | |
| 2313 | + glDrawBuffers(sizeof(COLOR_DRAW_BUFFERS) / sizeof(COLOR_DRAW_BUFFERS[0]), COLOR_DRAW_BUFFERS); | |
| 2314 | +} | |
| 2315 | + | |
| 2316 | +void DefaultMetavoxelRendererImplementation::loadSplatProgram(const char* type, | |
| 2317 | + ProgramObject& program, SplatLocations& locations) { | |
| 2318 | + program.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | |
| 2319 | + "shaders/metavoxel_" + type + "_splat.vert"); | |
| 2320 | + program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | |
| 2321 | + "shaders/metavoxel_" + type + "_splat.frag"); | |
| 2322 | + program.link(); | |
| 2323 | + | |
| 2324 | + program.bind(); | |
| 2325 | + program.setUniformValue("heightMap", 0); | |
| 2326 | + program.setUniformValue("textureMap", 1); | |
| 2327 | + program.setUniformValueArray("diffuseMaps", SPLAT_TEXTURE_UNITS, SPLAT_COUNT); | |
| 2328 | + locations.heightScale = program.uniformLocation("heightScale"); | |
| 2329 | + locations.textureScale = program.uniformLocation("textureScale"); | |
| 2330 | + locations.splatTextureOffset = program.uniformLocation("splatTextureOffset"); | |
| 2331 | + locations.splatTextureScalesS = program.uniformLocation("splatTextureScalesS"); | |
| 2332 | + locations.splatTextureScalesT = program.uniformLocation("splatTextureScalesT"); | |
| 2333 | + locations.textureValueMinima = program.uniformLocation("textureValueMinima"); | |
| 2334 | + locations.textureValueMaxima = program.uniformLocation("textureValueMaxima"); | |
| 2335 | + locations.materials = program.attributeLocation("materials"); | |
| 2336 | + locations.materialWeights = program.attributeLocation("materialWeights"); | |
| 2337 | + program.release(); | |
| 2210 | 2338 | } |
| 2211 | 2339 | |
| 2212 | 2340 | ProgramObject DefaultMetavoxelRendererImplementation::_pointProgram; |
| 2213 | 2341 | int DefaultMetavoxelRendererImplementation::_pointScaleLocation; |
| 2214 | −ProgramObject DefaultMetavoxelRendererImplementation::_heightfieldProgram; | |
| 2215 | −int DefaultMetavoxelRendererImplementation::_heightScaleLocation; | |
| 2216 | −int DefaultMetavoxelRendererImplementation::_colorScaleLocation; | |
| 2217 | −ProgramObject DefaultMetavoxelRendererImplementation::_shadowMapHeightfieldProgram; | |
| 2218 | −int DefaultMetavoxelRendererImplementation::_shadowMapHeightScaleLocation; | |
| 2219 | −int DefaultMetavoxelRendererImplementation::_shadowMapColorScaleLocation; | |
| 2220 | −ProgramObject DefaultMetavoxelRendererImplementation::_cascadedShadowMapHeightfieldProgram; | |
| 2221 | −int DefaultMetavoxelRendererImplementation::_cascadedShadowMapHeightScaleLocation; | |
| 2222 | −int DefaultMetavoxelRendererImplementation::_cascadedShadowMapColorScaleLocation; | |
| 2223 | −int DefaultMetavoxelRendererImplementation::_shadowDistancesLocation; | |
| 2224 | 2342 | ProgramObject DefaultMetavoxelRendererImplementation::_baseHeightfieldProgram; |
| 2225 | 2343 | int DefaultMetavoxelRendererImplementation::_baseHeightScaleLocation; |
| 2226 | 2344 | int DefaultMetavoxelRendererImplementation::_baseColorScaleLocation; |
| 2227 | 2345 | ProgramObject DefaultMetavoxelRendererImplementation::_splatHeightfieldProgram; |
| 2228 | −int DefaultMetavoxelRendererImplementation::_splatHeightScaleLocation; | |
| 2229 | −int DefaultMetavoxelRendererImplementation::_splatTextureScaleLocation; | |
| 2230 | −int DefaultMetavoxelRendererImplementation::_splatTextureOffsetLocation; | |
| 2231 | −int DefaultMetavoxelRendererImplementation::_splatTextureScalesSLocation; | |
| 2232 | −int DefaultMetavoxelRendererImplementation::_splatTextureScalesTLocation; | |
| 2233 | −int DefaultMetavoxelRendererImplementation::_splatTextureValueMinimaLocation; | |
| 2234 | −int DefaultMetavoxelRendererImplementation::_splatTextureValueMaximaLocation; | |
| 2235 | −ProgramObject DefaultMetavoxelRendererImplementation::_lightHeightfieldProgram; | |
| 2236 | −int DefaultMetavoxelRendererImplementation::_lightHeightScaleLocation; | |
| 2237 | −ProgramObject DefaultMetavoxelRendererImplementation::_shadowLightHeightfieldProgram; | |
| 2238 | −int DefaultMetavoxelRendererImplementation::_shadowLightHeightScaleLocation; | |
| 2239 | −ProgramObject DefaultMetavoxelRendererImplementation::_cascadedShadowLightHeightfieldProgram; | |
| 2240 | −int DefaultMetavoxelRendererImplementation::_cascadedShadowLightHeightScaleLocation; | |
| 2241 | −int DefaultMetavoxelRendererImplementation::_shadowLightDistancesLocation; | |
| 2346 | +DefaultMetavoxelRendererImplementation::SplatLocations DefaultMetavoxelRendererImplementation::_splatHeightfieldLocations; | |
| 2242 | 2347 | ProgramObject DefaultMetavoxelRendererImplementation::_heightfieldCursorProgram; |
| 2348 | +ProgramObject DefaultMetavoxelRendererImplementation::_baseVoxelProgram; | |
| 2349 | +ProgramObject DefaultMetavoxelRendererImplementation::_splatVoxelProgram; | |
| 2350 | +DefaultMetavoxelRendererImplementation::SplatLocations DefaultMetavoxelRendererImplementation::_splatVoxelLocations; | |
| 2243 | 2351 | |
| 2244 | 2352 | static void enableClipPlane(GLenum plane, float x, float y, float z, float w) { |
| 2245 | 2353 | GLdouble coefficients[] = { x, y, z, w }; |