Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 6 files). Show all
Unified · Split
| @@ -673,13 +673,17 @@ public: · 672 unmodified lines | ||
| 673 | 673 | glm::vec3 vertex; |
| 674 | 674 | }; |
| 675 | 675 | |
| 676 | +const int SPLAT_COUNT = 4; | |
| 677 | +const GLint SPLAT_TEXTURE_UNITS[] = { 3, 4, 5, 6 }; | |
| 678 | + | |
| 676 | 679 | void HeightfieldBuffer::render(bool cursor) { |
| 677 | 680 | // initialize textures, etc. on first render |
| 678 | 681 | if (_heightTextureID == 0) { |
| 679 | 682 | glGenTextures(1, &_heightTextureID); |
| 680 | 683 | glBindTexture(GL_TEXTURE_2D, _heightTextureID); |
| 681 | 684 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 682 | − glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
| 685 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 686 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 683 | 687 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 684 | 688 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 685 | 689 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, _heightSize, _heightSize, 0, |
| @@ -702,7 +706,8 @@ void HeightfieldBuffer::render(bool cursor) { · 16 unmodified lines | ||
| 702 | 706 | if (!_texture.isEmpty()) { |
| 703 | 707 | glGenTextures(1, &_textureTextureID); |
| 704 | 708 | glBindTexture(GL_TEXTURE_2D, _textureTextureID); |
| 705 | − glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
| 709 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 710 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 706 | 711 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 707 | 712 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 708 | 713 | int textureSize = glm::sqrt(_texture.size()); |
| @@ -800,11 +805,53 @@ void HeightfieldBuffer::render(bool cursor) { · 91 unmodified lines | ||
| 800 | 805 | glDrawRangeElements(GL_TRIANGLES, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0); |
| 801 | 806 | |
| 802 | 807 | glDepthFunc(GL_LEQUAL); |
| 808 | + glDepthMask(false); | |
| 803 | 809 | glEnable(GL_BLEND); |
| 804 | − glBlendFunc(GL_DST_COLOR, GL_ZERO); | |
| 810 | + glDisable(GL_ALPHA_TEST); | |
| 805 | 811 | glEnable(GL_POLYGON_OFFSET_FILL); |
| 806 | 812 | glPolygonOffset(-1.0f, -1.0f); |
| 813 | + | |
| 814 | + DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().bind(); | |
| 815 | + DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue( | |
| 816 | + DefaultMetavoxelRendererImplementation::getSplatHeightScaleLocation(), 1.0f / _heightSize); | |
| 817 | + DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue( | |
| 818 | + DefaultMetavoxelRendererImplementation::getSplatTextureScaleLocation(), (float)_heightSize / innerSize); | |
| 819 | + | |
| 820 | + glBindTexture(GL_TEXTURE_2D, _textureTextureID); | |
| 821 | + | |
| 822 | + const int TEXTURES_PER_SPLAT = 4; | |
| 823 | + for (int i = 0; i < _textures.size(); i += TEXTURES_PER_SPLAT) { | |
| 824 | + for (int j = 0; j < SPLAT_COUNT; j++) { | |
| 825 | + glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[j]); | |
| 826 | + int index = i + j; | |
| 827 | + if (index < _networkTextures.size()) { | |
| 828 | + const NetworkTexturePointer& texture = _networkTextures.at(index); | |
| 829 | + glBindTexture(GL_TEXTURE_2D, texture ? texture->getID() : 0); | |
| 830 | + } else { | |
| 831 | + glBindTexture(GL_TEXTURE_2D, 0); | |
| 832 | + } | |
| 833 | + } | |
| 834 | + const float QUARTER_STEP = 0.25f * EIGHT_BIT_MAXIMUM_RECIPROCAL; | |
| 835 | + DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue( | |
| 836 | + DefaultMetavoxelRendererImplementation::getSplatTextureValueMinimaLocation(), | |
| 837 | + (i + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, (i + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, | |
| 838 | + (i + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, (i + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP); | |
| 839 | + DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue( | |
| 840 | + DefaultMetavoxelRendererImplementation::getSplatTextureValueMaximaLocation(), | |
| 841 | + (i + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, (i + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, | |
| 842 | + (i + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, (i + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP); | |
| 843 | + glDrawRangeElements(GL_TRIANGLES, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0); | |
| 844 | + } | |
| 845 | + | |
| 846 | + glEnable(GL_ALPHA_TEST); | |
| 847 | + glBlendFunc(GL_DST_COLOR, GL_ZERO); | |
| 848 | + | |
| 849 | + for (int i = 0; i < SPLAT_COUNT; i++) { | |
| 850 | + glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[i]); | |
| 851 | + glBindTexture(GL_TEXTURE_2D, 0); | |
| 852 | + } | |
| 807 | 853 | |
| 854 | + glActiveTexture(GL_TEXTURE1); | |
| 808 | 855 | glBindTexture(GL_TEXTURE_2D, 0); |
| 809 | 856 | |
| 810 | 857 | if (Menu::getInstance()->isOptionChecked(MenuOption::SimpleShadows)) { |
| @@ -831,7 +878,8 @@ void HeightfieldBuffer::render(bool cursor) { · 20 unmodified lines | ||
| 831 | 878 | glDisable(GL_BLEND); |
| 832 | 879 | glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE); |
| 833 | 880 | glDepthFunc(GL_LESS); |
| 834 | − | |
| 881 | + glDepthMask(true); | |
| 882 | + | |
| 835 | 883 | glActiveTexture(GL_TEXTURE0); |
| 836 | 884 | |
| 837 | 885 | } else { |
| @@ -992,9 +1040,12 @@ void DefaultMetavoxelRendererImplementation::init() { · 154 unmodified lines | ||
| 992 | 1040 | |
| 993 | 1041 | _splatHeightfieldProgram.bind(); |
| 994 | 1042 | _splatHeightfieldProgram.setUniformValue("heightMap", 0); |
| 995 | − _splatHeightfieldProgram.setUniformValue("diffuseMap", 1); | |
| 1043 | + _splatHeightfieldProgram.setUniformValue("textureMap", 1); | |
| 1044 | + _splatHeightfieldProgram.setUniformValueArray("diffuseMaps", SPLAT_TEXTURE_UNITS, SPLAT_COUNT); | |
| 996 | 1045 | _splatHeightScaleLocation = _splatHeightfieldProgram.uniformLocation("heightScale"); |
| 997 | 1046 | _splatTextureScaleLocation = _splatHeightfieldProgram.uniformLocation("textureScale"); |
| 1047 | + _splatTextureValueMinimaLocation = _splatHeightfieldProgram.uniformLocation("textureValueMinima"); | |
| 1048 | + _splatTextureValueMaximaLocation = _splatHeightfieldProgram.uniformLocation("textureValueMaxima"); | |
| 998 | 1049 | _splatHeightfieldProgram.release(); |
| 999 | 1050 | |
| 1000 | 1051 | _lightHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + |
| @@ -1638,6 +1689,8 @@ int DefaultMetavoxelRendererImplementation::_baseColorScaleLocation; · 637 unmodified lines | ||
| 1638 | 1689 | ProgramObject DefaultMetavoxelRendererImplementation::_splatHeightfieldProgram; |
| 1639 | 1690 | int DefaultMetavoxelRendererImplementation::_splatHeightScaleLocation; |
| 1640 | 1691 | int DefaultMetavoxelRendererImplementation::_splatTextureScaleLocation; |
| 1692 | +int DefaultMetavoxelRendererImplementation::_splatTextureValueMinimaLocation; | |
| 1693 | +int DefaultMetavoxelRendererImplementation::_splatTextureValueMaximaLocation; | |
| 1641 | 1694 | ProgramObject DefaultMetavoxelRendererImplementation::_lightHeightfieldProgram; |
| 1642 | 1695 | int DefaultMetavoxelRendererImplementation::_lightHeightScaleLocation; |
| 1643 | 1696 | ProgramObject DefaultMetavoxelRendererImplementation::_shadowLightHeightfieldProgram; |