History

Merge branch 'master' of https://github.com/worklist/hifi into compressed_packets

ZappoMan committed 12 years ago

Commit 70213632 parents 66ebaae 7151d1627 files · +399 −114Browse files

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

Unified · Split

interface/src/VoxelSystem.cpp+33−4
@@ -519,6 +519,13 @@ void VoxelSystem::initVoxelMemory() { · 518 unmodified lines
519519 _perlinModulateProgram.bind();
520520 _perlinModulateProgram.setUniformValue("permutationNormalTexture", 0);
521521 _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();
522529 }
523530 }
524531
@@ -1092,6 +1099,7 @@ glm::vec3 VoxelSystem::computeVoxelVertex(const glm::vec3& startVertex, float vo · 567 unmodified lines
10921099 }
10931100
10941101 ProgramObject VoxelSystem::_perlinModulateProgram;
1102+ProgramObject VoxelSystem::_shadowMapProgram;
10951103
10961104 void VoxelSystem::init() {
10971105 if (_initialized) {
@@ -1398,20 +1406,41 @@ void VoxelSystem::render(bool texture) { · 300 unmodified lines
13981406 }
13991407
14001408 void VoxelSystem::applyScaleAndBindProgram(bool texture) {
1401− glPushMatrix();
1402− glScalef(_treeScale, _treeScale, _treeScale);
14031409
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) {
14051423 _perlinModulateProgram.bind();
14061424 glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getPermutationNormalTextureID());
14071425 }
1426+
1427+ glPushMatrix();
1428+ glScalef(_treeScale, _treeScale, _treeScale);
14081429 }
14091430
14101431 void VoxelSystem::removeScaleAndReleaseProgram(bool texture) {
14111432 // scale back down to 1 so heads aren't massive
14121433 glPopMatrix();
14131434
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) {
14151444 _perlinModulateProgram.release();
14161445 glBindTexture(GL_TEXTURE_2D, 0);
14171446 }