diff --git a/modules/touch/include/TouchMarker.h b/modules/touch/include/TouchMarker.h index 3cead1533f..d17313a9f9 100644 --- a/modules/touch/include/TouchMarker.h +++ b/modules/touch/include/TouchMarker.h @@ -34,6 +34,7 @@ #include #include #include +#include #include @@ -69,6 +70,9 @@ class TouchMarker : public properties::PropertyOwner properties::StringProperty _texturePath; properties::BoolProperty _visible; properties::FloatProperty _radiusSize; + properties::FloatProperty _transparency; + properties::FloatProperty _thickness; + properties::Vec3Property _color; std::unique_ptr _shader; std::unique_ptr _texture; diff --git a/modules/touch/shaders/marker_fs.glsl b/modules/touch/shaders/marker_fs.glsl index e15318779a..5e10ff3bdd 100644 --- a/modules/touch/shaders/marker_fs.glsl +++ b/modules/touch/shaders/marker_fs.glsl @@ -25,6 +25,9 @@ in vec2 out_position; uniform float radius; +uniform float transparency; +uniform float thickness; +uniform vec3 color; #include "PowerScaling/powerScaling_fs.hglsl" #include "fragment.glsl" @@ -37,24 +40,14 @@ Fragment getFragment() { float mag = dot(n.xy, n.xy); if (mag > 1.0) discard; // kill pixels outside circle n.z = sqrt(1.0-mag); - - //vec3 eye = vec3(0.0, 0.0, radius * n.z); - //float depth = (P[2][2] * eye.z + P[3][2]) / (P[2][3] * eye.z + P[3][3]); - //gl_FragDepth = (depth + 1.0) / 2.0; - // calculate lighting - //const vec3 light_dir = vec3(0.0, 0.0, 1.0); - //float diffuse = max(0.0, dot(light_dir, n)); - - //vec3 halfVector = normalize( eye + light_dir); - //float spec = pow(max(0.0, dot(n,halfVector)), 100.0); - - vec3 color = vec3(1.0, 1.0, 1.0); - float alpha = mag; + const vec3 light_dir = vec3(0.0, 0.0, 1.0); + float diffuse = max(0.0, dot(light_dir, n)); + float alpha = min(pow(mag, thickness), transparency); Fragment frag; - frag.color = vec4(color, alpha); + frag.color = vec4(color * diffuse, alpha); frag.depth = 1.0; return frag; } \ No newline at end of file diff --git a/modules/touch/src/TouchMarker.cpp b/modules/touch/src/TouchMarker.cpp index 2876b09e5b..3d98c8db12 100644 --- a/modules/touch/src/TouchMarker.cpp +++ b/modules/touch/src/TouchMarker.cpp @@ -43,7 +43,16 @@ namespace openspace { TouchMarker::TouchMarker() : properties::PropertyOwner("TouchMarker") , _visible("TouchMarkers visible", "Toggle visibility of markers", true) - , _radiusSize("Marker size", "Set marker size in radius", 10, 0, 30) + , _radiusSize("Marker size", "Marker radius", 30, 0, 50) + , _transparency("Transparency of marker", "Marker transparency", 0.8, 0, 1.0) + , _thickness("Thickness of marker", "Marker thickness", 1.0, 0, 2.0) + , _color( + "MarkerColor", + "Marker color", + glm::vec3(204.f / 255.f, 51.f / 255.f, 51.f / 255.f), + glm::vec3(0.f), + glm::vec3(1.f) + ) , _texturePath("texturePath", "Color Texture") , _shader(nullptr) , _texture(nullptr) @@ -52,9 +61,13 @@ TouchMarker::TouchMarker() { addProperty(_visible); addProperty(_radiusSize); + addProperty(_transparency); + addProperty(_thickness); + _color.setViewOption(properties::Property::ViewOptions::Color); + addProperty(_color); addProperty(_texturePath); _texturePath.onChange(std::bind(&TouchMarker::loadTexture, this)); - + //_texturePath.set("?"); } @@ -106,8 +119,17 @@ void TouchMarker::render(const std::vector list) { _texture->bind(); _shader->setUniform("texture1", unit);*/ _shader->setUniform("radius", _radiusSize); - + _shader->setUniform("transparency", _transparency); + _shader->setUniform("thickness", _thickness); + _shader->setUniform("color", _color.value()); + + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_SCISSOR_TEST); glEnable(GL_PROGRAM_POINT_SIZE); // Enable gl_PointSize in vertex shader + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); glBindVertexArray(_quad); glDrawArrays(GL_POINTS, 0, _numFingers); @@ -143,18 +165,17 @@ void TouchMarker::loadTexture() { void TouchMarker::createVertexList(const std::vector list) { _numFingers = list.size(); - std::vector vertexData(_numFingers * 2, 0); - GLfloat vertexTest[MAX_FINGERS]; + GLfloat vertexData[MAX_FINGERS]; int i = 0; for (const TUIO::TuioCursor& c : list) { - vertexTest[i] = 2 * (c.getX() - 0.5); - vertexTest[i + 1] = -2 * (c.getY() - 0.5); + vertexData[i] = 2 * (c.getX() - 0.5); + vertexData[i + 1] = -2 * (c.getY() - 0.5); i += 2; } glBindVertexArray(_quad); glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); - glBufferData(GL_ARRAY_BUFFER, sizeof(vertexTest), vertexTest, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer( 0,