Showing the changes to interface/src/VoxelSystem.cpp (1 of 27 files). Show all
Unified · Split
| @@ -519,6 +519,13 @@ void VoxelSystem::initVoxelMemory() { · 518 unmodified lines | ||
| 519 | 519 | _perlinModulateProgram.bind(); |
| 520 | 520 | _perlinModulateProgram.setUniformValue("permutationNormalTexture", 0); |
| 521 | 521 | _perlinModulateProgram.release(); |
| 522 | + | |
| 523 | + _shadowMapProgram.addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/shadow_map.frag"); | |
| 524 | + _shadowMapProgram.link(); | |
| 525 | + | |
| 526 | + _shadowMapProgram.bind(); | |
| 527 | + _shadowMapProgram.setUniformValue("shadowMap", 0); | |
| 528 | + _shadowMapProgram.release(); | |
| 522 | 529 | } |
| 523 | 530 | } |
| 524 | 531 | |
| @@ -1092,6 +1099,7 @@ glm::vec3 VoxelSystem::computeVoxelVertex(const glm::vec3& startVertex, float vo · 567 unmodified lines | ||
| 1092 | 1099 | } |
| 1093 | 1100 | |
| 1094 | 1101 | ProgramObject VoxelSystem::_perlinModulateProgram; |
| 1102 | +ProgramObject VoxelSystem::_shadowMapProgram; | |
| 1095 | 1103 | |
| 1096 | 1104 | void VoxelSystem::init() { |
| 1097 | 1105 | if (_initialized) { |
| @@ -1398,20 +1406,41 @@ void VoxelSystem::render(bool texture) { · 300 unmodified lines | ||
| 1398 | 1406 | } |
| 1399 | 1407 | |
| 1400 | 1408 | void VoxelSystem::applyScaleAndBindProgram(bool texture) { |
| 1401 | − glPushMatrix(); | |
| 1402 | − glScalef(_treeScale, _treeScale, _treeScale); | |
| 1403 | 1409 | |
| 1404 | − if (texture) { | |
| 1410 | + if (Menu::getInstance()->isOptionChecked(MenuOption::Shadows)) { | |
| 1411 | + _shadowMapProgram.bind(); | |
| 1412 | + glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getShadowDepthTextureID()); | |
| 1413 | + glEnable(GL_TEXTURE_GEN_S); | |
| 1414 | + glEnable(GL_TEXTURE_GEN_T); | |
| 1415 | + glEnable(GL_TEXTURE_GEN_R); | |
| 1416 | + glEnable(GL_TEXTURE_2D); | |
| 1417 | + | |
| 1418 | + glTexGenfv(GL_S, GL_EYE_PLANE, (const GLfloat*)&Application::getInstance()->getShadowMatrix()[0]); | |
| 1419 | + glTexGenfv(GL_T, GL_EYE_PLANE, (const GLfloat*)&Application::getInstance()->getShadowMatrix()[1]); | |
| 1420 | + glTexGenfv(GL_R, GL_EYE_PLANE, (const GLfloat*)&Application::getInstance()->getShadowMatrix()[2]); | |
| 1421 | + | |
| 1422 | + } else if (texture) { | |
| 1405 | 1423 | _perlinModulateProgram.bind(); |
| 1406 | 1424 | glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getPermutationNormalTextureID()); |
| 1407 | 1425 | } |
| 1426 | + | |
| 1427 | + glPushMatrix(); | |
| 1428 | + glScalef(_treeScale, _treeScale, _treeScale); | |
| 1408 | 1429 | } |
| 1409 | 1430 | |
| 1410 | 1431 | void VoxelSystem::removeScaleAndReleaseProgram(bool texture) { |
| 1411 | 1432 | // scale back down to 1 so heads aren't massive |
| 1412 | 1433 | glPopMatrix(); |
| 1413 | 1434 | |
| 1414 | − if (texture) { | |
| 1435 | + if (Menu::getInstance()->isOptionChecked(MenuOption::Shadows)) { | |
| 1436 | + _shadowMapProgram.release(); | |
| 1437 | + glBindTexture(GL_TEXTURE_2D, 0); | |
| 1438 | + glDisable(GL_TEXTURE_GEN_S); | |
| 1439 | + glDisable(GL_TEXTURE_GEN_T); | |
| 1440 | + glDisable(GL_TEXTURE_GEN_R); | |
| 1441 | + glDisable(GL_TEXTURE_2D); | |
| 1442 | + | |
| 1443 | + } else if (texture) { | |
| 1415 | 1444 | _perlinModulateProgram.release(); |
| 1416 | 1445 | glBindTexture(GL_TEXTURE_2D, 0); |
| 1417 | 1446 | } |