From 9eb545720c349814085ab1a801bdbe80f44ca6e6 Mon Sep 17 00:00:00 2001 From: Haydelj Date: Fri, 6 Sep 2019 12:06:47 -0600 Subject: [PATCH 01/10] started to converte glyph geom and remvoed unused shaders --- src/Graphics/Glyphs/GlyphGeom.cc | 128 ++++--------- .../Modules/Render/ES/shaders/Color.fs | 42 ----- .../Modules/Render/ES/shaders/Color.vs | 43 ----- .../Modules/Render/ES/shaders/ColorMap.fs | 118 ------------ .../Modules/Render/ES/shaders/ColorMap.vs | 48 ----- .../Render/ES/shaders/ColorMapUniform.fs | 48 ----- .../Render/ES/shaders/ColorMapUniform.vs | 47 ----- .../Render/ES/shaders/DblSided_ColorMap.fs | 36 ---- .../Render/ES/shaders/DblSided_ColorMap.vs | 47 ----- .../ES/shaders/DblSided_DirPhongCMap.fs | 153 ---------------- .../ES/shaders/DblSided_DirPhongCMap.vs | 57 ------ .../Render/ES/shaders/DblSided_InSituColor.fs | 42 ----- .../Render/ES/shaders/DblSided_InSituColor.vs | 45 ----- .../Modules/Render/ES/shaders/DirGouraud.fs | 42 ----- .../Modules/Render/ES/shaders/DirGouraud.vs | 72 -------- .../Modules/Render/ES/shaders/DirPhongCMap.fs | 165 ----------------- .../Modules/Render/ES/shaders/DirPhongCMap.vs | 55 ------ .../Render/ES/shaders/DirPhongInSitu.fs | 168 ------------------ .../Render/ES/shaders/DirPhongInSitu.vs | 55 ------ .../Render/ES/shaders/DirPhongNoClipping.fs | 107 ----------- .../Modules/Render/ES/shaders/Flat_Color.fs | 135 ++++++++++++++ .../ES/shaders/{DirPhong.vs => Flat_Color.vs} | 8 +- .../Render/ES/shaders/Flat_ColorMap.vs | 1 - .../Modules/Render/ES/shaders/InSituColor.fs | 126 ------------- .../Modules/Render/ES/shaders/InSituColor.vs | 48 ----- .../shaders/{DirPhong.fs => Phong_Color.fs} | 93 +++++----- .../{DirPhongNoClipping.vs => Phong_Color.vs} | 5 +- .../Modules/Render/ES/shaders/UniformColor.fs | 126 ------------- .../Modules/Render/ES/shaders/UniformColor.vs | 48 ----- 29 files changed, 223 insertions(+), 1885 deletions(-) delete mode 100644 src/Interface/Modules/Render/ES/shaders/Color.fs delete mode 100644 src/Interface/Modules/Render/ES/shaders/Color.vs delete mode 100644 src/Interface/Modules/Render/ES/shaders/ColorMap.fs delete mode 100644 src/Interface/Modules/Render/ES/shaders/ColorMap.vs delete mode 100644 src/Interface/Modules/Render/ES/shaders/ColorMapUniform.fs delete mode 100644 src/Interface/Modules/Render/ES/shaders/ColorMapUniform.vs delete mode 100644 src/Interface/Modules/Render/ES/shaders/DblSided_ColorMap.fs delete mode 100644 src/Interface/Modules/Render/ES/shaders/DblSided_ColorMap.vs delete mode 100644 src/Interface/Modules/Render/ES/shaders/DblSided_DirPhongCMap.fs delete mode 100644 src/Interface/Modules/Render/ES/shaders/DblSided_DirPhongCMap.vs delete mode 100644 src/Interface/Modules/Render/ES/shaders/DblSided_InSituColor.fs delete mode 100644 src/Interface/Modules/Render/ES/shaders/DblSided_InSituColor.vs delete mode 100644 src/Interface/Modules/Render/ES/shaders/DirGouraud.fs delete mode 100644 src/Interface/Modules/Render/ES/shaders/DirGouraud.vs delete mode 100644 src/Interface/Modules/Render/ES/shaders/DirPhongCMap.fs delete mode 100644 src/Interface/Modules/Render/ES/shaders/DirPhongCMap.vs delete mode 100644 src/Interface/Modules/Render/ES/shaders/DirPhongInSitu.fs delete mode 100644 src/Interface/Modules/Render/ES/shaders/DirPhongInSitu.vs delete mode 100644 src/Interface/Modules/Render/ES/shaders/DirPhongNoClipping.fs create mode 100644 src/Interface/Modules/Render/ES/shaders/Flat_Color.fs rename src/Interface/Modules/Render/ES/shaders/{DirPhong.vs => Flat_Color.vs} (92%) delete mode 100644 src/Interface/Modules/Render/ES/shaders/InSituColor.fs delete mode 100644 src/Interface/Modules/Render/ES/shaders/InSituColor.vs rename src/Interface/Modules/Render/ES/shaders/{DirPhong.fs => Phong_Color.fs} (73%) rename src/Interface/Modules/Render/ES/shaders/{DirPhongNoClipping.vs => Phong_Color.vs} (93%) delete mode 100644 src/Interface/Modules/Render/ES/shaders/UniformColor.fs delete mode 100644 src/Interface/Modules/Render/ES/shaders/UniformColor.vs diff --git a/src/Graphics/Glyphs/GlyphGeom.cc b/src/Graphics/Glyphs/GlyphGeom.cc index c4d255c70b..d60a8bd517 100644 --- a/src/Graphics/Glyphs/GlyphGeom.cc +++ b/src/Graphics/Glyphs/GlyphGeom.cc @@ -50,154 +50,86 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique std::string passName = uniqueNodeID + "Pass"; bool useTriangles = primIn == SpireIBO::PRIMITIVE::TRIANGLES; + bool useColor = colorScheme == ColorScheme::COLOR_IN_SITU || colorScheme == ColorScheme::COLOR_MAP; + bool useNormals = normals_.size() == points_.size(); - // Construct VBO. - std::string shader = "Shaders/UniformColor"; - std::vector attribs; - attribs.push_back(SpireVBO::AttributeData("aPos", 3 * sizeof(float))); - if (useTriangles) - attribs.push_back(SpireVBO::AttributeData("aNormal", 3 * sizeof(float))); RenderType renderType = RenderType::RENDER_VBO_IBO; + ColorRGB dft = state.defaultColor; - //ColorScheme colorScheme = COLOR_UNIFORM; - + std::string shader = (useNormals ? "Shaders/Phong" : "Shaders/Flat"); + std::vector attribs; std::vector uniforms; - if (isTransparent) - uniforms.push_back(SpireSubPass::Uniform("uTransparency", static_cast(transparencyValue))); - // TODO: add colormapping options - if (colorScheme == ColorScheme::COLOR_MAP) + + attribs.push_back(SpireVBO::AttributeData("aPos", 3 * sizeof(float))); + + if (useNormals) { - attribs.push_back(SpireVBO::AttributeData("aColor", 4 * sizeof(float))); - if (useTriangles) - { - shader = "Shaders/DirPhongCMap"; - uniforms.push_back(SpireSubPass::Uniform("uAmbientColor", - glm::vec4(0.1f, 0.1f, 0.1f, 1.0f))); - uniforms.push_back(SpireSubPass::Uniform("uSpecularColor", - glm::vec4(0.1f, 0.1f, 0.1f, 0.1f))); - uniforms.push_back(SpireSubPass::Uniform("uSpecularPower", 32.0f)); - } - else - { - shader = "Shaders/ColorMap"; - } + attribs.push_back(SpireVBO::AttributeData("aNormal", 3 * sizeof(float))); + uniforms.push_back(SpireSubPass::Uniform("uAmbientColor", glm::vec4(0.1f, 0.1f, 0.1f, 1.0f))); + uniforms.push_back(SpireSubPass::Uniform("uSpecularColor", glm::vec4(0.1f, 0.1f, 0.1f, 0.1f))); + uniforms.push_back(SpireSubPass::Uniform("uSpecularPower", 32.0f)); } - else if (colorScheme == ColorScheme::COLOR_IN_SITU) + + if (useColor) { + shader += "_Color"; attribs.push_back(SpireVBO::AttributeData("aColor", 4 * sizeof(float))); - if (useTriangles) - { - shader = "Shaders/DirPhongInSitu"; - uniforms.push_back(SpireSubPass::Uniform("uAmbientColor", - glm::vec4(0.1f, 0.1f, 0.1f, 1.0f))); - uniforms.push_back(SpireSubPass::Uniform("uSpecularColor", - glm::vec4(0.1f, 0.1f, 0.1f, 0.1f))); - uniforms.push_back(SpireSubPass::Uniform("uSpecularPower", 32.0f)); - } - else - { - shader = "Shaders/InSituColor"; - } } - else if (colorScheme == ColorScheme::COLOR_UNIFORM) + else { - ColorRGB dft = state.defaultColor; - if (useTriangles) - { - if (geom.isClippable()) - shader = "Shaders/DirPhong"; - else - shader = "Shaders/DirPhongNoClipping"; - uniforms.push_back(SpireSubPass::Uniform("uAmbientColor", - glm::vec4(0.1f, 0.1f, 0.1f, 1.0f))); - uniforms.push_back(SpireSubPass::Uniform("uDiffuseColor", - glm::vec4(dft.r(), dft.g(), dft.b(), static_cast(transparencyValue)))); - uniforms.push_back(SpireSubPass::Uniform("uSpecularColor", - glm::vec4(0.1f, 0.1f, 0.1f, 0.1f))); - uniforms.push_back(SpireSubPass::Uniform("uSpecularPower", 32.0f)); - } - else - { - uniforms.emplace_back("uColor", glm::vec4(dft.r(), dft.g(), dft.b(), static_cast(transparencyValue))); - } + uniforms.push_back(SpireSubPass::Uniform("uDiffuseColor", + glm::vec4(dft.r(), dft.g(), dft.b(), static_cast(transparencyValue)))); } - uint32_t iboSize = 0; - uint32_t vboSize = 0; - - vboSize = static_cast(points_.size()) * 3 * sizeof(float); - vboSize += static_cast(normals_.size()) * 3 * sizeof(float); - if (colorScheme == ColorScheme::COLOR_IN_SITU || colorScheme == ColorScheme::COLOR_MAP) - vboSize += static_cast(colors_.size()) * 4 * sizeof(float); //RGBA - iboSize = static_cast(indices_.size()) * sizeof(uint32_t); - /// \todo To reduce memory requirements, we can use a 16bit index buffer. - - /// \todo To further reduce a large amount of memory, get rid of the index - /// buffer and use glDrawArrays to render without an IBO. An IBO is - /// a waste of space. - /// http://www.opengl.org/sdk/docs/man3/xhtml/glDrawArrays.xml + if (isTransparent) uniforms.push_back(SpireSubPass::Uniform("uTransparency", static_cast(transparencyValue))); - /// \todo Switch to unique_ptrs and move semantics. + size_t vboSize = static_cast(points_.size()) * 3 * sizeof(float); + if (useNormals) vboSize += static_cast(normals_.size()) * 3 * sizeof(float); + if (useColor) vboSize += static_cast(colors_.size()) * 4 * sizeof(float); //RGBA + size_t iboSize = static_cast(indices_.size()) * sizeof(uint32_t); std::shared_ptr iboBufferSPtr(new spire::VarBuffer(iboSize)); std::shared_ptr vboBufferSPtr(new spire::VarBuffer(vboSize)); - - // Accessing the pointers like this is contrived. We only do this for - // speed since we will be using the pointers in a tight inner loop. auto iboBuffer = iboBufferSPtr.get(); auto vboBuffer = vboBufferSPtr.get(); //write to the IBO/VBOs - for (auto a : indices_) iboBuffer->write(a); BBox newBBox; - - const bool writeNormals = normals_.size() == points_.size(); for (size_t i = 0; i < points_.size(); i++) { - // Write first point on line + newBBox.extend(Point(points_.at(i).x(), points_.at(i).y(), points_.at(i).z())); vboBuffer->write(static_cast(points_.at(i).x())); vboBuffer->write(static_cast(points_.at(i).y())); vboBuffer->write(static_cast(points_.at(i).z())); - newBBox.extend(Point(points_.at(i).x(), points_.at(i).y(), points_.at(i).z())); - - if (writeNormals) + if (useNormals) { vboBuffer->write(static_cast(normals_.at(i).x())); vboBuffer->write(static_cast(normals_.at(i).y())); vboBuffer->write(static_cast(normals_.at(i).z())); } - if (colorScheme == ColorScheme::COLOR_MAP || colorScheme == ColorScheme::COLOR_IN_SITU) + + if (useColor) { vboBuffer->write(static_cast(colors_.at(i).r())); vboBuffer->write(static_cast(colors_.at(i).g())); vboBuffer->write(static_cast(colors_.at(i).b())); vboBuffer->write(static_cast(colors_.at(i).a())); - //vboBuffer->write(static_cast(1.f)); - } // no color writing otherwise + } } + if(!bbox.valid()) newBBox.reset(); - if(!bbox.valid()) - newBBox.reset(); - - // If true, then the VBO will be placed on the GPU. We don't want to place - // VBOs on the GPU when we are generating rendering lists. SpireVBO geomVBO(vboName, attribs, vboBufferSPtr, numVBOElements_, newBBox, true); - - // Construct IBO. SpireIBO geomIBO(iboName, primIn, sizeof(uint32_t), iboBufferSPtr); state.set(RenderState::IS_ON, true); state.set(RenderState::HAS_DATA, true); SpireText text; - - // Construct Pass. SpireSubPass pass(passName, vboName, iboName, shader, colorScheme, state, renderType, geomVBO, geomIBO, text); - // Add all uniforms generated above to the pass. for (const auto& uniform : uniforms) { pass.addUniform(uniform); } geom.vbos().push_back(geomVBO); diff --git a/src/Interface/Modules/Render/ES/shaders/Color.fs b/src/Interface/Modules/Render/ES/shaders/Color.fs deleted file mode 100644 index edd693863f..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/Color.fs +++ /dev/null @@ -1,42 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ -#ifdef OPENGL_ES - #ifdef GL_FRAGMENT_PRECISION_HIGH - // Default precision - precision highp float; - #else - precision mediump float; - #endif -#endif - -varying vec4 fColor; - -void main() -{ - gl_FragColor = fColor; -} diff --git a/src/Interface/Modules/Render/ES/shaders/Color.vs b/src/Interface/Modules/Render/ES/shaders/Color.vs deleted file mode 100644 index 2d919bd83e..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/Color.vs +++ /dev/null @@ -1,43 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -// Uniforms -uniform mat4 uModelViewProjection; - -// Attributes -attribute vec3 aPos; -attribute vec4 aColorFloat; - -// Outputs to the fragment shader. -varying vec4 fColor; - -void main( void ) -{ - gl_Position = uModelViewProjection * vec4(aPos, 1.0); - fColor = aColorFloat; -} diff --git a/src/Interface/Modules/Render/ES/shaders/ColorMap.fs b/src/Interface/Modules/Render/ES/shaders/ColorMap.fs deleted file mode 100644 index 187b9649e5..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/ColorMap.fs +++ /dev/null @@ -1,118 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - */ -varying vec4 fColor; -varying vec4 vPosWorld;//for clipping plane calc -varying vec4 vPosView;// for fog calculation - -// Transparency to use along side the color map. -uniform float uTransparency; - -//clipping planes -uniform vec4 uClippingPlane0; // clipping plane 0 -uniform vec4 uClippingPlane1; // clipping plane 1 -uniform vec4 uClippingPlane2; // clipping plane 2 -uniform vec4 uClippingPlane3; // clipping plane 3 -uniform vec4 uClippingPlane4; // clipping plane 4 -uniform vec4 uClippingPlane5; // clipping plane 5 -//clipping plane controls -uniform vec4 uClippingPlaneCtrl0;// clipping plane 0 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl1;// clipping plane 1 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl2;// clipping plane 2 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl3;// clipping plane 3 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl4;// clipping plane 4 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl5;// clipping plane 5 control (visible, showFrame, reverseNormal, 0) - -//fog -uniform vec4 uFogSettings; // fog settings (intensity, start, end, 0.0) -uniform vec4 uFogColor; // fog color - -void main() -{ - float fPlaneValue; - if (uClippingPlaneCtrl0.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane0); - fPlaneValue = uClippingPlaneCtrl0.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl1.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane1); - fPlaneValue = uClippingPlaneCtrl1.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl2.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane2); - fPlaneValue = uClippingPlaneCtrl2.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl3.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane3); - fPlaneValue = uClippingPlaneCtrl3.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl4.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane4); - fPlaneValue = uClippingPlaneCtrl4.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl5.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane5); - fPlaneValue = uClippingPlaneCtrl5.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - - gl_FragColor = vec4(fColor.xyz,uTransparency); - - //calculate fog - if (uFogSettings.x > 0.0) - { - vec4 fp; - fp.x = uFogSettings.x; - fp.y = uFogSettings.y; - fp.z = uFogSettings.z; - fp.w = abs(vPosView.z/vPosView.w); - - float fog_factor; - fog_factor = (fp.z-fp.w)/(fp.z-fp.y); - fog_factor = 1.0 - clamp(fog_factor, 0.0, 1.0); - fog_factor = 1.0 - exp(-pow(fog_factor*2.5, 2.0)); - gl_FragColor.xyz = mix(clamp(gl_FragColor.xyz, 0.0, 1.0), - clamp(uFogColor.xyz, 0.0, 1.0), fog_factor); - } -} diff --git a/src/Interface/Modules/Render/ES/shaders/ColorMap.vs b/src/Interface/Modules/Render/ES/shaders/ColorMap.vs deleted file mode 100644 index 041d297749..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/ColorMap.vs +++ /dev/null @@ -1,48 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -// Uniforms -uniform mat4 uModelViewProjection; -uniform mat4 uView; - -// Attributes -attribute vec3 aPos; -attribute vec4 aColor; - -// Outputs to the fragment shader. -varying vec4 fColor; -varying vec4 vPosWorld;//for clipping plane calc -varying vec4 vPosView;// for fog calculation - -void main( void ) -{ - gl_Position = uModelViewProjection * vec4(aPos, 1.0); - fColor = aColor; - vPosWorld = vec4(aPos, 1.0); - vPosView = uView * vPosWorld; -} diff --git a/src/Interface/Modules/Render/ES/shaders/ColorMapUniform.fs b/src/Interface/Modules/Render/ES/shaders/ColorMapUniform.fs deleted file mode 100644 index 79d415364f..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/ColorMapUniform.fs +++ /dev/null @@ -1,48 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ -#ifdef OPENGL_ES - #ifdef GL_FRAGMENT_PRECISION_HIGH - // Default precision - precision highp float; - #else - precision mediump float; - #endif -#endif - -uniform sampler1D uTX0; -varying float fFieldData; - -// Transparency to use along side the color map. -uniform float uTransparency; - -void main() -{ - vec4 color = texture1D(uTX0, fFieldData); - color.a = uTransparency; - gl_FragColor = color; -} diff --git a/src/Interface/Modules/Render/ES/shaders/ColorMapUniform.vs b/src/Interface/Modules/Render/ES/shaders/ColorMapUniform.vs deleted file mode 100644 index 32a724188b..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/ColorMapUniform.vs +++ /dev/null @@ -1,47 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -// Uniforms -uniform mat4 uModelViewProjection; - -// The following values are used to rescale the data between 0 .. 1. -uniform float uFieldData; - -// Transparency to use along side the color map. - -// Attributes -attribute vec3 aPos; - -// Outputs to the fragment shader. -varying float fFieldData; - -void main( void ) -{ - gl_Position = uModelViewProjection * vec4(aPos, 1.0); - fFieldData = uFieldData; -} diff --git a/src/Interface/Modules/Render/ES/shaders/DblSided_ColorMap.fs b/src/Interface/Modules/Render/ES/shaders/DblSided_ColorMap.fs deleted file mode 100644 index 49ecd4440f..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/DblSided_ColorMap.fs +++ /dev/null @@ -1,36 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ -varying vec4 fColor; - -// Transparency to use along side the color map. -uniform float uTransparency; - -void main() -{ - gl_FragColor = vec4(fColor.xyx,uTransparency); -} diff --git a/src/Interface/Modules/Render/ES/shaders/DblSided_ColorMap.vs b/src/Interface/Modules/Render/ES/shaders/DblSided_ColorMap.vs deleted file mode 100644 index ff33992b50..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/DblSided_ColorMap.vs +++ /dev/null @@ -1,47 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -// Uniforms -uniform mat4 uModelViewProjection; -uniform vec4 uColor; // Uniform color -uniform float uFDToggle; // Field data toggle - -// Attributes -attribute vec3 aPos; -attribute vec4 aColor; -attribute vec4 aColorSecondary; - -// Outputs to the fragment shader. -varying vec4 fColor; - -void main( void ) -{ - gl_Position = uModelViewProjection * vec4(aPos, 1.0); - vec4 colorData = uFDToggle * aColor + (1.0 - uFDToggle) * aColorSecondary; - fColor = colorData; -} diff --git a/src/Interface/Modules/Render/ES/shaders/DblSided_DirPhongCMap.fs b/src/Interface/Modules/Render/ES/shaders/DblSided_DirPhongCMap.fs deleted file mode 100644 index 61473ed768..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/DblSided_DirPhongCMap.fs +++ /dev/null @@ -1,153 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -uniform vec3 uCamViewVec; // Camera 'at' vector in world space -uniform vec4 uAmbientColor; // Ambient color -uniform vec4 uSpecularColor; // Specular color -uniform vec4 uDiffuseColor; // Diffuse color -uniform float uSpecularPower; // Specular power -uniform vec3 uLightDirectionView; // Directional light (view space). - -//clipping planes -uniform vec4 uClippingPlane0; // clipping plane 0 -uniform vec4 uClippingPlane1; // clipping plane 1 -uniform vec4 uClippingPlane2; // clipping plane 2 -uniform vec4 uClippingPlane3; // clipping plane 3 -uniform vec4 uClippingPlane4; // clipping plane 4 -uniform vec4 uClippingPlane5; // clipping plane 5 -//clipping plane controls -uniform vec4 uClippingPlaneCtrl0;// clipping plane 0 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl1;// clipping plane 1 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl2;// clipping plane 2 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl3;// clipping plane 3 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl4;// clipping plane 4 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl5;// clipping plane 5 control (visible, showFrame, reverseNormal, 0) - -//fog -uniform vec4 uFogSettings; // fog settings (intensity, start, end, 0.0) -uniform vec4 uFogColor; // fog color - -// Lighting in world space. Generally, it's better to light in eye space if you -// are dealing with point lights. Since we are only dealing with directional -// lights we light in world space. -varying vec3 vNormal; -varying vec4 vColor; -varying vec4 vPosWorld;//for clipping plane calc -varying vec4 vPosView;// for fog calculation - -void main() -{ - float fPlaneValue; - if (uClippingPlaneCtrl0.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane0); - fPlaneValue = uClippingPlaneCtrl0.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl1.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane1); - fPlaneValue = uClippingPlaneCtrl1.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl2.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane2); - fPlaneValue = uClippingPlaneCtrl2.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl3.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane3); - fPlaneValue = uClippingPlaneCtrl3.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl4.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane4); - fPlaneValue = uClippingPlaneCtrl4.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl5.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane5); - fPlaneValue = uClippingPlaneCtrl5.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - - // Remember to always negate the light direction for these lighting - // calculations. The dot product takes on its greatest values when the angle - // between the two vectors diminishes. - vec3 invLightDir = -uLightDirectionView; - vec3 normal = normalize(vNormal); - float diffuse = max(0.0, dot(normal, invLightDir)); - - // Note, the following is a hack due to legacy meshes still being supported. - // We light the object as if it was double sided. We choose the normal based - // on the normal that yields the largest diffuse component. - float diffuseInv = max(0.0, dot(-normal, invLightDir)); - - if (diffuse < diffuseInv) - { - diffuse = diffuseInv; - normal = -normal; - } - - vec3 reflection = reflect(invLightDir, normal); - float spec = max(0.0, dot(reflection, uCamViewVec)); - - vec4 diffuseColor = vColor; - diffuseColor.a = uAmbientColor.a; - - spec = pow(spec, uSpecularPower); - gl_FragColor = diffuse * spec * uSpecularColor + diffuse * diffuseColor + uAmbientColor; - - //calculate fog - if (uFogSettings.x > 0.0) - { - vec4 fp; - fp.x = uFogSettings.x; - fp.y = uFogSettings.y; - fp.z = uFogSettings.z; - fp.w = abs(vPosView.z/vPosView.w); - - float fog_factor; - fog_factor = (fp.z-fp.w)/(fp.z-fp.y); - fog_factor = 1.0 - clamp(fog_factor, 0.0, 1.0); - fog_factor = 1.0 - exp(-pow(fog_factor*2.5, 2.0)); - gl_FragColor.xyz = mix(clamp(gl_FragColor.xyz, 0.0, 1.0), - clamp(uFogColor.xyz, 0.0, 1.0), fog_factor); - } -} - diff --git a/src/Interface/Modules/Render/ES/shaders/DblSided_DirPhongCMap.vs b/src/Interface/Modules/Render/ES/shaders/DblSided_DirPhongCMap.vs deleted file mode 100644 index 5e36362e15..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/DblSided_DirPhongCMap.vs +++ /dev/null @@ -1,57 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -// Uniforms -uniform mat4 uModelViewProjection; -uniform mat4 uModel; -uniform float uFDToggle; // Field data toggle -uniform mat4 uView; - -// Attributes -attribute vec3 aPos; -attribute vec3 aNormal; -attribute vec4 aColor; -attribute vec4 aColorSecondary; - -// Outputs to the fragment shader. -varying vec3 vNormal; -varying vec4 vColor; -varying vec4 vPosWorld;//for clipping plane calc -varying vec4 vPosView;// for fog calculation - -void main( void ) -{ - gl_Position = uModelViewProjection * vec4(aPos, 1.0); - - vNormal = vec3(uModel * vec4(aNormal, 0.0)); - - vec4 colorData = uFDToggle * aColor + (1.0 - uFDToggle) * aColorSecondary; - vColor = colorData; - vPosWorld = vec4(aPos, 1.0); - vPosView = uView * vPosWorld; -} diff --git a/src/Interface/Modules/Render/ES/shaders/DblSided_InSituColor.fs b/src/Interface/Modules/Render/ES/shaders/DblSided_InSituColor.fs deleted file mode 100644 index edd693863f..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/DblSided_InSituColor.fs +++ /dev/null @@ -1,42 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ -#ifdef OPENGL_ES - #ifdef GL_FRAGMENT_PRECISION_HIGH - // Default precision - precision highp float; - #else - precision mediump float; - #endif -#endif - -varying vec4 fColor; - -void main() -{ - gl_FragColor = fColor; -} diff --git a/src/Interface/Modules/Render/ES/shaders/DblSided_InSituColor.vs b/src/Interface/Modules/Render/ES/shaders/DblSided_InSituColor.vs deleted file mode 100644 index 87c47d6d77..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/DblSided_InSituColor.vs +++ /dev/null @@ -1,45 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -// Uniforms -uniform mat4 uModelViewProjection; -uniform float uFDToggle; // Field data toggle - -// Attributes -attribute vec3 aPos; -attribute vec4 aColor; -attribute vec4 aColorSecondary - -// Outputs to the fragment shader. -varying vec4 fColor; - -void main( void ) -{ - gl_Position = uModelViewProjection * vec4(aPos, 1.0); - fColor = uFDToggle * aColor + (1.0 - uFDToggle) * aColorSecondary; -} diff --git a/src/Interface/Modules/Render/ES/shaders/DirGouraud.fs b/src/Interface/Modules/Render/ES/shaders/DirGouraud.fs deleted file mode 100644 index edd693863f..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/DirGouraud.fs +++ /dev/null @@ -1,42 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ -#ifdef OPENGL_ES - #ifdef GL_FRAGMENT_PRECISION_HIGH - // Default precision - precision highp float; - #else - precision mediump float; - #endif -#endif - -varying vec4 fColor; - -void main() -{ - gl_FragColor = fColor; -} diff --git a/src/Interface/Modules/Render/ES/shaders/DirGouraud.vs b/src/Interface/Modules/Render/ES/shaders/DirGouraud.vs deleted file mode 100644 index e02abb15ff..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/DirGouraud.vs +++ /dev/null @@ -1,72 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -// Uniforms -uniform mat4 uModelViewProjection; -uniform mat4 uModel; -uniform vec3 uCamViewVec; // Camera 'at' vector in world space -uniform vec4 uAmbientColor; // Ambient color -uniform vec4 uDiffuseColor; // Diffuse color -uniform vec4 uSpecularColor; // Specular color -uniform float uSpecularPower; // Specular power -uniform vec3 uLightDirectionView; // Directional light (view space). - -// Attributes -attribute vec3 aPos; -attribute vec3 aNormal; - -// Outputs to the fragment shader. -varying vec4 fColor; - -void main( void ) -{ - vec3 invLightDir = -uLightDirectionView; - vec3 normal = normalize(aNormal); - vec3 worldSpaceNorm = vec3(uModel * vec4(normal, 0.0)); - float diffuse = max(0.0, dot(worldSpaceNorm, invLightDir)); - - // Note, the following is a hack due to legacy meshes still being supported. - // We light the object as if it was double sided. We choose the normal based - // on the normal that yields the largest diffuse component. - float diffuseInv = max(0.0, dot(-worldSpaceNorm, invLightDir)); - - if (diffuse < diffuseInv) - { - diffuse = diffuseInv; - worldSpaceNorm = -worldSpaceNorm; - } - - vec3 reflection = reflect(invLightDir, worldSpaceNorm); - float spec = max(0.0, dot(reflection, uCamViewVec)); - - // Convert color into gamma space before rasterization. - spec = pow(spec, uSpecularPower); - fColor = diffuse * spec * uSpecularColor + diffuse * uDiffuseColor + uAmbientColor; - - gl_Position = uModelViewProjection * vec4(aPos, 1.0); -} diff --git a/src/Interface/Modules/Render/ES/shaders/DirPhongCMap.fs b/src/Interface/Modules/Render/ES/shaders/DirPhongCMap.fs deleted file mode 100644 index d9483ecc6a..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/DirPhongCMap.fs +++ /dev/null @@ -1,165 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - */ - - #ifdef OPENGL_ES - #ifdef GL_FRAGMENT_PRECISION_HIGH - precision highp float; - #else - precision mediump float; - #endif - #endif - -uniform vec4 uAmbientColor; -uniform vec4 uSpecularColor; -uniform float uSpecularPower; -uniform vec3 uLightDirectionView0; -uniform vec3 uLightDirectionView1; -uniform vec3 uLightDirectionView2; -uniform vec3 uLightDirectionView3; -uniform vec3 uLightColor0; -uniform vec3 uLightColor1; -uniform vec3 uLightColor2; -uniform vec3 uLightColor3; -uniform float uTransparency; - -uniform vec4 uClippingPlane0; -uniform vec4 uClippingPlane1; -uniform vec4 uClippingPlane2; -uniform vec4 uClippingPlane3; -uniform vec4 uClippingPlane4; -uniform vec4 uClippingPlane5; - -// clipping plane controls (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl0; -uniform vec4 uClippingPlaneCtrl1; -uniform vec4 uClippingPlaneCtrl2; -uniform vec4 uClippingPlaneCtrl3; -uniform vec4 uClippingPlaneCtrl4; -uniform vec4 uClippingPlaneCtrl5; - -// fog settings (intensity, start, end, 0.0) -uniform vec4 uFogSettings; -uniform vec4 uFogColor; - -varying vec3 vNormal; -varying vec4 vColor; -varying vec4 vPosWorld; -varying vec4 vPosView; - -vec4 calculate_lighting(vec3 N, vec3 L, vec3 V, vec3 diffuseColor, vec3 specularColor, vec3 lightColor) -{ - vec3 H = normalize(V + L); - float diffuse = max(0.0, dot(N, L)); - float specular = max(0.0, dot(N, H)); - specular = pow(specular, uSpecularPower); - - return vec4(lightColor * (diffuse * diffuseColor + specular * specularColor), 0.0); -} - -void main() -{ - float fPlaneValue; - if (uClippingPlaneCtrl0.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane0); - fPlaneValue = uClippingPlaneCtrl0.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl1.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane1); - fPlaneValue = uClippingPlaneCtrl1.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl2.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane2); - fPlaneValue = uClippingPlaneCtrl2.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl3.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane3); - fPlaneValue = uClippingPlaneCtrl3.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl4.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane4); - fPlaneValue = uClippingPlaneCtrl4.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl5.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane5); - fPlaneValue = uClippingPlaneCtrl5.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - - vec3 diffuseColor = vColor.rgb; - vec3 specularColor = uSpecularColor.rgb; - vec3 ambientColor = uAmbientColor.rgb; - float transparency = uTransparency; - - vec3 normal = normalize(vNormal); - if (gl_FrontFacing) normal = -normal; - vec3 cameraVector = -normalize(vPosView.xyz); - - gl_FragColor = vec4(ambientColor * diffuseColor, transparency); - if (length(uLightDirectionView0) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView0, cameraVector, diffuseColor, specularColor, uLightColor0); - if (length(uLightDirectionView1) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView1, cameraVector, diffuseColor, specularColor, uLightColor1); - if (length(uLightDirectionView2) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView2, cameraVector, diffuseColor, specularColor, uLightColor2); - if (length(uLightDirectionView3) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView3, cameraVector, diffuseColor, specularColor, uLightColor3); - - //calculate fog - if (uFogSettings.x > 0.0) - { - vec4 fp; - fp.x = uFogSettings.x; - fp.y = uFogSettings.y; - fp.z = uFogSettings.z; - fp.w = abs(vPosView.z/vPosView.w); - - float fog_factor; - fog_factor = (fp.z-fp.w)/(fp.z-fp.y); - fog_factor = 1.0 - clamp(fog_factor, 0.0, 1.0); - fog_factor = 1.0 - exp(-pow(fog_factor*2.5, 2.0)); - gl_FragColor.xyz = mix(clamp(gl_FragColor.xyz, 0.0, 1.0), - clamp(uFogColor.xyz, 0.0, 1.0), fog_factor); - } -} diff --git a/src/Interface/Modules/Render/ES/shaders/DirPhongCMap.vs b/src/Interface/Modules/Render/ES/shaders/DirPhongCMap.vs deleted file mode 100644 index 6277b2fb74..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/DirPhongCMap.vs +++ /dev/null @@ -1,55 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. - */ - -// Uniforms -uniform mat4 uModelViewProjection; -uniform mat4 uModel; -uniform mat4 uView; - -// Attributes -attribute vec3 aPos; -attribute vec3 aNormal; -attribute vec4 aColor; - -// Outputs to the fragment shader. -varying vec3 vNormal; -varying vec4 vColor; -varying vec4 vPosWorld; -varying vec4 vPosView; - -void main( void ) -{ - // Todo: Add gamma correction factor of 2.2. For textures, we assume that it - // was generated in gamma space, and we need to convert it to linear space. - vPosWorld = uModel * vec4(aPos, 1.0); - vPosView = uView * vPosWorld; - vNormal = normalize((uView * uModel * vec4(aNormal, 0.0)).xyz); - vColor = aColor; - - gl_Position = uModelViewProjection * vec4(aPos, 1.0); -} \ No newline at end of file diff --git a/src/Interface/Modules/Render/ES/shaders/DirPhongInSitu.fs b/src/Interface/Modules/Render/ES/shaders/DirPhongInSitu.fs deleted file mode 100644 index d7c427c7c4..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/DirPhongInSitu.fs +++ /dev/null @@ -1,168 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -#ifdef OPENGL_ES - #ifdef GL_FRAGMENT_PRECISION_HIGH - precision highp float; - #else - precision mediump float; - #endif -#endif - -uniform vec3 uCamViewVec; -uniform vec4 uAmbientColor; -uniform vec4 uDiffuseColor; -uniform vec4 uSpecularColor; -uniform float uSpecularPower; -uniform vec3 uLightDirectionView0; -uniform vec3 uLightDirectionView1; -uniform vec3 uLightDirectionView2; -uniform vec3 uLightDirectionView3; -uniform vec3 uLightColor0; -uniform vec3 uLightColor1; -uniform vec3 uLightColor2; -uniform vec3 uLightColor3; -uniform float uTransparency; - -uniform vec4 uClippingPlane0; -uniform vec4 uClippingPlane1; -uniform vec4 uClippingPlane2; -uniform vec4 uClippingPlane3; -uniform vec4 uClippingPlane4; -uniform vec4 uClippingPlane5; - -// clipping plane controls (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl0; -uniform vec4 uClippingPlaneCtrl1; -uniform vec4 uClippingPlaneCtrl2; -uniform vec4 uClippingPlaneCtrl3; -uniform vec4 uClippingPlaneCtrl4; -uniform vec4 uClippingPlaneCtrl5; - -// fog settings (intensity, start, end, 0.0) -uniform vec4 uFogSettings; -uniform vec4 uFogColor; - - -varying vec3 vNormal; -varying vec4 vColor; -varying vec4 vPosWorld; -varying vec4 vPosView; - -vec4 calculate_lighting(vec3 N, vec3 L, vec3 V, vec3 diffuseColor, vec3 specularColor, vec3 lightColor) -{ - vec3 H = normalize(V + L); - float diffuse = max(0.0, dot(N, L)); - float specular = max(0.0, dot(N, H)); - specular = pow(specular, uSpecularPower); - - return vec4(lightColor * (diffuse * diffuseColor + specular * specularColor), 0.0); -} - -void main() -{ - float fPlaneValue; - if (uClippingPlaneCtrl0.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane0); - fPlaneValue = uClippingPlaneCtrl0.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl1.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane1); - fPlaneValue = uClippingPlaneCtrl1.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl2.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane2); - fPlaneValue = uClippingPlaneCtrl2.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl3.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane3); - fPlaneValue = uClippingPlaneCtrl3.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl4.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane4); - fPlaneValue = uClippingPlaneCtrl4.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl5.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane5); - fPlaneValue = uClippingPlaneCtrl5.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - - vec3 diffuseColor = vColor.rgb; - vec3 specularColor = uSpecularColor.rgb; - vec3 ambientColor = uAmbientColor.rgb; - float transparency = uTransparency; - - vec3 normal = normalize(vNormal); - if (gl_FrontFacing) normal = -normal; - vec3 cameraVector = -normalize(vPosView.xyz); - - gl_FragColor = vec4(ambientColor * diffuseColor, transparency); - if (length(uLightDirectionView0) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView0, cameraVector, diffuseColor, specularColor, uLightColor0); - if (length(uLightDirectionView1) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView1, cameraVector, diffuseColor, specularColor, uLightColor1); - if (length(uLightDirectionView2) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView2, cameraVector, diffuseColor, specularColor, uLightColor2); - if (length(uLightDirectionView3) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView3, cameraVector, diffuseColor, specularColor, uLightColor3); - - //calculate fog - if (uFogSettings.x > 0.0) - { - vec4 fp; - fp.x = uFogSettings.x; - fp.y = uFogSettings.y; - fp.z = uFogSettings.z; - fp.w = abs(vPosView.z/vPosView.w); - - float fog_factor; - fog_factor = (fp.z-fp.w)/(fp.z-fp.y); - fog_factor = 1.0 - clamp(fog_factor, 0.0, 1.0); - fog_factor = 1.0 - exp(-pow(fog_factor*2.5, 2.0)); - gl_FragColor.xyz = mix(clamp(gl_FragColor.xyz, 0.0, 1.0), - clamp(uFogColor.xyz, 0.0, 1.0), fog_factor); - } -} diff --git a/src/Interface/Modules/Render/ES/shaders/DirPhongInSitu.vs b/src/Interface/Modules/Render/ES/shaders/DirPhongInSitu.vs deleted file mode 100644 index c45d65e277..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/DirPhongInSitu.vs +++ /dev/null @@ -1,55 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -// Uniforms -uniform mat4 uViewProjection; -uniform mat4 uModel; -uniform mat4 uView; - -// Attributes -attribute vec3 aPos; -attribute vec3 aNormal; -attribute vec4 aColor; - -// Outputs to the fragment shader. -varying vec3 vNormal; -varying vec4 vColor; -varying vec4 vPosWorld; -varying vec4 vPosView; - -void main( void ) -{ - // Todo: Add gamma correction factor of 2.2. For textures, we assume that it - // was generated in gamma space, and we need to convert it to linear space. - vPosWorld = vec4(aPos, 1.0); - vPosView = uView * vPosWorld; - vNormal = normalize((uView * vec4(aNormal, 0.0)).xyz); - vColor = aColor; - - gl_Position = uViewProjection * vPosWorld; -} diff --git a/src/Interface/Modules/Render/ES/shaders/DirPhongNoClipping.fs b/src/Interface/Modules/Render/ES/shaders/DirPhongNoClipping.fs deleted file mode 100644 index 7c9fb96a18..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/DirPhongNoClipping.fs +++ /dev/null @@ -1,107 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -#ifdef OPENGL_ES - #ifdef GL_FRAGMENT_PRECISION_HIGH - precision highp float; - #else - precision mediump float; - #endif -#endif - -uniform vec3 uCamViewVec; -uniform vec4 uAmbientColor; -uniform vec4 uDiffuseColor; -uniform vec4 uSpecularColor; -uniform float uSpecularPower; -uniform vec3 uLightDirectionView0; -uniform vec3 uLightDirectionView1; -uniform vec3 uLightDirectionView2; -uniform vec3 uLightDirectionView3; -uniform vec3 uLightColor0; -uniform vec3 uLightColor1; -uniform vec3 uLightColor2; -uniform vec3 uLightColor3; -uniform float uTransparency; - -// fog settings (intensity, start, end, 0.0) -uniform vec4 uFogSettings; -uniform vec4 uFogColor; - -varying vec3 vNormal; -varying vec4 vPosWorld; -varying vec4 vPosView; - -vec4 calculate_lighting(vec3 N, vec3 L, vec3 V, vec3 diffuseColor, vec3 specularColor, vec3 lightColor) -{ - vec3 H = normalize(V + L); - float diffuse = max(0.0, dot(N, L)); - float specular = max(0.0, dot(N, H)); - specular = pow(specular, uSpecularPower); - - return vec4(lightColor * (diffuse * diffuseColor + specular * specularColor), 0.0); -} - -void main() -{ - vec3 diffuseColor = uDiffuseColor.rgb; - vec3 specularColor = uSpecularColor.rgb; - vec3 ambientColor = uAmbientColor.rgb; - float transparency = uTransparency; - - vec3 normal = normalize(vNormal); - if (gl_FrontFacing) normal = -normal; - vec3 cameraVector = -normalize(vPosView.xyz); - - gl_FragColor = vec4(ambientColor * diffuseColor, transparency); - if (length(uLightDirectionView0) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView0, cameraVector, diffuseColor, specularColor, uLightColor0); - if (length(uLightDirectionView1) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView1, cameraVector, diffuseColor, specularColor, uLightColor1); - if (length(uLightDirectionView2) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView2, cameraVector, diffuseColor, specularColor, uLightColor2); - if (length(uLightDirectionView3) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView3, cameraVector, diffuseColor, specularColor, uLightColor3); - - //calculate fog - if (uFogSettings.x > 0.0) - { - vec4 fp; - fp.x = uFogSettings.x; - fp.y = uFogSettings.y; - fp.z = uFogSettings.z; - fp.w = abs(vPosView.z/vPosView.w); - - float fog_factor; - fog_factor = (fp.z-fp.w)/(fp.z-fp.y); - fog_factor = 1.0 - clamp(fog_factor, 0.0, 1.0); - fog_factor = 1.0 - exp(-pow(fog_factor*2.5, 2.0)); - gl_FragColor.xyz = mix(clamp(gl_FragColor.xyz, 0.0, 1.0), - clamp(uFogColor.xyz, 0.0, 1.0), fog_factor); - } -} diff --git a/src/Interface/Modules/Render/ES/shaders/Flat_Color.fs b/src/Interface/Modules/Render/ES/shaders/Flat_Color.fs new file mode 100644 index 0000000000..3de310a89d --- /dev/null +++ b/src/Interface/Modules/Render/ES/shaders/Flat_Color.fs @@ -0,0 +1,135 @@ +/* + For more information, please see: http://software.sci.utah.edu + + The MIT License + + Copyright (c) 2015 Scientific Computing and Imaging Institute, + University of Utah. + + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#ifdef OPENGL_ES + #ifdef GL_FRAGMENT_PRECISION_HIGH + precision highp float; + #else + precision mediump float; + #endif +#endif + +uniform bool uUseFog; +uniform bool uUseClippingPlanes; + +uniform float uTransparency; + +uniform vec4 uClippingPlane0; +uniform vec4 uClippingPlane1; +uniform vec4 uClippingPlane2; +uniform vec4 uClippingPlane3; +uniform vec4 uClippingPlane4; +uniform vec4 uClippingPlane5; + +// clipping plane controls (visible, showFrame, reverseNormal, 0) +uniform vec4 uClippingPlaneCtrl0; +uniform vec4 uClippingPlaneCtrl1; +uniform vec4 uClippingPlaneCtrl2; +uniform vec4 uClippingPlaneCtrl3; +uniform vec4 uClippingPlaneCtrl4; +uniform vec4 uClippingPlaneCtrl5; + +// fog settings (intensity, start, end, 0.0) +uniform vec4 uFogSettings; +uniform vec4 uFogColor; + +varying vec4 vPosWorld; +varying vec4 vPosView; +varying vec4 vColor; + +void main() +{ + if(uUseClippingPlanes) + { + float fPlaneValue; + if (uClippingPlaneCtrl0.x > 0.5) + { + fPlaneValue = dot(vPosWorld, uClippingPlane0); + fPlaneValue = uClippingPlaneCtrl0.z > 0.5 ? -fPlaneValue : fPlaneValue; + if (fPlaneValue < 0.0) + discard; + } + if (uClippingPlaneCtrl1.x > 0.5) + { + fPlaneValue = dot(vPosWorld, uClippingPlane1); + fPlaneValue = uClippingPlaneCtrl1.z > 0.5 ? -fPlaneValue : fPlaneValue; + if (fPlaneValue < 0.0) + discard; + } + if (uClippingPlaneCtrl2.x > 0.5) + { + fPlaneValue = dot(vPosWorld, uClippingPlane2); + fPlaneValue = uClippingPlaneCtrl2.z > 0.5 ? -fPlaneValue : fPlaneValue; + if (fPlaneValue < 0.0) + discard; + } + if (uClippingPlaneCtrl3.x > 0.5) + { + fPlaneValue = dot(vPosWorld, uClippingPlane3); + fPlaneValue = uClippingPlaneCtrl3.z > 0.5 ? -fPlaneValue : fPlaneValue; + if (fPlaneValue < 0.0) + discard; + } + if (uClippingPlaneCtrl4.x > 0.5) + { + fPlaneValue = dot(vPosWorld, uClippingPlane4); + fPlaneValue = uClippingPlaneCtrl4.z > 0.5 ? -fPlaneValue : fPlaneValue; + if (fPlaneValue < 0.0) + discard; + } + if (uClippingPlaneCtrl5.x > 0.5) + { + fPlaneValue = dot(vPosWorld, uClippingPlane5); + fPlaneValue = uClippingPlaneCtrl5.z > 0.5 ? -fPlaneValue : fPlaneValue; + if (fPlaneValue < 0.0) + discard; + } + } + + vec3 diffuseColor = vColor.rgb; + float transparency = uTransparency; //change to vColor.a when we support for glyph tranparency + + gl_FragColor = vec4(diffuseColor, transparency); + + //calculate fog + if (uUseFog && uFogSettings.x > 0.0) + { + vec4 fp; + fp.x = uFogSettings.x; + fp.y = uFogSettings.y; + fp.z = uFogSettings.z; + fp.w = abs(vPosView.z/vPosView.w); + + float fog_factor; + fog_factor = (fp.z-fp.w)/(fp.z-fp.y); + fog_factor = 1.0 - clamp(fog_factor, 0.0, 1.0); + fog_factor = 1.0 - exp(-pow(fog_factor*2.5, 2.0)); + gl_FragColor.xyz = mix(clamp(gl_FragColor.xyz, 0.0, 1.0), + clamp(uFogColor.xyz, 0.0, 1.0), fog_factor); + } +} diff --git a/src/Interface/Modules/Render/ES/shaders/DirPhong.vs b/src/Interface/Modules/Render/ES/shaders/Flat_Color.vs similarity index 92% rename from src/Interface/Modules/Render/ES/shaders/DirPhong.vs rename to src/Interface/Modules/Render/ES/shaders/Flat_Color.vs index f00fe841a9..f03dabfd43 100644 --- a/src/Interface/Modules/Render/ES/shaders/DirPhong.vs +++ b/src/Interface/Modules/Render/ES/shaders/Flat_Color.vs @@ -33,20 +33,20 @@ uniform mat4 uView; // Attributes attribute vec3 aPos; -attribute vec3 aNormal; +attribute vec4 aColor; // Outputs to the fragment shader. -varying vec3 vNormal; varying vec4 vPosWorld; varying vec4 vPosView; +varying vec4 vColor; void main( void ) { // Todo: Add gamma correction factor of 2.2. For textures, we assume that it // was generated in gamma space, and we need to convert it to linear space. vPosWorld = uModel * vec4(aPos, 1.0); - vPosView = uView * vPosWorld; - vNormal = normalize((uView * uModel * vec4(aNormal, 0.0)).xyz); + vPosView = uView * uModel * vPosWorld; + vColor = aColor; gl_Position = uModelViewProjection * vec4(aPos, 1.0); } diff --git a/src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.vs b/src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.vs index 238ade32bc..3d9dacc1c8 100644 --- a/src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.vs +++ b/src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.vs @@ -25,7 +25,6 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#define COLOR_MAP // Uniforms uniform mat4 uModelViewProjection; diff --git a/src/Interface/Modules/Render/ES/shaders/InSituColor.fs b/src/Interface/Modules/Render/ES/shaders/InSituColor.fs deleted file mode 100644 index d017abd07f..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/InSituColor.fs +++ /dev/null @@ -1,126 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ -#ifdef OPENGL_ES - #ifdef GL_FRAGMENT_PRECISION_HIGH - // Default precision - precision highp float; - #else - precision mediump float; - #endif -#endif - -varying vec4 fColor; -varying vec4 vPosWorld;//for clipping plane calc -varying vec4 vPosView;// for fog calculation - -uniform float uTransparency; - -//clipping planes -uniform vec4 uClippingPlane0; // clipping plane 0 -uniform vec4 uClippingPlane1; // clipping plane 1 -uniform vec4 uClippingPlane2; // clipping plane 2 -uniform vec4 uClippingPlane3; // clipping plane 3 -uniform vec4 uClippingPlane4; // clipping plane 4 -uniform vec4 uClippingPlane5; // clipping plane 5 -//clipping plane controls -uniform vec4 uClippingPlaneCtrl0;// clipping plane 0 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl1;// clipping plane 1 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl2;// clipping plane 2 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl3;// clipping plane 3 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl4;// clipping plane 4 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl5;// clipping plane 5 control (visible, showFrame, reverseNormal, 0) - -//fog -uniform vec4 uFogSettings; // fog settings (intensity, start, end, 0.0) -uniform vec4 uFogColor; // fog color - -void main() -{ - float fPlaneValue; - if (uClippingPlaneCtrl0.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane0); - fPlaneValue = uClippingPlaneCtrl0.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl1.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane1); - fPlaneValue = uClippingPlaneCtrl1.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl2.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane2); - fPlaneValue = uClippingPlaneCtrl2.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl3.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane3); - fPlaneValue = uClippingPlaneCtrl3.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl4.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane4); - fPlaneValue = uClippingPlaneCtrl4.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl5.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane5); - fPlaneValue = uClippingPlaneCtrl5.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - - gl_FragColor = vec4(fColor.xyz,uTransparency); - - //calculate fog - if (uFogSettings.x > 0.0) - { - vec4 fp; - fp.x = uFogSettings.x; - fp.y = uFogSettings.y; - fp.z = uFogSettings.z; - fp.w = abs(vPosView.z/vPosView.w); - - float fog_factor; - fog_factor = (fp.z-fp.w)/(fp.z-fp.y); - fog_factor = 1.0 - clamp(fog_factor, 0.0, 1.0); - fog_factor = 1.0 - exp(-pow(fog_factor*2.5, 2.0)); - gl_FragColor.xyz = mix(clamp(gl_FragColor.xyz, 0.0, 1.0), - clamp(uFogColor.xyz, 0.0, 1.0), fog_factor); - } -} diff --git a/src/Interface/Modules/Render/ES/shaders/InSituColor.vs b/src/Interface/Modules/Render/ES/shaders/InSituColor.vs deleted file mode 100644 index 89ce2d9c37..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/InSituColor.vs +++ /dev/null @@ -1,48 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -// Uniforms -uniform mat4 uModelViewProjection; -uniform mat4 uView; - -// Attributes -attribute vec3 aPos; -attribute vec4 aColor; - -// Outputs to the fragment shader. -varying vec4 fColor; -varying vec4 vPosWorld;//for clipping plane calc -varying vec4 vPosView;// for fog calculation - -void main( void ) -{ - gl_Position = uModelViewProjection * vec4(aPos, 1.0); - fColor = aColor; - vPosWorld = vec4(aPos, 1.0); - vPosView = uView * vPosWorld; -} diff --git a/src/Interface/Modules/Render/ES/shaders/DirPhong.fs b/src/Interface/Modules/Render/ES/shaders/Phong_Color.fs similarity index 73% rename from src/Interface/Modules/Render/ES/shaders/DirPhong.fs rename to src/Interface/Modules/Render/ES/shaders/Phong_Color.fs index 91edd4b1f2..e554c2920b 100644 --- a/src/Interface/Modules/Render/ES/shaders/DirPhong.fs +++ b/src/Interface/Modules/Render/ES/shaders/Phong_Color.fs @@ -34,6 +34,9 @@ #endif #endif +uniform bool uUseFog; +uniform bool uUseClippingPlanes; + uniform vec4 uAmbientColor; uniform vec4 uDiffuseColor; uniform vec4 uSpecularColor; @@ -70,6 +73,7 @@ uniform vec4 uFogColor; varying vec3 vNormal; varying vec4 vPosWorld; varying vec4 vPosView; +varying vec4 vColor; vec4 calculate_lighting(vec3 N, vec3 L, vec3 V, vec3 diffuseColor, vec3 specularColor, vec3 lightColor) { @@ -83,51 +87,54 @@ vec4 calculate_lighting(vec3 N, vec3 L, vec3 V, vec3 diffuseColor, vec3 specular void main() { - float fPlaneValue; - if (uClippingPlaneCtrl0.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane0); - fPlaneValue = uClippingPlaneCtrl0.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl1.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane1); - fPlaneValue = uClippingPlaneCtrl1.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl2.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane2); - fPlaneValue = uClippingPlaneCtrl2.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl3.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane3); - fPlaneValue = uClippingPlaneCtrl3.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl4.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane4); - fPlaneValue = uClippingPlaneCtrl4.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl5.x > 0.5) + if(uUseClippingPlanes) { - fPlaneValue = dot(vPosWorld, uClippingPlane5); - fPlaneValue = uClippingPlaneCtrl5.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + float fPlaneValue; + if (uClippingPlaneCtrl0.x > 0.5) + { + fPlaneValue = dot(vPosWorld, uClippingPlane0); + fPlaneValue = uClippingPlaneCtrl0.z > 0.5 ? -fPlaneValue : fPlaneValue; + if (fPlaneValue < 0.0) + discard; + } + if (uClippingPlaneCtrl1.x > 0.5) + { + fPlaneValue = dot(vPosWorld, uClippingPlane1); + fPlaneValue = uClippingPlaneCtrl1.z > 0.5 ? -fPlaneValue : fPlaneValue; + if (fPlaneValue < 0.0) + discard; + } + if (uClippingPlaneCtrl2.x > 0.5) + { + fPlaneValue = dot(vPosWorld, uClippingPlane2); + fPlaneValue = uClippingPlaneCtrl2.z > 0.5 ? -fPlaneValue : fPlaneValue; + if (fPlaneValue < 0.0) + discard; + } + if (uClippingPlaneCtrl3.x > 0.5) + { + fPlaneValue = dot(vPosWorld, uClippingPlane3); + fPlaneValue = uClippingPlaneCtrl3.z > 0.5 ? -fPlaneValue : fPlaneValue; + if (fPlaneValue < 0.0) + discard; + } + if (uClippingPlaneCtrl4.x > 0.5) + { + fPlaneValue = dot(vPosWorld, uClippingPlane4); + fPlaneValue = uClippingPlaneCtrl4.z > 0.5 ? -fPlaneValue : fPlaneValue; + if (fPlaneValue < 0.0) + discard; + } + if (uClippingPlaneCtrl5.x > 0.5) + { + fPlaneValue = dot(vPosWorld, uClippingPlane5); + fPlaneValue = uClippingPlaneCtrl5.z > 0.5 ? -fPlaneValue : fPlaneValue; + if (fPlaneValue < 0.0) + discard; + } } - vec3 diffuseColor = uDiffuseColor.rgb; + vec3 diffuseColor = vColor.rgb; vec3 specularColor = uSpecularColor.rgb; vec3 ambientColor = uAmbientColor.rgb; float transparency = uTransparency; @@ -147,7 +154,7 @@ void main() gl_FragColor += calculate_lighting(normal, uLightDirectionView3, cameraVector, diffuseColor, specularColor, uLightColor3); //calculate fog - if (uFogSettings.x > 0.0) + if (uUseFog && uFogSettings.x > 0.0) { vec4 fp; fp.x = uFogSettings.x; diff --git a/src/Interface/Modules/Render/ES/shaders/DirPhongNoClipping.vs b/src/Interface/Modules/Render/ES/shaders/Phong_Color.vs similarity index 93% rename from src/Interface/Modules/Render/ES/shaders/DirPhongNoClipping.vs rename to src/Interface/Modules/Render/ES/shaders/Phong_Color.vs index f00fe841a9..d6f5a5b477 100644 --- a/src/Interface/Modules/Render/ES/shaders/DirPhongNoClipping.vs +++ b/src/Interface/Modules/Render/ES/shaders/Phong_Color.vs @@ -34,11 +34,13 @@ uniform mat4 uView; // Attributes attribute vec3 aPos; attribute vec3 aNormal; +attribute vec4 aColor; // Outputs to the fragment shader. varying vec3 vNormal; varying vec4 vPosWorld; varying vec4 vPosView; +varying vec4 vColor; void main( void ) { @@ -46,7 +48,8 @@ void main( void ) // was generated in gamma space, and we need to convert it to linear space. vPosWorld = uModel * vec4(aPos, 1.0); vPosView = uView * vPosWorld; - vNormal = normalize((uView * uModel * vec4(aNormal, 0.0)).xyz); + vNormal = normalize((uView * vec4(aNormal, 0.0)).xyz); + vColor = aColor; gl_Position = uModelViewProjection * vec4(aPos, 1.0); } diff --git a/src/Interface/Modules/Render/ES/shaders/UniformColor.fs b/src/Interface/Modules/Render/ES/shaders/UniformColor.fs deleted file mode 100644 index dca5881e65..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/UniformColor.fs +++ /dev/null @@ -1,126 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ -#ifdef OPENGL_ES - #ifdef GL_FRAGMENT_PRECISION_HIGH - // Default precision - precision highp float; - #else - precision mediump float; - #endif -#endif - -uniform float uTransparency; - -//clipping planes -uniform vec4 uClippingPlane0; // clipping plane 0 -uniform vec4 uClippingPlane1; // clipping plane 1 -uniform vec4 uClippingPlane2; // clipping plane 2 -uniform vec4 uClippingPlane3; // clipping plane 3 -uniform vec4 uClippingPlane4; // clipping plane 4 -uniform vec4 uClippingPlane5; // clipping plane 5 -//clipping plane controls -uniform vec4 uClippingPlaneCtrl0;// clipping plane 0 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl1;// clipping plane 1 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl2;// clipping plane 2 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl3;// clipping plane 3 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl4;// clipping plane 4 control (visible, showFrame, reverseNormal, 0) -uniform vec4 uClippingPlaneCtrl5;// clipping plane 5 control (visible, showFrame, reverseNormal, 0) - -//fog -uniform vec4 uFogSettings; // fog settings (intensity, start, end, 0.0) -uniform vec4 uFogColor; // fog color - -varying vec4 fColor; -varying vec4 vPosWorld;//for clipping plane calc -varying vec4 vPosView;// for fog calculation - -void main() -{ - float fPlaneValue; - if (uClippingPlaneCtrl0.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane0); - fPlaneValue = uClippingPlaneCtrl0.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl1.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane1); - fPlaneValue = uClippingPlaneCtrl1.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl2.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane2); - fPlaneValue = uClippingPlaneCtrl2.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl3.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane3); - fPlaneValue = uClippingPlaneCtrl3.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl4.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane4); - fPlaneValue = uClippingPlaneCtrl4.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - if (uClippingPlaneCtrl5.x > 0.5) - { - fPlaneValue = dot(vPosWorld, uClippingPlane5); - fPlaneValue = uClippingPlaneCtrl5.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; - } - - gl_FragColor = vec4(fColor.xyz,uTransparency); - - //calculate fog - if (uFogSettings.x > 0.0) - { - vec4 fp; - fp.x = uFogSettings.x; - fp.y = uFogSettings.y; - fp.z = uFogSettings.z; - fp.w = abs(vPosView.z/vPosView.w); - - float fog_factor; - fog_factor = (fp.z-fp.w)/(fp.z-fp.y); - fog_factor = 1.0 - clamp(fog_factor, 0.0, 1.0); - fog_factor = 1.0 - exp(-pow(fog_factor*2.5, 2.0)); - gl_FragColor.xyz = mix(clamp(gl_FragColor.xyz, 0.0, 1.0), - clamp(uFogColor.xyz, 0.0, 1.0), fog_factor); - } -} diff --git a/src/Interface/Modules/Render/ES/shaders/UniformColor.vs b/src/Interface/Modules/Render/ES/shaders/UniformColor.vs deleted file mode 100644 index bb40ba408c..0000000000 --- a/src/Interface/Modules/Render/ES/shaders/UniformColor.vs +++ /dev/null @@ -1,48 +0,0 @@ -/* - For more information, please see: http://software.sci.utah.edu - - The MIT License - - Copyright (c) 2015 Scientific Computing and Imaging Institute, - University of Utah. - - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -// Uniforms -uniform mat4 uModelViewProjection; -uniform vec4 uColor; // Uniform color -uniform mat4 uView; - -// Attributes -attribute vec3 aPos; - -// Outputs to the fragment shader. -varying vec4 fColor; -varying vec4 vPosWorld;//for clipping plane calc -varying vec4 vPosView;// for fog calculation - -void main( void ) -{ - gl_Position = uModelViewProjection * vec4(aPos, 1.0); - fColor = uColor; - vPosWorld = vec4(aPos, 1.0); - vPosView = uView * vPosWorld; -} From aa2445dc83cbfde438fb06ad4e9da5fa6041d465 Mon Sep 17 00:00:00 2001 From: Haydelj Date: Fri, 6 Sep 2019 15:22:18 -0600 Subject: [PATCH 02/10] added texture mapping to edges --- src/Graphics/Glyphs/GlyphGeom.cc | 60 +++++++++++++++++++++----- src/Graphics/Glyphs/GlyphGeom.h | 2 +- src/Modules/Visualization/ShowField.cc | 29 ++++++++++--- 3 files changed, 72 insertions(+), 19 deletions(-) diff --git a/src/Graphics/Glyphs/GlyphGeom.cc b/src/Graphics/Glyphs/GlyphGeom.cc index d60a8bd517..4db06c03cc 100644 --- a/src/Graphics/Glyphs/GlyphGeom.cc +++ b/src/Graphics/Glyphs/GlyphGeom.cc @@ -28,6 +28,7 @@ DEALINGS IN THE SOFTWARE. #include #include +#include #include #include @@ -43,7 +44,7 @@ GlyphGeom::GlyphGeom() : numVBOElements_(0), lineIndex_(0) } void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& uniqueNodeID, const bool isTransparent, const double transparencyValue, - const ColorScheme& colorScheme, RenderState state, const SpireIBO::PRIMITIVE& primIn, const BBox& bbox) + const ColorScheme& colorScheme, RenderState state, const SpireIBO::PRIMITIVE& primIn, const BBox& bbox, const Core::Datatypes::ColorMapHandle colorMap) { std::string vboName = uniqueNodeID + "VBO"; std::string iboName = uniqueNodeID + "IBO"; @@ -52,6 +53,7 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique bool useTriangles = primIn == SpireIBO::PRIMITIVE::TRIANGLES; bool useColor = colorScheme == ColorScheme::COLOR_IN_SITU || colorScheme == ColorScheme::COLOR_MAP; bool useNormals = normals_.size() == points_.size(); + int numAttributes = 3; RenderType renderType = RenderType::RENDER_VBO_IBO; ColorRGB dft = state.defaultColor; @@ -61,9 +63,12 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique std::vector uniforms; attribs.push_back(SpireVBO::AttributeData("aPos", 3 * sizeof(float))); + uniforms.push_back(SpireSubPass::Uniform("uUseClippingPlanes", true)); + uniforms.push_back(SpireSubPass::Uniform("uUseFog", true)); if (useNormals) { + numAttributes += 3; attribs.push_back(SpireVBO::AttributeData("aNormal", 3 * sizeof(float))); uniforms.push_back(SpireSubPass::Uniform("uAmbientColor", glm::vec4(0.1f, 0.1f, 0.1f, 1.0f))); uniforms.push_back(SpireSubPass::Uniform("uSpecularColor", glm::vec4(0.1f, 0.1f, 0.1f, 0.1f))); @@ -72,8 +77,18 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique if (useColor) { - shader += "_Color"; - attribs.push_back(SpireVBO::AttributeData("aColor", 4 * sizeof(float))); + if(colorMap) + { + numAttributes += 2; + shader += "_ColorMap"; + attribs.push_back(SpireVBO::AttributeData("aTexCoords", 2 * sizeof(float))); + } + else + { + numAttributes += 4; + shader += "_Color"; + attribs.push_back(SpireVBO::AttributeData("aColor", 4 * sizeof(float))); + } } else { @@ -83,9 +98,7 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique if (isTransparent) uniforms.push_back(SpireSubPass::Uniform("uTransparency", static_cast(transparencyValue))); - size_t vboSize = static_cast(points_.size()) * 3 * sizeof(float); - if (useNormals) vboSize += static_cast(normals_.size()) * 3 * sizeof(float); - if (useColor) vboSize += static_cast(colors_.size()) * 4 * sizeof(float); //RGBA + size_t vboSize = static_cast(points_.size()) * numAttributes * sizeof(float); size_t iboSize = static_cast(indices_.size()) * sizeof(uint32_t); std::shared_ptr iboBufferSPtr(new spire::VarBuffer(iboSize)); std::shared_ptr vboBufferSPtr(new spire::VarBuffer(vboSize)); @@ -113,10 +126,18 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique if (useColor) { - vboBuffer->write(static_cast(colors_.at(i).r())); - vboBuffer->write(static_cast(colors_.at(i).g())); - vboBuffer->write(static_cast(colors_.at(i).b())); - vboBuffer->write(static_cast(colors_.at(i).a())); + if(!colorMap) + { + vboBuffer->write(static_cast(colors_.at(i).r())); + vboBuffer->write(static_cast(colors_.at(i).g())); + vboBuffer->write(static_cast(colors_.at(i).b())); + vboBuffer->write(static_cast(colors_.at(i).a())); + } + else + { + vboBuffer->write(static_cast(colors_.at(i).r())); + vboBuffer->write(static_cast(colors_.at(i).r())); + } } } if(!bbox.valid()) newBBox.reset(); @@ -127,8 +148,25 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique state.set(RenderState::IS_ON, true); state.set(RenderState::HAS_DATA, true); + SpireTexture2D texture; + if (colorMap) + { + const static int colorMapResolution = 256; + for(int i = 0; i < colorMapResolution; ++i) + { + ColorRGB color = colorMap->valueToColor(static_cast(i)/colorMapResolution * 2.0 - 1.0); + texture.bitmap.push_back(color.r()*255); + texture.bitmap.push_back(color.g()*255); + texture.bitmap.push_back(color.b()*255); + texture.bitmap.push_back(255); + } + texture.name = "ColorMap"; + texture.height = 1; + texture.width = colorMapResolution; + } + SpireText text; - SpireSubPass pass(passName, vboName, iboName, shader, colorScheme, state, renderType, geomVBO, geomIBO, text); + SpireSubPass pass(passName, vboName, iboName, shader, colorScheme, state, renderType, geomVBO, geomIBO, text, texture); for (const auto& uniform : uniforms) { pass.addUniform(uniform); } diff --git a/src/Graphics/Glyphs/GlyphGeom.h b/src/Graphics/Glyphs/GlyphGeom.h index 866cd47f81..9c050fb7ff 100644 --- a/src/Graphics/Glyphs/GlyphGeom.h +++ b/src/Graphics/Glyphs/GlyphGeom.h @@ -51,7 +51,7 @@ namespace SCIRun { void buildObject(Datatypes::GeometryObjectSpire& geom, const std::string& uniqueNodeID, const bool isTransparent, const double transparencyValue, const Datatypes::ColorScheme& colorScheme, RenderState state, - const Datatypes::SpireIBO::PRIMITIVE& primIn, const Core::Geometry::BBox& bbox); + const Datatypes::SpireIBO::PRIMITIVE& primIn, const Core::Geometry::BBox& bbox, const Core::Datatypes::ColorMapHandle colorMap = nullptr); void addArrow(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius, double ratio, int resolution, const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2, bool render_cylinder_base, bool render_cone_base); diff --git a/src/Modules/Visualization/ShowField.cc b/src/Modules/Visualization/ShowField.cc index 6601ea89cb..875248b70a 100644 --- a/src/Modules/Visualization/ShowField.cc +++ b/src/Modules/Visualization/ShowField.cc @@ -926,6 +926,13 @@ void GeometryBuilder::renderEdges( ColorScheme colorScheme; ColorRGB edge_colors[2]; + ColorMapHandle realColorMap = nullptr; + if(colorMap) realColorMap = colorMap.get(); + if(!realColorMap) realColorMap = StandardColorMapFactory::create(); + + auto coordinateMap = StandardColorMapFactory::create("Grayscale", 256, 0, false, + realColorMap->getColorMapRescaleScale(), realColorMap->getColorMapRescaleShift()); + if (fld->basis_order() < 0 || (fld->basis_order() == 0 && mesh->dimensionality() != 0) || state.get(RenderState::USE_DEFAULT_COLOR_EDGES)) @@ -984,8 +991,8 @@ void GeometryBuilder::renderEdges( sval1 = sval0; } - edge_colors[0] = map->valueToColor(sval0); - edge_colors[1] = map->valueToColor(sval1); + edge_colors[0] = coordinateMap->valueToColor(sval0); + edge_colors[1] = coordinateMap->valueToColor(sval1); } else if (fld->is_vector()) { @@ -1000,8 +1007,8 @@ void GeometryBuilder::renderEdges( vval1 = vval0; } - edge_colors[0] = map->valueToColor(vval0); - edge_colors[1] = map->valueToColor(vval1); + edge_colors[0] = coordinateMap->valueToColor(vval0); + edge_colors[1] = coordinateMap->valueToColor(vval1); } else if (fld->is_tensor()) { @@ -1016,8 +1023,8 @@ void GeometryBuilder::renderEdges( tval1 = tval0; } - edge_colors[0] = map->valueToColor(tval0); - edge_colors[1] = map->valueToColor(tval1); + edge_colors[0] = coordinateMap->valueToColor(tval0); + edge_colors[1] = coordinateMap->valueToColor(tval1); } } //accumulate VBO or IBO data @@ -1039,8 +1046,16 @@ void GeometryBuilder::renderEdges( ++eiter; } + ColorMapHandle map = nullptr; + if(realColorMap) + { + map = StandardColorMapFactory::create(realColorMap->getColorMapName(), + realColorMap->getColorMapResolution(), realColorMap->getColorMapShift(), + realColorMap->getColorMapInvert()); + } + glyphs.buildObject(*geom, uniqueNodeID, state.get(RenderState::USE_TRANSPARENT_EDGES), edgeTransparencyValue_, - colorScheme, state, primIn, mesh->get_bounding_box()); + colorScheme, state, primIn, mesh->get_bounding_box(), map); } void ShowField::updateAvailableRenderOptions(FieldHandle field) From 546eacfc857b1b90696396ed9a68e00c8f0fd23b Mon Sep 17 00:00:00 2001 From: Haydelj Date: Sat, 7 Sep 2019 17:47:46 -0600 Subject: [PATCH 03/10] added vbo splitting to the glyph geom class --- src/Graphics/Glyphs/GlyphGeom.cc | 140 +++++++++++++++++-------------- src/Graphics/Glyphs/GlyphGeom.h | 6 +- 2 files changed, 79 insertions(+), 67 deletions(-) diff --git a/src/Graphics/Glyphs/GlyphGeom.cc b/src/Graphics/Glyphs/GlyphGeom.cc index 4db06c03cc..7702b138f3 100644 --- a/src/Graphics/Glyphs/GlyphGeom.cc +++ b/src/Graphics/Glyphs/GlyphGeom.cc @@ -46,11 +46,6 @@ GlyphGeom::GlyphGeom() : numVBOElements_(0), lineIndex_(0) void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& uniqueNodeID, const bool isTransparent, const double transparencyValue, const ColorScheme& colorScheme, RenderState state, const SpireIBO::PRIMITIVE& primIn, const BBox& bbox, const Core::Datatypes::ColorMapHandle colorMap) { - std::string vboName = uniqueNodeID + "VBO"; - std::string iboName = uniqueNodeID + "IBO"; - std::string passName = uniqueNodeID + "Pass"; - - bool useTriangles = primIn == SpireIBO::PRIMITIVE::TRIANGLES; bool useColor = colorScheme == ColorScheme::COLOR_IN_SITU || colorScheme == ColorScheme::COLOR_MAP; bool useNormals = normals_.size() == points_.size(); int numAttributes = 3; @@ -98,81 +93,98 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique if (isTransparent) uniforms.push_back(SpireSubPass::Uniform("uTransparency", static_cast(transparencyValue))); - size_t vboSize = static_cast(points_.size()) * numAttributes * sizeof(float); - size_t iboSize = static_cast(indices_.size()) * sizeof(uint32_t); - std::shared_ptr iboBufferSPtr(new spire::VarBuffer(iboSize)); - std::shared_ptr vboBufferSPtr(new spire::VarBuffer(vboSize)); - auto iboBuffer = iboBufferSPtr.get(); - auto vboBuffer = vboBufferSPtr.get(); - - //write to the IBO/VBOs - for (auto a : indices_) - iboBuffer->write(a); - - BBox newBBox; - for (size_t i = 0; i < points_.size(); i++) + size_t pointsLeft = points_.size(); + size_t startOfPass = 0; + int passNumber = 0; + while(pointsLeft > 0) { - newBBox.extend(Point(points_.at(i).x(), points_.at(i).y(), points_.at(i).z())); - vboBuffer->write(static_cast(points_.at(i).x())); - vboBuffer->write(static_cast(points_.at(i).y())); - vboBuffer->write(static_cast(points_.at(i).z())); - - if (useNormals) + std::string passID = uniqueNodeID + "_" + std::to_string(passNumber++); + std::string vboName = passID + "VBO"; + std::string iboName = passID + "IBO"; + std::string passName = passID + "Pass"; + + const static size_t maxPointsPerPass = 3 << 24; + uint32_t pointsInThisPass = std::min(pointsLeft, maxPointsPerPass); + size_t endOfPass = startOfPass + pointsInThisPass; + pointsLeft -= pointsInThisPass; + + size_t vboSize = static_cast(pointsInThisPass) * numAttributes * sizeof(float); + size_t iboSize = static_cast(pointsInThisPass) * sizeof(uint32_t); + std::shared_ptr iboBufferSPtr(new spire::VarBuffer(iboSize)); + std::shared_ptr vboBufferSPtr(new spire::VarBuffer(vboSize)); + auto iboBuffer = iboBufferSPtr.get(); + auto vboBuffer = vboBufferSPtr.get(); + + for (auto a : indices_) if(a >= startOfPass && a < endOfPass) + iboBuffer->write(static_cast(a - startOfPass)); + + BBox newBBox; + for (size_t i = startOfPass; i < endOfPass; ++i) { - vboBuffer->write(static_cast(normals_.at(i).x())); - vboBuffer->write(static_cast(normals_.at(i).y())); - vboBuffer->write(static_cast(normals_.at(i).z())); - } + newBBox.extend(Point(points_.at(i).x(), points_.at(i).y(), points_.at(i).z())); + vboBuffer->write(static_cast(points_.at(i).x())); + vboBuffer->write(static_cast(points_.at(i).y())); + vboBuffer->write(static_cast(points_.at(i).z())); - if (useColor) - { - if(!colorMap) + if (useNormals) { - vboBuffer->write(static_cast(colors_.at(i).r())); - vboBuffer->write(static_cast(colors_.at(i).g())); - vboBuffer->write(static_cast(colors_.at(i).b())); - vboBuffer->write(static_cast(colors_.at(i).a())); + vboBuffer->write(static_cast(normals_.at(i).x())); + vboBuffer->write(static_cast(normals_.at(i).y())); + vboBuffer->write(static_cast(normals_.at(i).z())); } - else + + if (useColor) { - vboBuffer->write(static_cast(colors_.at(i).r())); - vboBuffer->write(static_cast(colors_.at(i).r())); + if(!colorMap) + { + vboBuffer->write(static_cast(colors_.at(i).r())); + vboBuffer->write(static_cast(colors_.at(i).g())); + vboBuffer->write(static_cast(colors_.at(i).b())); + vboBuffer->write(static_cast(colors_.at(i).a())); + } + else + { + vboBuffer->write(static_cast(colors_.at(i).r())); + vboBuffer->write(static_cast(colors_.at(i).r())); + } } } - } - if(!bbox.valid()) newBBox.reset(); + if(!bbox.valid()) newBBox.reset(); - SpireVBO geomVBO(vboName, attribs, vboBufferSPtr, numVBOElements_, newBBox, true); - SpireIBO geomIBO(iboName, primIn, sizeof(uint32_t), iboBufferSPtr); + startOfPass = endOfPass; - state.set(RenderState::IS_ON, true); - state.set(RenderState::HAS_DATA, true); + SpireVBO geomVBO(vboName, attribs, vboBufferSPtr, numVBOElements_, newBBox, true); + SpireIBO geomIBO(iboName, primIn, sizeof(uint32_t), iboBufferSPtr); - SpireTexture2D texture; - if (colorMap) - { - const static int colorMapResolution = 256; - for(int i = 0; i < colorMapResolution; ++i) + state.set(RenderState::IS_ON, true); + state.set(RenderState::HAS_DATA, true); + + SpireTexture2D texture; + if (colorMap) { - ColorRGB color = colorMap->valueToColor(static_cast(i)/colorMapResolution * 2.0 - 1.0); - texture.bitmap.push_back(color.r()*255); - texture.bitmap.push_back(color.g()*255); - texture.bitmap.push_back(color.b()*255); - texture.bitmap.push_back(255); + const static int colorMapResolution = 256; + for(int i = 0; i < colorMapResolution; ++i) + { + ColorRGB color = colorMap->valueToColor(static_cast(i)/colorMapResolution * 2.0 - 1.0); + texture.bitmap.push_back(color.r()*255); + texture.bitmap.push_back(color.g()*255); + texture.bitmap.push_back(color.b()*255); + texture.bitmap.push_back(255); + } + texture.name = "ColorMap"; + texture.height = 1; + texture.width = colorMapResolution; } - texture.name = "ColorMap"; - texture.height = 1; - texture.width = colorMapResolution; - } - SpireText text; - SpireSubPass pass(passName, vboName, iboName, shader, colorScheme, state, renderType, geomVBO, geomIBO, text, texture); + SpireText text; + SpireSubPass pass(passName, vboName, iboName, shader, colorScheme, state, renderType, geomVBO, geomIBO, text, texture); - for (const auto& uniform : uniforms) { pass.addUniform(uniform); } + for (const auto& uniform : uniforms) pass.addUniform(uniform); - geom.vbos().push_back(geomVBO); - geom.ibos().push_back(geomIBO); - geom.passes().push_back(pass); + geom.vbos().push_back(geomVBO); + geom.ibos().push_back(geomIBO); + geom.passes().push_back(pass); + } } void GlyphGeom::addArrow(const Point& p1, const Point& p2, double radius, double ratio, int resolution, diff --git a/src/Graphics/Glyphs/GlyphGeom.h b/src/Graphics/Glyphs/GlyphGeom.h index 9c050fb7ff..e0991af4ae 100644 --- a/src/Graphics/Glyphs/GlyphGeom.h +++ b/src/Graphics/Glyphs/GlyphGeom.h @@ -102,9 +102,9 @@ namespace SCIRun { std::vector points_; std::vector normals_; std::vector colors_; - std::vector indices_; - int64_t numVBOElements_; - uint32_t lineIndex_; + std::vector indices_; + size_t numVBOElements_; + size_t lineIndex_; void generateCylinder(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius1, double radius2, int resolution, const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2); void generateSphere(const Core::Geometry::Point& center, double radius, int resolution, const Core::Datatypes::ColorRGB& color); From 833d275060663a95d7f22d240f32b0309bee3dac Mon Sep 17 00:00:00 2001 From: Haydelj Date: Mon, 9 Sep 2019 14:27:18 -0600 Subject: [PATCH 04/10] fixed clippign planes --- src/Graphics/Glyphs/GlyphGeom.cc | 10 ++++++---- src/Graphics/Glyphs/GlyphGeom.h | 2 +- src/Interface/Modules/Render/ViewScene.cc | 4 ++-- src/Modules/Visualization/ShowField.cc | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Graphics/Glyphs/GlyphGeom.cc b/src/Graphics/Glyphs/GlyphGeom.cc index 7702b138f3..f12dcd3f52 100644 --- a/src/Graphics/Glyphs/GlyphGeom.cc +++ b/src/Graphics/Glyphs/GlyphGeom.cc @@ -43,8 +43,10 @@ GlyphGeom::GlyphGeom() : numVBOElements_(0), lineIndex_(0) } -void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& uniqueNodeID, const bool isTransparent, const double transparencyValue, - const ColorScheme& colorScheme, RenderState state, const SpireIBO::PRIMITIVE& primIn, const BBox& bbox, const Core::Datatypes::ColorMapHandle colorMap) +void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& uniqueNodeID, + const bool isTransparent, const double transparencyValue, const ColorScheme& colorScheme, + RenderState state, const SpireIBO::PRIMITIVE& primIn, const BBox& bbox, const bool isClippable, + const Core::Datatypes::ColorMapHandle colorMap) { bool useColor = colorScheme == ColorScheme::COLOR_IN_SITU || colorScheme == ColorScheme::COLOR_MAP; bool useNormals = normals_.size() == points_.size(); @@ -58,7 +60,7 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique std::vector uniforms; attribs.push_back(SpireVBO::AttributeData("aPos", 3 * sizeof(float))); - uniforms.push_back(SpireSubPass::Uniform("uUseClippingPlanes", true)); + uniforms.push_back(SpireSubPass::Uniform("uUseClippingPlanes", isClippable)); uniforms.push_back(SpireSubPass::Uniform("uUseFog", true)); if (useNormals) @@ -103,7 +105,7 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique std::string iboName = passID + "IBO"; std::string passName = passID + "Pass"; - const static size_t maxPointsPerPass = 3 << 24; + const static size_t maxPointsPerPass = 3 << 24; //must be a numebr divisible by 2, 3 and, 4 uint32_t pointsInThisPass = std::min(pointsLeft, maxPointsPerPass); size_t endOfPass = startOfPass + pointsInThisPass; pointsLeft -= pointsInThisPass; diff --git a/src/Graphics/Glyphs/GlyphGeom.h b/src/Graphics/Glyphs/GlyphGeom.h index e0991af4ae..b7cb0afd3a 100644 --- a/src/Graphics/Glyphs/GlyphGeom.h +++ b/src/Graphics/Glyphs/GlyphGeom.h @@ -51,7 +51,7 @@ namespace SCIRun { void buildObject(Datatypes::GeometryObjectSpire& geom, const std::string& uniqueNodeID, const bool isTransparent, const double transparencyValue, const Datatypes::ColorScheme& colorScheme, RenderState state, - const Datatypes::SpireIBO::PRIMITIVE& primIn, const Core::Geometry::BBox& bbox, const Core::Datatypes::ColorMapHandle colorMap = nullptr); + const Datatypes::SpireIBO::PRIMITIVE& primIn, const Core::Geometry::BBox& bbox, const bool isClippable = true, const Core::Datatypes::ColorMapHandle colorMap = nullptr); void addArrow(const Core::Geometry::Point& p1, const Core::Geometry::Point& p2, double radius, double ratio, int resolution, const Core::Datatypes::ColorRGB& color1, const Core::Datatypes::ColorRGB& color2, bool render_cylinder_base, bool render_cone_base); diff --git a/src/Interface/Modules/Render/ViewScene.cc b/src/Interface/Modules/Render/ViewScene.cc index 8ed8ea2fe6..fb05664244 100644 --- a/src/Interface/Modules/Render/ViewScene.cc +++ b/src/Interface/Modules/Render/ViewScene.cc @@ -1488,7 +1488,7 @@ void ViewSceneDialog::buildGeometryClippingPlane(int index, glm::vec4 plane, con renState.set(RenderState::IS_WIDGET, true); auto geom(boost::make_shared(*gid_, uniqueNodeID, false)); glyphs.buildObject(*geom, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENCY), 1.0, - colorScheme, renState, SpireIBO::PRIMITIVE::TRIANGLES, BBox()); + colorScheme, renState, SpireIBO::PRIMITIVE::TRIANGLES, BBox(), false, nullptr); Graphics::GlyphGeom glyphs2; glyphs2.addPlane(p1, p2, p3, p4, ColorRGB()); @@ -1503,7 +1503,7 @@ void ViewSceneDialog::buildGeometryClippingPlane(int index, glm::vec4 plane, con renState.defaultColor = ColorRGB(1, 1, 1, 0.2); auto geom2(boost::make_shared(*gid_, ss.str(), false)); glyphs2.buildObject(*geom2, uniqueNodeID, renState.get(RenderState::USE_TRANSPARENCY), 0.2, - colorScheme, renState, SpireIBO::PRIMITIVE::TRIANGLES, BBox()); + colorScheme, renState, SpireIBO::PRIMITIVE::TRIANGLES, BBox(), false, nullptr); clippingPlaneGeoms_.push_back(geom); clippingPlaneGeoms_.push_back(geom2); diff --git a/src/Modules/Visualization/ShowField.cc b/src/Modules/Visualization/ShowField.cc index 875248b70a..1f2993465c 100644 --- a/src/Modules/Visualization/ShowField.cc +++ b/src/Modules/Visualization/ShowField.cc @@ -1055,7 +1055,7 @@ void GeometryBuilder::renderEdges( } glyphs.buildObject(*geom, uniqueNodeID, state.get(RenderState::USE_TRANSPARENT_EDGES), edgeTransparencyValue_, - colorScheme, state, primIn, mesh->get_bounding_box(), map); + colorScheme, state, primIn, mesh->get_bounding_box(), true, map); } void ShowField::updateAvailableRenderOptions(FieldHandle field) From 318854838f0508c8da9c567ae310d535878f2c0b Mon Sep 17 00:00:00 2001 From: Haydelj Date: Mon, 16 Sep 2019 13:46:40 -0600 Subject: [PATCH 05/10] made suggested changes --- src/Core/Datatypes/ColorMap.cc | 15 ++++- src/Graphics/Glyphs/GlyphGeom.cc | 66 +++++++++---------- .../Render/ES/shaders/Flat_ColorMap.fs | 8 ++- .../Render/ES/shaders/Phong_ColorMap.fs | 8 ++- src/Modules/Visualization/ShowField.cc | 57 ++++++++-------- 5 files changed, 83 insertions(+), 71 deletions(-) diff --git a/src/Core/Datatypes/ColorMap.cc b/src/Core/Datatypes/ColorMap.cc index 08845ba005..23b8ca432e 100644 --- a/src/Core/Datatypes/ColorMap.cc +++ b/src/Core/Datatypes/ColorMap.cc @@ -215,7 +215,10 @@ double alpha(double transformedValue) * @return The RGB value mapped from the scalar. */ ColorRGB ColorMap::valueToColor(double scalar) const { - return getColorMapVal(scalar); + ColorRGB color = getColorMapVal(scalar); + return color; + //float alpha = 0.5; + //return ColorRGB(color.r(), color.g(), color.b(), alpha); } /** * @name valueToColor @@ -227,7 +230,10 @@ ColorRGB ColorMap::valueToColor(Tensor &tensor) const { double eigen1, eigen2, eigen3; tensor.get_eigenvalues(eigen1, eigen2, eigen3); double magnitude = Vector(eigen1, eigen2, eigen3).length(); - return getColorMapVal(magnitude); + ColorRGB color = getColorMapVal(magnitude); + return color; + //float alpha = 0.5; + //return ColorRGB(color.r(), color.g(), color.b(), alpha); } /** * @name valueToColor @@ -238,7 +244,10 @@ ColorRGB ColorMap::valueToColor(Tensor &tensor) const { ColorRGB ColorMap::valueToColor(const Vector &vector) const { //TODO this is probably not implemented correctly. // return ColorRGB(getTransformedColor(fabs(vector.x())),getTransformedColor(fabs(vector.y())), getTransformedColor(fabs(vector.z()))); - return getColorMapVal(vector.length()); + ColorRGB color = getColorMapVal(vector.length()); + return color; + //float alpha = 0.5; + //return ColorRGB(color.r(), color.g(), color.b(), alpha); } // This Rainbow takes into account scientific visualization recommendations. diff --git a/src/Graphics/Glyphs/GlyphGeom.cc b/src/Graphics/Glyphs/GlyphGeom.cc index f12dcd3f52..a2369b0232 100644 --- a/src/Graphics/Glyphs/GlyphGeom.cc +++ b/src/Graphics/Glyphs/GlyphGeom.cc @@ -72,6 +72,8 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique uniforms.push_back(SpireSubPass::Uniform("uSpecularPower", 32.0f)); } + SpireText text; + SpireTexture2D texture; if (useColor) { if(colorMap) @@ -79,6 +81,20 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique numAttributes += 2; shader += "_ColorMap"; attribs.push_back(SpireVBO::AttributeData("aTexCoords", 2 * sizeof(float))); + + const static int colorMapResolution = 256; + for(int i = 0; i < colorMapResolution; ++i) + { + ColorRGB color = colorMap->valueToColor(static_cast(i)/colorMapResolution * 2.0f - 1.0f); + texture.bitmap.push_back(color.r()*255.99f); + texture.bitmap.push_back(color.g()*255.99f); + texture.bitmap.push_back(color.b()*255.99f); + texture.bitmap.push_back(color.a()*255.99f); + } + + texture.name = "ColorMap"; + texture.height = 1; + texture.width = colorMapResolution; } else { @@ -105,7 +121,7 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique std::string iboName = passID + "IBO"; std::string passName = passID + "Pass"; - const static size_t maxPointsPerPass = 3 << 24; //must be a numebr divisible by 2, 3 and, 4 + const static size_t maxPointsPerPass = 3 << 24; //must be a number divisible by 2, 3 and, 4 uint32_t pointsInThisPass = std::min(pointsLeft, maxPointsPerPass); size_t endOfPass = startOfPass + pointsInThisPass; pointsLeft -= pointsInThisPass; @@ -123,31 +139,34 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique BBox newBBox; for (size_t i = startOfPass; i < endOfPass; ++i) { - newBBox.extend(Point(points_.at(i).x(), points_.at(i).y(), points_.at(i).z())); - vboBuffer->write(static_cast(points_.at(i).x())); - vboBuffer->write(static_cast(points_.at(i).y())); - vboBuffer->write(static_cast(points_.at(i).z())); + Vector point = points_.at(i); + newBBox.extend(Point(point.x(), point.y(), point.z())); + vboBuffer->write(static_cast(point.x())); + vboBuffer->write(static_cast(point.y())); + vboBuffer->write(static_cast(point.z())); if (useNormals) { - vboBuffer->write(static_cast(normals_.at(i).x())); - vboBuffer->write(static_cast(normals_.at(i).y())); - vboBuffer->write(static_cast(normals_.at(i).z())); + Vector normal = normals_.at(i); + vboBuffer->write(static_cast(normal.x())); + vboBuffer->write(static_cast(normal.y())); + vboBuffer->write(static_cast(normal.z())); } if (useColor) { + ColorRGB color = colors_.at(i); if(!colorMap) { - vboBuffer->write(static_cast(colors_.at(i).r())); - vboBuffer->write(static_cast(colors_.at(i).g())); - vboBuffer->write(static_cast(colors_.at(i).b())); - vboBuffer->write(static_cast(colors_.at(i).a())); + vboBuffer->write(static_cast(color.r())); + vboBuffer->write(static_cast(color.g())); + vboBuffer->write(static_cast(color.b())); + vboBuffer->write(static_cast(color.a())); } else { - vboBuffer->write(static_cast(colors_.at(i).r())); - vboBuffer->write(static_cast(colors_.at(i).r())); + vboBuffer->write(static_cast(color.r())); + vboBuffer->write(static_cast(color.r())); } } } @@ -160,25 +179,6 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique state.set(RenderState::IS_ON, true); state.set(RenderState::HAS_DATA, true); - - SpireTexture2D texture; - if (colorMap) - { - const static int colorMapResolution = 256; - for(int i = 0; i < colorMapResolution; ++i) - { - ColorRGB color = colorMap->valueToColor(static_cast(i)/colorMapResolution * 2.0 - 1.0); - texture.bitmap.push_back(color.r()*255); - texture.bitmap.push_back(color.g()*255); - texture.bitmap.push_back(color.b()*255); - texture.bitmap.push_back(255); - } - texture.name = "ColorMap"; - texture.height = 1; - texture.width = colorMapResolution; - } - - SpireText text; SpireSubPass pass(passName, vboName, iboName, shader, colorScheme, state, renderType, geomVBO, geomIBO, text, texture); for (const auto& uniform : uniforms) pass.addUniform(uniform); diff --git a/src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.fs b/src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.fs index bbb5cd2619..4dd5784392 100644 --- a/src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.fs +++ b/src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.fs @@ -114,9 +114,11 @@ void main() } } - vec3 diffuseColor; - if(gl_FrontFacing) diffuseColor = texture2D(uTX0, vec2(vTexCoords.y, 0.0)).rgb; - else diffuseColor = texture2D(uTX0, vec2(vTexCoords.x, 0.0)).rgb; + vec4 colorMapValue; + if(gl_FrontFacing) colorMapValue = texture2D(uTX0, vec2(vTexCoords.y, 0.0)); + else colorMapValue = texture2D(uTX0, vec2(vTexCoords.x, 0.0)); + + vec3 diffuseColor = colorMapValue.rgb; float transparency = uTransparency; gl_FragColor = vec4(diffuseColor, transparency); diff --git a/src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.fs b/src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.fs index db9e3bef9b..14895656d6 100644 --- a/src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.fs +++ b/src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.fs @@ -136,9 +136,11 @@ void main() } } - vec3 diffuseColor; - if(gl_FrontFacing) diffuseColor = texture2D(uTX0, vec2(vTexCoords.y, 0.0)).rgb; - else diffuseColor = texture2D(uTX0, vec2(vTexCoords.x, 0.0)).rgb; + vec4 colorMapValue; + if(gl_FrontFacing) colorMapValue = texture2D(uTX0, vec2(vTexCoords.y, 0.0)); + else colorMapValue = texture2D(uTX0, vec2(vTexCoords.x, 0.0)); + + vec3 diffuseColor = colorMapValue.rgb; vec3 specularColor = uSpecularColor.rgb; vec3 ambientColor = uAmbientColor.rgb; float transparency = uTransparency; diff --git a/src/Modules/Visualization/ShowField.cc b/src/Modules/Visualization/ShowField.cc index 1f2993465c..89a5ae7238 100644 --- a/src/Modules/Visualization/ShowField.cc +++ b/src/Modules/Visualization/ShowField.cc @@ -469,6 +469,23 @@ namespace { return ((int)writeQuads << 2) | ((int)writeNormals << 1) | ((int)writeTexCoords); } + + void spiltColorMapToTextureAndCoordinates( + const boost::optional>& colorMap, + ColorMapHandle& textureMap, ColorMapHandle& coordinateMap) + { + ColorMapHandle realColorMap = nullptr; + + if(colorMap) realColorMap = colorMap.get(); + else realColorMap = StandardColorMapFactory::create(); + + textureMap = StandardColorMapFactory::create(realColorMap->getColorMapName(), + realColorMap->getColorMapResolution(), realColorMap->getColorMapShift(), + realColorMap->getColorMapInvert()); + + coordinateMap = StandardColorMapFactory::create("Grayscale", 256, 0, false, + realColorMap->getColorMapRescaleScale(), realColorMap->getColorMapRescaleShift()); + } } @@ -522,12 +539,9 @@ void GeometryBuilder::renderFacesLinear( ColorScheme colorScheme = ColorScheme::COLOR_UNIFORM; - ColorMapHandle realColorMap; - if(colorMap) realColorMap = colorMap.get(); - if(!realColorMap) realColorMap = StandardColorMapFactory::create(); - auto coordinateMap = StandardColorMapFactory::create("Grayscale", 256, 0, false, - realColorMap->getColorMapRescaleScale(), realColorMap->getColorMapRescaleShift()); + ColorMapHandle textureMap, coordinateMap; + spiltColorMapToTextureAndCoordinates(colorMap, textureMap, coordinateMap); if (useColorMap) { @@ -773,18 +787,14 @@ void GeometryBuilder::renderFacesLinear( shader += "_ColorMap"; attribs.push_back(SpireVBO::AttributeData("aTexCoords", 2 * sizeof(float))); - auto map = StandardColorMapFactory::create(realColorMap->getColorMapName(), - realColorMap->getColorMapResolution(), realColorMap->getColorMapShift(), - realColorMap->getColorMapInvert()); - const static int colorMapResolution = 256; for(int i = 0; i < colorMapResolution; ++i) { - ColorRGB color = map->valueToColor(static_cast(i)/colorMapResolution * 2.0 - 1.0); - texture.bitmap.push_back(color.r()*255); - texture.bitmap.push_back(color.g()*255); - texture.bitmap.push_back(color.b()*255); - texture.bitmap.push_back(255); + ColorRGB color = textureMap->valueToColor(static_cast(i)/colorMapResolution * 2.0 - 1.0); + texture.bitmap.push_back(color.r()*255.99f); + texture.bitmap.push_back(color.g()*255.99f); + texture.bitmap.push_back(color.b()*255.99f); + texture.bitmap.push_back(color.a()*255.99f); } texture.name = "ColorMap"; texture.height = 1; @@ -908,6 +918,7 @@ void GeometryBuilder::renderNodes( } + void GeometryBuilder::renderEdges( FieldHandle field, boost::optional> colorMap, @@ -926,12 +937,8 @@ void GeometryBuilder::renderEdges( ColorScheme colorScheme; ColorRGB edge_colors[2]; - ColorMapHandle realColorMap = nullptr; - if(colorMap) realColorMap = colorMap.get(); - if(!realColorMap) realColorMap = StandardColorMapFactory::create(); - - auto coordinateMap = StandardColorMapFactory::create("Grayscale", 256, 0, false, - realColorMap->getColorMapRescaleScale(), realColorMap->getColorMapRescaleShift()); + ColorMapHandle textureMap, coordinateMap; + spiltColorMapToTextureAndCoordinates(colorMap, textureMap, coordinateMap); if (fld->basis_order() < 0 || (fld->basis_order() == 0 && mesh->dimensionality() != 0) || @@ -1046,16 +1053,8 @@ void GeometryBuilder::renderEdges( ++eiter; } - ColorMapHandle map = nullptr; - if(realColorMap) - { - map = StandardColorMapFactory::create(realColorMap->getColorMapName(), - realColorMap->getColorMapResolution(), realColorMap->getColorMapShift(), - realColorMap->getColorMapInvert()); - } - glyphs.buildObject(*geom, uniqueNodeID, state.get(RenderState::USE_TRANSPARENT_EDGES), edgeTransparencyValue_, - colorScheme, state, primIn, mesh->get_bounding_box(), true, map); + colorScheme, state, primIn, mesh->get_bounding_box(), true, textureMap); } void ShowField::updateAvailableRenderOptions(FieldHandle field) From 7241bb9b42a85b6532f210d2e9884968216da41b Mon Sep 17 00:00:00 2001 From: Haydelj Date: Wed, 18 Sep 2019 11:06:55 -0600 Subject: [PATCH 06/10] removed commented out code --- src/Core/Datatypes/ColorMap.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Core/Datatypes/ColorMap.cc b/src/Core/Datatypes/ColorMap.cc index 23b8ca432e..0482050aae 100644 --- a/src/Core/Datatypes/ColorMap.cc +++ b/src/Core/Datatypes/ColorMap.cc @@ -217,8 +217,6 @@ double alpha(double transformedValue) ColorRGB ColorMap::valueToColor(double scalar) const { ColorRGB color = getColorMapVal(scalar); return color; - //float alpha = 0.5; - //return ColorRGB(color.r(), color.g(), color.b(), alpha); } /** * @name valueToColor @@ -232,8 +230,6 @@ ColorRGB ColorMap::valueToColor(Tensor &tensor) const { double magnitude = Vector(eigen1, eigen2, eigen3).length(); ColorRGB color = getColorMapVal(magnitude); return color; - //float alpha = 0.5; - //return ColorRGB(color.r(), color.g(), color.b(), alpha); } /** * @name valueToColor @@ -246,8 +242,6 @@ ColorRGB ColorMap::valueToColor(const Vector &vector) const { // return ColorRGB(getTransformedColor(fabs(vector.x())),getTransformedColor(fabs(vector.y())), getTransformedColor(fabs(vector.z()))); ColorRGB color = getColorMapVal(vector.length()); return color; - //float alpha = 0.5; - //return ColorRGB(color.r(), color.g(), color.b(), alpha); } // This Rainbow takes into account scientific visualization recommendations. From 3b24230c433c92db79f67fd377c4e148ae0ba023 Mon Sep 17 00:00:00 2001 From: Haydelj Date: Mon, 23 Sep 2019 14:02:40 -0600 Subject: [PATCH 07/10] fixed widget normals and added gamma correction to the phong shaders --- .../Modules/Render/ES/SRInterface.cc | 19 ++++-- .../Modules/Render/ES/shaders/Flat.vs | 2 - .../Modules/Render/ES/shaders/Flat_Color.vs | 2 - .../Render/ES/shaders/Flat_ColorMap.vs | 2 - .../Modules/Render/ES/shaders/Phong.fs | 62 +++++++++---------- .../Modules/Render/ES/shaders/Phong.vs | 8 +-- .../Modules/Render/ES/shaders/Phong_Color.fs | 62 +++++++++---------- .../Modules/Render/ES/shaders/Phong_Color.vs | 6 +- .../Render/ES/shaders/Phong_ColorMap.fs | 62 +++++++++---------- .../Render/ES/shaders/Phong_ColorMap.vs | 6 +- 10 files changed, 109 insertions(+), 122 deletions(-) diff --git a/src/Interface/Modules/Render/ES/SRInterface.cc b/src/Interface/Modules/Render/ES/SRInterface.cc index fab9a99798..3e8a97dbed 100644 --- a/src/Interface/Modules/Render/ES/SRInterface.cc +++ b/src/Interface/Modules/Render/ES/SRInterface.cc @@ -77,6 +77,17 @@ namespace fs = spire; namespace SCIRun { namespace Render { + + static glm::vec4 inverseGammaCorrect(glm::vec4 in) + { + return glm::vec4(glm::pow(glm::vec3(in), glm::vec3(2.2)), in.a); + } + + static glm::vec3 inverseGammaCorrect(glm::vec3 in) + { + return glm::pow(in, glm::vec3(2.2)); + } + //---------------------------------------------------------------------------------------------- SRInterface::SRInterface(std::shared_ptr context, int frameInitLimit) : mContext(context), @@ -1781,9 +1792,9 @@ namespace SCIRun { void SRInterface::applyMatFactors(Graphics::Datatypes::SpireSubPass::Uniform& uniform) { if (uniform.name == "uAmbientColor") - uniform.data = glm::vec4(mMatAmbient); + uniform.data = inverseGammaCorrect(glm::vec4(mMatAmbient)); else if (uniform.name == "uSpecularColor") - uniform.data = glm::vec4(mMatSpecular); + uniform.data = inverseGammaCorrect(glm::vec4(mMatSpecular)); else if (uniform.name == "uSpecularPower") uniform.data = glm::vec4(mMatShine); } @@ -1800,7 +1811,7 @@ namespace SCIRun { } else if (uniform.name == "uFogColor") { - uniform.data = mFogColor; + uniform.data = inverseGammaCorrect(mFogColor); } uniform.type = Graphics::Datatypes::SpireSubPass::Uniform::UniformType::UNIFORM_VEC4; @@ -1814,7 +1825,7 @@ namespace SCIRun { StaticWorldLight* light = mCore.getStaticComponent(); if (light) { - light->lightColor[index] = glm::vec3(r, g, b); + light->lightColor[index] = inverseGammaCorrect(glm::vec3(r, g, b)); } } diff --git a/src/Interface/Modules/Render/ES/shaders/Flat.vs b/src/Interface/Modules/Render/ES/shaders/Flat.vs index 493e29007f..25b3222d5a 100644 --- a/src/Interface/Modules/Render/ES/shaders/Flat.vs +++ b/src/Interface/Modules/Render/ES/shaders/Flat.vs @@ -41,8 +41,6 @@ varying vec4 vPosView; void main( void ) { - // Todo: Add gamma correction factor of 2.2. For textures, we assume that it - // was generated in gamma space, and we need to convert it to linear space. vPosWorld = uModel * vec4(aPos, 1.0); vPosView = uView * uModel * vPosWorld; diff --git a/src/Interface/Modules/Render/ES/shaders/Flat_Color.vs b/src/Interface/Modules/Render/ES/shaders/Flat_Color.vs index f03dabfd43..6c723ea7b0 100644 --- a/src/Interface/Modules/Render/ES/shaders/Flat_Color.vs +++ b/src/Interface/Modules/Render/ES/shaders/Flat_Color.vs @@ -42,8 +42,6 @@ varying vec4 vColor; void main( void ) { - // Todo: Add gamma correction factor of 2.2. For textures, we assume that it - // was generated in gamma space, and we need to convert it to linear space. vPosWorld = uModel * vec4(aPos, 1.0); vPosView = uView * uModel * vPosWorld; vColor = aColor; diff --git a/src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.vs b/src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.vs index 3d9dacc1c8..09841109b2 100644 --- a/src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.vs +++ b/src/Interface/Modules/Render/ES/shaders/Flat_ColorMap.vs @@ -42,8 +42,6 @@ varying vec2 vTexCoords; void main( void ) { - // Todo: Add gamma correction factor of 2.2. For textures, we assume that it - // was generated in gamma space, and we need to convert it to linear space. vPosWorld = uModel * vec4(aPos, 1.0); vPosView = uView * uModel * vPosWorld; vTexCoords = aTexCoords; diff --git a/src/Interface/Modules/Render/ES/shaders/Phong.fs b/src/Interface/Modules/Render/ES/shaders/Phong.fs index 63777c358c..f03de62a15 100644 --- a/src/Interface/Modules/Render/ES/shaders/Phong.fs +++ b/src/Interface/Modules/Render/ES/shaders/Phong.fs @@ -74,14 +74,14 @@ varying vec3 vNormal; varying vec4 vPosWorld; varying vec4 vPosView; -vec4 calculate_lighting(vec3 N, vec3 L, vec3 V, vec3 diffuseColor, vec3 specularColor, vec3 lightColor) +vec3 calculate_lighting(vec3 N, vec3 L, vec3 V, vec3 diffuseColor, vec3 specularColor, vec3 lightColor) { vec3 H = normalize(V + L); float diffuse = max(0.0, dot(N, L)); float specular = max(0.0, dot(N, H)); specular = pow(specular, uSpecularPower); - return vec4(lightColor * (diffuse * diffuseColor + specular * specularColor), 0.0); + return lightColor * (diffuse * diffuseColor + specular * specularColor); } void main() @@ -89,71 +89,65 @@ void main() if(uUseClippingPlanes) { float fPlaneValue; - if (uClippingPlaneCtrl0.x > 0.5) + if(uClippingPlaneCtrl0.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane0); fPlaneValue = uClippingPlaneCtrl0.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } - if (uClippingPlaneCtrl1.x > 0.5) + if(uClippingPlaneCtrl1.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane1); fPlaneValue = uClippingPlaneCtrl1.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } - if (uClippingPlaneCtrl2.x > 0.5) + if(uClippingPlaneCtrl2.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane2); fPlaneValue = uClippingPlaneCtrl2.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } - if (uClippingPlaneCtrl3.x > 0.5) + if(uClippingPlaneCtrl3.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane3); fPlaneValue = uClippingPlaneCtrl3.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } - if (uClippingPlaneCtrl4.x > 0.5) + if(uClippingPlaneCtrl4.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane4); fPlaneValue = uClippingPlaneCtrl4.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } - if (uClippingPlaneCtrl5.x > 0.5) + if(uClippingPlaneCtrl5.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane5); fPlaneValue = uClippingPlaneCtrl5.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } } - vec3 diffuseColor = uDiffuseColor.rgb; + vec3 diffuseColor = pow(uDiffuseColor.rgb, vec3(2.2)); vec3 specularColor = uSpecularColor.rgb; vec3 ambientColor = uAmbientColor.rgb; float transparency = uTransparency; vec3 normal = normalize(vNormal); - if (gl_FrontFacing) normal = -normal; + if(gl_FrontFacing) normal = -normal; vec3 cameraVector = -normalize(vPosView.xyz); gl_FragColor = vec4(ambientColor * diffuseColor, transparency); - if (length(uLightDirectionView0) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView0, cameraVector, diffuseColor, specularColor, uLightColor0); - if (length(uLightDirectionView1) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView1, cameraVector, diffuseColor, specularColor, uLightColor1); - if (length(uLightDirectionView2) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView2, cameraVector, diffuseColor, specularColor, uLightColor2); - if (length(uLightDirectionView3) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView3, cameraVector, diffuseColor, specularColor, uLightColor3); + if(length(uLightDirectionView0) > 0.0) gl_FragColor.rgb += calculate_lighting(normal, + uLightDirectionView0, cameraVector, diffuseColor, specularColor, uLightColor0); + if(length(uLightDirectionView1) > 0.0) gl_FragColor.rgb += calculate_lighting(normal, + uLightDirectionView1, cameraVector, diffuseColor, specularColor, uLightColor1); + if(length(uLightDirectionView2) > 0.0) gl_FragColor.rgb += calculate_lighting(normal, + uLightDirectionView2, cameraVector, diffuseColor, specularColor, uLightColor2); + if(length(uLightDirectionView3) > 0.0) gl_FragColor.rgb += calculate_lighting(normal, + uLightDirectionView3, cameraVector, diffuseColor, specularColor, uLightColor3); //calculate fog - if (uUseFog && uFogSettings.x > 0.0) + if(uUseFog && uFogSettings.x > 0.0) { vec4 fp; fp.x = uFogSettings.x; @@ -165,7 +159,9 @@ void main() fog_factor = (fp.z-fp.w)/(fp.z-fp.y); fog_factor = 1.0 - clamp(fog_factor, 0.0, 1.0); fog_factor = 1.0 - exp(-pow(fog_factor*2.5, 2.0)); - gl_FragColor.xyz = mix(clamp(gl_FragColor.xyz, 0.0, 1.0), - clamp(uFogColor.xyz, 0.0, 1.0), fog_factor); + gl_FragColor.rgb = mix(clamp(gl_FragColor.rgb, 0.0, 1.0), + clamp(uFogColor.rgb, 0.0, 1.0), fog_factor); } + + gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(1.0/2.2)); } diff --git a/src/Interface/Modules/Render/ES/shaders/Phong.vs b/src/Interface/Modules/Render/ES/shaders/Phong.vs index 9586ef9144..5530d2970b 100644 --- a/src/Interface/Modules/Render/ES/shaders/Phong.vs +++ b/src/Interface/Modules/Render/ES/shaders/Phong.vs @@ -43,11 +43,9 @@ varying vec4 vPosView; void main( void ) { - // Todo: Add gamma correction factor of 2.2. For textures, we assume that it - // was generated in gamma space, and we need to convert it to linear space. vPosWorld = uModel * vec4(aPos, 1.0); - vPosView = uView * vPosWorld; - vNormal = normalize((uView * vec4(aNormal, 0.0)).xyz); - + vPosView = uView * uModel * vPosWorld; + vNormal = normalize((uView * uModel * vec4(aNormal, 0.0)).xyz); + gl_Position = uModelViewProjection * vec4(aPos, 1.0); } diff --git a/src/Interface/Modules/Render/ES/shaders/Phong_Color.fs b/src/Interface/Modules/Render/ES/shaders/Phong_Color.fs index e554c2920b..1840df1787 100644 --- a/src/Interface/Modules/Render/ES/shaders/Phong_Color.fs +++ b/src/Interface/Modules/Render/ES/shaders/Phong_Color.fs @@ -75,14 +75,14 @@ varying vec4 vPosWorld; varying vec4 vPosView; varying vec4 vColor; -vec4 calculate_lighting(vec3 N, vec3 L, vec3 V, vec3 diffuseColor, vec3 specularColor, vec3 lightColor) +vec3 calculate_lighting(vec3 N, vec3 L, vec3 V, vec3 diffuseColor, vec3 specularColor, vec3 lightColor) { vec3 H = normalize(V + L); float diffuse = max(0.0, dot(N, L)); float specular = max(0.0, dot(N, H)); specular = pow(specular, uSpecularPower); - return vec4(lightColor * (diffuse * diffuseColor + specular * specularColor), 0.0); + return lightColor * (diffuse * diffuseColor + specular * specularColor); } void main() @@ -90,71 +90,65 @@ void main() if(uUseClippingPlanes) { float fPlaneValue; - if (uClippingPlaneCtrl0.x > 0.5) + if(uClippingPlaneCtrl0.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane0); fPlaneValue = uClippingPlaneCtrl0.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } - if (uClippingPlaneCtrl1.x > 0.5) + if(uClippingPlaneCtrl1.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane1); fPlaneValue = uClippingPlaneCtrl1.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } - if (uClippingPlaneCtrl2.x > 0.5) + if(uClippingPlaneCtrl2.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane2); fPlaneValue = uClippingPlaneCtrl2.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } - if (uClippingPlaneCtrl3.x > 0.5) + if(uClippingPlaneCtrl3.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane3); fPlaneValue = uClippingPlaneCtrl3.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } - if (uClippingPlaneCtrl4.x > 0.5) + if(uClippingPlaneCtrl4.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane4); fPlaneValue = uClippingPlaneCtrl4.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } - if (uClippingPlaneCtrl5.x > 0.5) + if(uClippingPlaneCtrl5.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane5); fPlaneValue = uClippingPlaneCtrl5.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } } - vec3 diffuseColor = vColor.rgb; + vec3 diffuseColor = pow(vColor.rgb, vec3(2.2)); vec3 specularColor = uSpecularColor.rgb; vec3 ambientColor = uAmbientColor.rgb; float transparency = uTransparency; vec3 normal = normalize(vNormal); - if (gl_FrontFacing) normal = -normal; + if(gl_FrontFacing) normal = -normal; vec3 cameraVector = -normalize(vPosView.xyz); gl_FragColor = vec4(ambientColor * diffuseColor, transparency); - if (length(uLightDirectionView0) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView0, cameraVector, diffuseColor, specularColor, uLightColor0); - if (length(uLightDirectionView1) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView1, cameraVector, diffuseColor, specularColor, uLightColor1); - if (length(uLightDirectionView2) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView2, cameraVector, diffuseColor, specularColor, uLightColor2); - if (length(uLightDirectionView3) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView3, cameraVector, diffuseColor, specularColor, uLightColor3); + if(length(uLightDirectionView0) > 0.0) gl_FragColor.rgb += calculate_lighting(normal, + uLightDirectionView0, cameraVector, diffuseColor, specularColor, uLightColor0); + if(length(uLightDirectionView1) > 0.0) gl_FragColor.rgb += calculate_lighting(normal, + uLightDirectionView1, cameraVector, diffuseColor, specularColor, uLightColor1); + if(length(uLightDirectionView2) > 0.0) gl_FragColor.rgb += calculate_lighting(normal, + uLightDirectionView2, cameraVector, diffuseColor, specularColor, uLightColor2); + if(length(uLightDirectionView3) > 0.0) gl_FragColor.rgb += calculate_lighting(normal, + uLightDirectionView3, cameraVector, diffuseColor, specularColor, uLightColor3); //calculate fog - if (uUseFog && uFogSettings.x > 0.0) + if(uUseFog && uFogSettings.x > 0.0) { vec4 fp; fp.x = uFogSettings.x; @@ -166,7 +160,9 @@ void main() fog_factor = (fp.z-fp.w)/(fp.z-fp.y); fog_factor = 1.0 - clamp(fog_factor, 0.0, 1.0); fog_factor = 1.0 - exp(-pow(fog_factor*2.5, 2.0)); - gl_FragColor.xyz = mix(clamp(gl_FragColor.xyz, 0.0, 1.0), - clamp(uFogColor.xyz, 0.0, 1.0), fog_factor); + gl_FragColor.rgb = mix(clamp(gl_FragColor.rgb, 0.0, 1.0), + clamp(uFogColor.rgb, 0.0, 1.0), fog_factor); } + + gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(1.0/2.2)); } diff --git a/src/Interface/Modules/Render/ES/shaders/Phong_Color.vs b/src/Interface/Modules/Render/ES/shaders/Phong_Color.vs index d6f5a5b477..ea9fa845f6 100644 --- a/src/Interface/Modules/Render/ES/shaders/Phong_Color.vs +++ b/src/Interface/Modules/Render/ES/shaders/Phong_Color.vs @@ -44,11 +44,9 @@ varying vec4 vColor; void main( void ) { - // Todo: Add gamma correction factor of 2.2. For textures, we assume that it - // was generated in gamma space, and we need to convert it to linear space. vPosWorld = uModel * vec4(aPos, 1.0); - vPosView = uView * vPosWorld; - vNormal = normalize((uView * vec4(aNormal, 0.0)).xyz); + vPosView = uView * uModel * vPosWorld; + vNormal = normalize((uView * uModel * vec4(aNormal, 0.0)).xyz); vColor = aColor; gl_Position = uModelViewProjection * vec4(aPos, 1.0); diff --git a/src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.fs b/src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.fs index 14895656d6..354c516272 100644 --- a/src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.fs +++ b/src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.fs @@ -77,14 +77,14 @@ varying vec4 vPosWorld; varying vec4 vPosView; varying vec2 vTexCoords; -vec4 calculate_lighting(vec3 N, vec3 L, vec3 V, vec3 diffuseColor, vec3 specularColor, vec3 lightColor) +vec3 calculate_lighting(vec3 N, vec3 L, vec3 V, vec3 diffuseColor, vec3 specularColor, vec3 lightColor) { vec3 H = normalize(V + L); float diffuse = max(0.0, dot(N, L)); float specular = max(0.0, dot(N, H)); specular = pow(specular, uSpecularPower); - return vec4(lightColor * (diffuse * diffuseColor + specular * specularColor), 0.0); + return lightColor * (diffuse * diffuseColor + specular * specularColor); } void main() @@ -92,47 +92,41 @@ void main() if(uUseClippingPlanes) { float fPlaneValue; - if (uClippingPlaneCtrl0.x > 0.5) + if(uClippingPlaneCtrl0.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane0); fPlaneValue = uClippingPlaneCtrl0.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } - if (uClippingPlaneCtrl1.x > 0.5) + if(uClippingPlaneCtrl1.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane1); fPlaneValue = uClippingPlaneCtrl1.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } - if (uClippingPlaneCtrl2.x > 0.5) + if(uClippingPlaneCtrl2.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane2); fPlaneValue = uClippingPlaneCtrl2.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } - if (uClippingPlaneCtrl3.x > 0.5) + if(uClippingPlaneCtrl3.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane3); fPlaneValue = uClippingPlaneCtrl3.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } - if (uClippingPlaneCtrl4.x > 0.5) + if(uClippingPlaneCtrl4.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane4); fPlaneValue = uClippingPlaneCtrl4.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } - if (uClippingPlaneCtrl5.x > 0.5) + if(uClippingPlaneCtrl5.x > 0.5) { fPlaneValue = dot(vPosWorld, uClippingPlane5); fPlaneValue = uClippingPlaneCtrl5.z > 0.5 ? -fPlaneValue : fPlaneValue; - if (fPlaneValue < 0.0) - discard; + if(fPlaneValue < 0.0) discard; } } @@ -140,27 +134,27 @@ void main() if(gl_FrontFacing) colorMapValue = texture2D(uTX0, vec2(vTexCoords.y, 0.0)); else colorMapValue = texture2D(uTX0, vec2(vTexCoords.x, 0.0)); - vec3 diffuseColor = colorMapValue.rgb; + vec3 diffuseColor = pow(colorMapValue.rgb, vec3(2.2)); vec3 specularColor = uSpecularColor.rgb; vec3 ambientColor = uAmbientColor.rgb; float transparency = uTransparency; vec3 normal = normalize(vNormal); - if (gl_FrontFacing) normal = -normal; + if(gl_FrontFacing) normal = -normal; vec3 cameraVector = -normalize(vPosView.xyz); gl_FragColor = vec4(ambientColor * diffuseColor, transparency); - if (length(uLightDirectionView0) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView0, cameraVector, diffuseColor, specularColor, uLightColor0); - if (length(uLightDirectionView1) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView1, cameraVector, diffuseColor, specularColor, uLightColor1); - if (length(uLightDirectionView2) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView2, cameraVector, diffuseColor, specularColor, uLightColor2); - if (length(uLightDirectionView3) > 0.0) - gl_FragColor += calculate_lighting(normal, uLightDirectionView3, cameraVector, diffuseColor, specularColor, uLightColor3); + if(length(uLightDirectionView0) > 0.0) gl_FragColor.rgb += calculate_lighting(normal, + uLightDirectionView0, cameraVector, diffuseColor, specularColor, uLightColor0); + if(length(uLightDirectionView1) > 0.0) gl_FragColor.rgb += calculate_lighting(normal, + uLightDirectionView1, cameraVector, diffuseColor, specularColor, uLightColor1); + if(length(uLightDirectionView2) > 0.0) gl_FragColor.rgb += calculate_lighting(normal, + uLightDirectionView2, cameraVector, diffuseColor, specularColor, uLightColor2); + if(length(uLightDirectionView3) > 0.0) gl_FragColor.rgb += calculate_lighting(normal, + uLightDirectionView3, cameraVector, diffuseColor, specularColor, uLightColor3); //calculate fog - if (uUseFog && uFogSettings.x > 0.0) + if(uUseFog && uFogSettings.x > 0.0) { vec4 fp; fp.x = uFogSettings.x; @@ -172,7 +166,9 @@ void main() fog_factor = (fp.z-fp.w)/(fp.z-fp.y); fog_factor = 1.0 - clamp(fog_factor, 0.0, 1.0); fog_factor = 1.0 - exp(-pow(fog_factor*2.5, 2.0)); - gl_FragColor.xyz = mix(clamp(gl_FragColor.xyz, 0.0, 1.0), - clamp(uFogColor.xyz, 0.0, 1.0), fog_factor); + gl_FragColor.rgb = mix(clamp(gl_FragColor.rgb, 0.0, 1.0), + clamp(uFogColor.rgb, 0.0, 1.0), fog_factor); } + + gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(1.0/2.2)); } diff --git a/src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.vs b/src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.vs index 7a17bc517f..181acde3fe 100644 --- a/src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.vs +++ b/src/Interface/Modules/Render/ES/shaders/Phong_ColorMap.vs @@ -44,11 +44,9 @@ varying vec2 vTexCoords; void main( void ) { - // Todo: Add gamma correction factor of 2.2. For textures, we assume that it - // was generated in gamma space, and we need to convert it to linear space. vPosWorld = uModel * vec4(aPos, 1.0); - vPosView = uView * vPosWorld; - vNormal = normalize((uView * vec4(aNormal, 0.0)).xyz); + vPosView = uView * uModel * vPosWorld; + vNormal = normalize((uView * uModel * vec4(aNormal, 0.0)).xyz); vTexCoords = aTexCoords; gl_Position = uModelViewProjection * vec4(aPos, 1.0); From 92a928a6ffa4437e353ed4823ece99e5f4b63c60 Mon Sep 17 00:00:00 2001 From: Haydelj Date: Wed, 25 Sep 2019 14:16:56 -0600 Subject: [PATCH 08/10] added quad rendering support --- src/Graphics/Datatypes/GeometryImpl.h | 1 + .../Modules/Render/ES/SRInterface.cc | 46 +++---- src/Interface/Modules/Render/ES/SRInterface.h | 4 +- .../Render/ES/systems/RenderBasicSys.cc | 113 +----------------- src/Modules/Visualization/ShowField.cc | 9 +- 5 files changed, 35 insertions(+), 138 deletions(-) diff --git a/src/Graphics/Datatypes/GeometryImpl.h b/src/Graphics/Datatypes/GeometryImpl.h index 9ca49a72ce..44ee4e0d99 100644 --- a/src/Graphics/Datatypes/GeometryImpl.h +++ b/src/Graphics/Datatypes/GeometryImpl.h @@ -109,6 +109,7 @@ namespace SCIRun { POINTS, LINES, TRIANGLES, + QUADS }; SpireIBO() : indexSize(0), prim(PRIMITIVE::POINTS) {} diff --git a/src/Interface/Modules/Render/ES/SRInterface.cc b/src/Interface/Modules/Render/ES/SRInterface.cc index 3e8a97dbed..a2f69f9e6e 100644 --- a/src/Interface/Modules/Render/ES/SRInterface.cc +++ b/src/Interface/Modules/Render/ES/SRInterface.cc @@ -453,18 +453,21 @@ namespace SCIRun { GLenum primitive = GL_TRIANGLES; switch (ibo.prim) { - case SpireIBO::PRIMITIVE::POINTS: - primitive = GL_POINTS; - break; + case SpireIBO::PRIMITIVE::POINTS: + primitive = GL_POINTS; + break; - case SpireIBO::PRIMITIVE::LINES: - primitive = GL_LINES; - break; + case SpireIBO::PRIMITIVE::LINES: + primitive = GL_LINES; + break; - case SpireIBO::PRIMITIVE::TRIANGLES: - default: - primitive = GL_TRIANGLES; - break; + case SpireIBO::PRIMITIVE::TRIANGLES: + primitive = GL_TRIANGLES; + break; + + case SpireIBO::PRIMITIVE::QUADS: + primitive = GL_QUADS; + break; } int numPrimitives = ibo.data->getBufferSize() / ibo.indexSize; @@ -1047,18 +1050,21 @@ namespace SCIRun { GLenum primitive = GL_TRIANGLES; switch (ibo.prim) { - case SpireIBO::PRIMITIVE::POINTS: - primitive = GL_POINTS; - break; + case SpireIBO::PRIMITIVE::POINTS: + primitive = GL_POINTS; + break; - case SpireIBO::PRIMITIVE::LINES: - primitive = GL_LINES; - break; + case SpireIBO::PRIMITIVE::LINES: + primitive = GL_LINES; + break; - case SpireIBO::PRIMITIVE::TRIANGLES: - default: - primitive = GL_TRIANGLES; - break; + case SpireIBO::PRIMITIVE::TRIANGLES: + primitive = GL_TRIANGLES; + break; + + case SpireIBO::PRIMITIVE::QUADS: + primitive = GL_QUADS; + break; } if (mRenderSortType == RenderState::TransparencySortType::LISTS_SORT) diff --git a/src/Interface/Modules/Render/ES/SRInterface.h b/src/Interface/Modules/Render/ES/SRInterface.h index d3f1d5698d..d9aec520dd 100644 --- a/src/Interface/Modules/Render/ES/SRInterface.h +++ b/src/Interface/Modules/Render/ES/SRInterface.h @@ -381,8 +381,8 @@ namespace SCIRun { std::vector mLightDirectionView {}; std::vector mLightsOn {}; - glm::vec2 autoRotateVector {0.0, 0.0}; - float autoRotateSpeed {0.01f}; + glm::vec2 autoRotateVector {0.0, 0.0}; + float autoRotateSpeed {0.01f}; const int frameInitLimit_ {}; std::unique_ptr mCamera; // Primary camera. diff --git a/src/Interface/Modules/Render/ES/systems/RenderBasicSys.cc b/src/Interface/Modules/Render/ES/systems/RenderBasicSys.cc index 1f3d654efa..f434df7783 100644 --- a/src/Interface/Modules/Render/ES/systems/RenderBasicSys.cc +++ b/src/Interface/Modules/Render/ES/systems/RenderBasicSys.cc @@ -251,118 +251,7 @@ class RenderBasicSys : geom.front().attribs.bind(); - if (rlist.size() > 0) - { - glm::mat4 rlistTrafo = trafo.front().transform; - - GLint uniformColorLoc = 0; - for (const ren::VecUniform& unif : vecUniforms) - { - if (std::string(unif.uniformName) == "uColor") - { - uniformColorLoc = unif.uniformLocation; - } - } - - // Note: Some of this work can be done beforehand. But we elect not to - // since it is feasible that the data contained in the VBO can change - // fairly dramatically. - - // Build BSerialize object. - spire::BSerialize posDeserialize( - rlist.front().data->getBuffer(), rlist.front().data->getBufferSize()); - - spire::BSerialize colorDeserialize( - rlist.front().data->getBuffer(), rlist.front().data->getBufferSize()); - - int64_t posSize = 0; - int64_t colorSize = 0; - int64_t stride = 0; // Stride of entire attributes buffer. - - // Determine stride for our buffer. Also determine appropriate position - // and color information offsets, and set the offsets. Also determine - // attribute size in bytes. - for (const auto& attrib : rlist.front().attributes) - { - if (attrib.name == "aPos") - { - if (stride != 0) {posDeserialize.readBytes(stride);} - posSize = attrib.sizeInBytes; - } - else if (attrib.name == "aColor") - { - if (stride != 0) {colorDeserialize.readBytes(stride);} - colorSize = attrib.sizeInBytes; - } - - stride += attrib.sizeInBytes; - } - - int64_t posStride = stride - posSize; - int64_t colorStride = stride - colorSize; - - // Render using a draw list. We will be using the VBO and IBO attached - // to this object as the basic rendering primitive. - for (int i = 0; i < rlist.front().numElements; ++i) - { - // Read position. - float x = posDeserialize.read(); - float y = posDeserialize.read(); - float z = posDeserialize.read(); - posDeserialize.readBytes(posStride); - - // Read color if available. - if (colorSize > 0) - { - float r = static_cast(colorDeserialize.read()) / 255.0f; - float g = static_cast(colorDeserialize.read()) / 255.0f; - float b = static_cast(colorDeserialize.read()) / 255.0f; - float a = static_cast(colorDeserialize.read()) / 255.0f; - if (colorDeserialize.getBytesLeft() > colorStride) - { - colorDeserialize.readBytes(colorStride); - } - GL(glUniform4f(uniformColorLoc, r, g, b, a)); - } - - // Update transform. - rlistTrafo[3].x = x; - rlistTrafo[3].y = y; - rlistTrafo[3].z = z; - commonUniforms.front().applyCommonUniforms( - rlistTrafo, camera.front().data, time.front().globalTime); - - GL(glDrawElements(ibo.front().primMode, ibo.front().numPrims, - ibo.front().primType, 0)); - } - } - else - { - if (!srstate.front().state.get(RenderState::IS_DOUBLE_SIDED)) - { - GL(glDrawElements(ibo.front().primMode, ibo.front().numPrims, - ibo.front().primType, 0)); - } - else - { - GL(glEnable(GL_CULL_FACE)); - // Double sided rendering. Mimic SCIRun4 and use GL_FRONT and GL_BACK - // to mimic forward facing and back facing polygons. - - // Draw front facing polygons. - GLint fdToggleLoc = glGetUniformLocation(shader.front().glid, "uFDToggle"); - - GL(glUniform1f(fdToggleLoc, 1.0f)); - glCullFace(GL_BACK); - GL(glDrawElements(ibo.front().primMode, ibo.front().numPrims, - ibo.front().primType, 0)); - - GL(glUniform1f(fdToggleLoc, 0.0f)); - glCullFace(GL_FRONT); - GL(glDrawElements(ibo.front().primMode, ibo.front().numPrims, - ibo.front().primType, 0)); - } - } + GL(glDrawElements(ibo.front().primMode, ibo.front().numPrims, ibo.front().primType, 0)); if (!depthMask) { diff --git a/src/Modules/Visualization/ShowField.cc b/src/Modules/Visualization/ShowField.cc index 89a5ae7238..9e3c0486e9 100644 --- a/src/Modules/Visualization/ShowField.cc +++ b/src/Modules/Visualization/ShowField.cc @@ -568,7 +568,7 @@ void GeometryBuilder::renderFacesLinear( facesLeft -= facesLeftInThisPass; // Three 32 bit ints for each triangle to index into the VBO (triangles = verticies - 2) - size_t iboSize = static_cast(facesLeftInThisPass * sizeof(uint32_t) * (numNodesPerFace - 2) * 3); + size_t iboSize = static_cast(facesLeftInThisPass * sizeof(uint32_t) * numNodesPerFace); size_t vboSize = static_cast(facesLeftInThisPass * sizeof(float) * numNodesPerFace * numAttributes); std::shared_ptr iboBufferSPtr(new spire::VarBuffer(iboSize)); std::shared_ptr vboBufferSPtr(new spire::VarBuffer(vboSize)); @@ -583,9 +583,9 @@ void GeometryBuilder::renderFacesLinear( iboBuffer->writeUnsafe(i+0); iboBuffer->writeUnsafe(i+1); iboBuffer->writeUnsafe(i+2); - iboBuffer->writeUnsafe(i+2); + //iboBuffer->writeUnsafe(i+2); iboBuffer->writeUnsafe(i+3); - iboBuffer->writeUnsafe(i+0); + //iboBuffer->writeUnsafe(i+0); } } else @@ -810,7 +810,8 @@ void GeometryBuilder::renderFacesLinear( SpireVBO geomVBO(vboName, attribs, vboBufferSPtr, 0, mesh->get_bounding_box(), true); geom->vbos().push_back(geomVBO); - SpireIBO geomIBO(iboName, SpireIBO::PRIMITIVE::TRIANGLES, sizeof(uint32_t), iboBufferSPtr); + SpireIBO geomIBO(iboName, useQuads ? SpireIBO::PRIMITIVE::QUADS : SpireIBO::PRIMITIVE::TRIANGLES, + sizeof(uint32_t), iboBufferSPtr); geom->ibos().push_back(geomIBO); SpireText text; From 2291bdbf9dbb8f5868599d87e5a2ffee510f1b8f Mon Sep 17 00:00:00 2001 From: Haydelj Date: Wed, 25 Sep 2019 14:18:49 -0600 Subject: [PATCH 09/10] cleaned up commented code --- src/Modules/Visualization/ShowField.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Modules/Visualization/ShowField.cc b/src/Modules/Visualization/ShowField.cc index 9e3c0486e9..c4881016e7 100644 --- a/src/Modules/Visualization/ShowField.cc +++ b/src/Modules/Visualization/ShowField.cc @@ -583,9 +583,7 @@ void GeometryBuilder::renderFacesLinear( iboBuffer->writeUnsafe(i+0); iboBuffer->writeUnsafe(i+1); iboBuffer->writeUnsafe(i+2); - //iboBuffer->writeUnsafe(i+2); iboBuffer->writeUnsafe(i+3); - //iboBuffer->writeUnsafe(i+0); } } else From b478ed2f2d3b357b2c050c579512d107182cdd8d Mon Sep 17 00:00:00 2001 From: Haydelj Date: Wed, 25 Sep 2019 14:50:18 -0600 Subject: [PATCH 10/10] disabled quad rendering --- src/Modules/Visualization/ShowField.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Modules/Visualization/ShowField.cc b/src/Modules/Visualization/ShowField.cc index c4881016e7..89a5ae7238 100644 --- a/src/Modules/Visualization/ShowField.cc +++ b/src/Modules/Visualization/ShowField.cc @@ -568,7 +568,7 @@ void GeometryBuilder::renderFacesLinear( facesLeft -= facesLeftInThisPass; // Three 32 bit ints for each triangle to index into the VBO (triangles = verticies - 2) - size_t iboSize = static_cast(facesLeftInThisPass * sizeof(uint32_t) * numNodesPerFace); + size_t iboSize = static_cast(facesLeftInThisPass * sizeof(uint32_t) * (numNodesPerFace - 2) * 3); size_t vboSize = static_cast(facesLeftInThisPass * sizeof(float) * numNodesPerFace * numAttributes); std::shared_ptr iboBufferSPtr(new spire::VarBuffer(iboSize)); std::shared_ptr vboBufferSPtr(new spire::VarBuffer(vboSize)); @@ -583,7 +583,9 @@ void GeometryBuilder::renderFacesLinear( iboBuffer->writeUnsafe(i+0); iboBuffer->writeUnsafe(i+1); iboBuffer->writeUnsafe(i+2); + iboBuffer->writeUnsafe(i+2); iboBuffer->writeUnsafe(i+3); + iboBuffer->writeUnsafe(i+0); } } else @@ -808,8 +810,7 @@ void GeometryBuilder::renderFacesLinear( SpireVBO geomVBO(vboName, attribs, vboBufferSPtr, 0, mesh->get_bounding_box(), true); geom->vbos().push_back(geomVBO); - SpireIBO geomIBO(iboName, useQuads ? SpireIBO::PRIMITIVE::QUADS : SpireIBO::PRIMITIVE::TRIANGLES, - sizeof(uint32_t), iboBufferSPtr); + SpireIBO geomIBO(iboName, SpireIBO::PRIMITIVE::TRIANGLES, sizeof(uint32_t), iboBufferSPtr); geom->ibos().push_back(geomIBO); SpireText text;