Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 6 files). Show all
Unified · Split
| @@ -51,12 +51,6 @@ void MetavoxelSystem::init() { · 50 unmodified lines | |||
| 51 | new BufferDataAttribute("voxelBuffer")); | 51 | new BufferDataAttribute("voxelBuffer")); |
| 52 | _voxelBufferAttribute->setLODThresholdMultiplier( | 52 | _voxelBufferAttribute->setLODThresholdMultiplier( |
| 53 | AttributeRegistry::getInstance()->getVoxelColorAttribute()->getLODThresholdMultiplier()); | 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); | ||
| 60 | } | 54 | } |
| 61 | 55 | ||
| 62 | MetavoxelLOD MetavoxelSystem::getLOD() { | 56 | MetavoxelLOD MetavoxelSystem::getLOD() { |
| @@ -138,8 +132,6 @@ void MetavoxelSystem::render() { · 75 unmodified lines | |||
| 138 | viewFrustum->getFarBottomRight(), viewFrustum->getNearTopLeft(), viewFrustum->getNearTopRight(), | 132 | viewFrustum->getFarBottomRight(), viewFrustum->getNearTopLeft(), viewFrustum->getNearTopRight(), |
| 139 | viewFrustum->getNearBottomLeft(), viewFrustum->getNearBottomRight()); | 133 | viewFrustum->getNearBottomLeft(), viewFrustum->getNearBottomRight()); |
| 140 | 134 | ||
| 141 | _needToLight = false; | ||
| 142 | |||
| 143 | // clear the normal buffer | 135 | // clear the normal buffer |
| 144 | glDrawBuffers(sizeof(NORMAL_DRAW_BUFFERS) / sizeof(NORMAL_DRAW_BUFFERS[0]), NORMAL_DRAW_BUFFERS); | 136 | glDrawBuffers(sizeof(NORMAL_DRAW_BUFFERS) / sizeof(NORMAL_DRAW_BUFFERS[0]), NORMAL_DRAW_BUFFERS); |
| 145 | glClear(GL_COLOR_BUFFER_BIT); | 137 | glClear(GL_COLOR_BUFFER_BIT); |
| @@ -151,126 +143,6 @@ void MetavoxelSystem::render() { · 5 unmodified lines | |||
| 151 | 143 | ||
| 152 | // give external parties a chance to join in | 144 | // give external parties a chance to join in |
| 153 | emit rendering(); | 145 | 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 | // get the viewport side (left, right, both) | ||
| 185 | int viewport[4]; | ||
| 186 | glGetIntegerv(GL_VIEWPORT, viewport); | ||
| 187 | const int VIEWPORT_X_INDEX = 0; | ||
| 188 | const int VIEWPORT_WIDTH_INDEX = 2; | ||
| 189 | float sMin = viewport[VIEWPORT_X_INDEX] / (float)primaryFBO->width(); | ||
| 190 | float sWidth = viewport[VIEWPORT_WIDTH_INDEX] / (float)primaryFBO->width(); | ||
| 191 | |||
| 192 | if (Menu::getInstance()->getShadowsEnabled()) { | ||
| 193 | glActiveTexture(GL_TEXTURE2); | ||
| 194 | glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getPrimaryDepthTextureID()); | ||
| 195 | |||
| 196 | glActiveTexture(GL_TEXTURE3); | ||
| 197 | glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getShadowDepthTextureID()); | ||
| 198 | |||
| 199 | ProgramObject* program = &_directionalLightShadowMap; | ||
| 200 | const LightLocations* locations = &_directionalLightShadowMapLocations; | ||
| 201 | if (Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows)) { | ||
| 202 | program = &_directionalLightCascadedShadowMap; | ||
| 203 | locations = &_directionalLightCascadedShadowMapLocations; | ||
| 204 | _directionalLightCascadedShadowMap.bind(); | ||
| 205 | _directionalLightCascadedShadowMap.setUniform(locations->shadowDistances, | ||
| 206 | Application::getInstance()->getShadowDistances()); | ||
| 207 | |||
| 208 | } else { | ||
| 209 | program->bind(); | ||
| 210 | } | ||
| 211 | program->setUniformValue(locations->shadowScale, | ||
| 212 | 1.0f / Application::getInstance()->getTextureCache()->getShadowFramebufferObject()->width()); | ||
| 213 | |||
| 214 | float left, right, bottom, top, nearVal, farVal; | ||
| 215 | glm::vec4 nearClipPlane, farClipPlane; | ||
| 216 | Application::getInstance()->computeOffAxisFrustum( | ||
| 217 | left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); | ||
| 218 | program->setUniformValue(locations->nearLocation, nearVal); | ||
| 219 | program->setUniformValue(locations->depthScale, (farVal - nearVal) / farVal); | ||
| 220 | float nearScale = -1.0f / nearVal; | ||
| 221 | float sScale = 1.0f / sWidth; | ||
| 222 | float depthTexCoordScaleS = (right - left) * nearScale * sScale; | ||
| 223 | program->setUniformValue(locations->depthTexCoordOffset, left * nearScale - sMin * depthTexCoordScaleS, | ||
| 224 | bottom * nearScale); | ||
| 225 | program->setUniformValue(locations->depthTexCoordScale, depthTexCoordScaleS, (top - bottom) * nearScale); | ||
| 226 | |||
| 227 | renderFullscreenQuad(sMin, sMin + sWidth); | ||
| 228 | |||
| 229 | program->release(); | ||
| 230 | |||
| 231 | glBindTexture(GL_TEXTURE_2D, 0); | ||
| 232 | |||
| 233 | glActiveTexture(GL_TEXTURE2); | ||
| 234 | glBindTexture(GL_TEXTURE_2D, 0); | ||
| 235 | |||
| 236 | glActiveTexture(GL_TEXTURE1); | ||
| 237 | |||
| 238 | } else { | ||
| 239 | _directionalLight.bind(); | ||
| 240 | renderFullscreenQuad(sMin, sMin + sWidth); | ||
| 241 | _directionalLight.release(); | ||
| 242 | } | ||
| 243 | |||
| 244 | glBindTexture(GL_TEXTURE_2D, 0); | ||
| 245 | glActiveTexture(GL_TEXTURE0); | ||
| 246 | |||
| 247 | freeFBO->release(); | ||
| 248 | |||
| 249 | // now transfer the lit region to the primary fbo | ||
| 250 | glEnable(GL_BLEND); | ||
| 251 | |||
| 252 | primaryFBO->bind(); | ||
| 253 | |||
| 254 | glBindTexture(GL_TEXTURE_2D, freeFBO->texture()); | ||
| 255 | glEnable(GL_TEXTURE_2D); | ||
| 256 | |||
| 257 | glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | ||
| 258 | |||
| 259 | renderFullscreenQuad(sMin, sMin + sWidth); | ||
| 260 | |||
| 261 | glBindTexture(GL_TEXTURE_2D, 0); | ||
| 262 | glDisable(GL_TEXTURE_2D); | ||
| 263 | |||
| 264 | glEnable(GL_LIGHTING); | ||
| 265 | glEnable(GL_DEPTH_TEST); | ||
| 266 | glDepthMask(true); | ||
| 267 | |||
| 268 | glDisable(GL_ALPHA_TEST); | ||
| 269 | |||
| 270 | glPopMatrix(); | ||
| 271 | |||
| 272 | glMatrixMode(GL_MODELVIEW); | ||
| 273 | glPopMatrix(); | ||
| 274 | } | 146 | } |
| 275 | 147 | ||
| 276 | class RayHeightfieldIntersectionVisitor : public RayIntersectionVisitor { | 148 | class RayHeightfieldIntersectionVisitor : public RayIntersectionVisitor { |
| @@ -630,24 +502,6 @@ void MetavoxelSystem::guideToAugmented(MetavoxelVisitor& visitor, bool render) { · 353 unmodified lines | |||
| 630 | } | 502 | } |
| 631 | } | 503 | } |
| 632 | 504 | ||
| 633 | void MetavoxelSystem::loadLightProgram(const char* name, ProgramObject& program, LightLocations& locations) { | ||
| 634 | program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + name); | ||
| 635 | program.link(); | ||
| 636 | |||
| 637 | program.bind(); | ||
| 638 | program.setUniformValue("diffuseMap", 0); | ||
| 639 | program.setUniformValue("normalMap", 1); | ||
| 640 | program.setUniformValue("depthMap", 2); | ||
| 641 | program.setUniformValue("shadowMap", 3); | ||
| 642 | locations.shadowDistances = program.uniformLocation("shadowDistances"); | ||
| 643 | locations.shadowScale = program.uniformLocation("shadowScale"); | ||
| 644 | locations.nearLocation = program.uniformLocation("near"); | ||
| 645 | locations.depthScale = program.uniformLocation("depthScale"); | ||
| 646 | locations.depthTexCoordOffset = program.uniformLocation("depthTexCoordOffset"); | ||
| 647 | locations.depthTexCoordScale = program.uniformLocation("depthTexCoordScale"); | ||
| 648 | program.release(); | ||
| 649 | } | ||
| 650 | |||
| 651 | MetavoxelSystemClient::MetavoxelSystemClient(const SharedNodePointer& node, MetavoxelUpdater* updater) : | 505 | MetavoxelSystemClient::MetavoxelSystemClient(const SharedNodePointer& node, MetavoxelUpdater* updater) : |
| 652 | MetavoxelClient(node, updater) { | 506 | MetavoxelClient(node, updater) { |
| 653 | } | 507 | } |
| @@ -1077,8 +931,6 @@ void HeightfieldBuffer::render(bool cursor) { · 423 unmodified lines | |||
| 1077 | 931 | ||
| 1078 | bufferPair.first.release(); | 932 | bufferPair.first.release(); |
| 1079 | bufferPair.second.release(); | 933 | bufferPair.second.release(); |
| 1080 | |||
| 1081 | Application::getInstance()->getMetavoxels()->noteNeedToLight(); | ||
| 1082 | } | 934 | } |
| 1083 | 935 | ||
| 1084 | QHash<int, HeightfieldBuffer::BufferPair> HeightfieldBuffer::_bufferPairs; | 936 | QHash<int, HeightfieldBuffer::BufferPair> HeightfieldBuffer::_bufferPairs; |
| @@ -1245,8 +1097,6 @@ void VoxelBuffer::render(bool cursor) { · 160 unmodified lines | |||
| 1245 | 1097 | ||
| 1246 | _vertexBuffer.release(); | 1098 | _vertexBuffer.release(); |
| 1247 | _indexBuffer.release(); | 1099 | _indexBuffer.release(); |
| 1248 | |||
| 1249 | Application::getInstance()->getMetavoxels()->noteNeedToLight(); | ||
| 1250 | } | 1100 | } |
| 1251 | 1101 | ||
| 1252 | BufferDataAttribute::BufferDataAttribute(const QString& name) : | 1102 | BufferDataAttribute::BufferDataAttribute(const QString& name) : |