12 #ifndef hifi_render_utils_HighlightStyle_h
13 #define hifi_render_utils_HighlightStyle_h
15 #include <glm/vec3.hpp>
16 #include <glm/gtx/string_cast.hpp>
20 #include <ViewFrustum.h>
25 class HighlightStyle {
28 glm::vec3 color { 1.0f, 0.7f, 0.2f };
31 RGBA(
const glm::vec3& c,
float a) : color(c), alpha(a) {}
33 std::string toString()
const {
return glm::to_string(color) +
" " + std::to_string(alpha); }
36 RGBA _outlineUnoccluded { { 1.0f, 0.7f, 0.2f }, 0.9f };
37 RGBA _outlineOccluded { { 1.0f, 0.7f, 0.2f }, 0.9f };
38 RGBA _fillUnoccluded { { 0.2f, 0.7f, 1.0f }, 0.0f };
39 RGBA _fillOccluded { { 0.2f, 0.7f, 1.0f }, 0.0f };
41 float _outlineWidth { 2.0f };
42 bool _isOutlineSmooth {
false };
44 bool isFilled()
const {
45 return _fillUnoccluded.alpha > 5e-3f || _fillOccluded.alpha > 5e-3f;
48 std::string toString()
const {
49 return _outlineUnoccluded.toString() + _outlineOccluded.toString() + _fillUnoccluded.toString() +
50 _fillOccluded.toString() + std::to_string(_outlineWidth) + std::to_string(_isOutlineSmooth);
53 static HighlightStyle calculateOutlineStyle(uint8_t mode,
float outlineWidth,
const glm::vec3& outline,
54 const glm::vec3& position,
const ViewFrustum& viewFrustum,
size_t screenHeight) {
56 style._outlineUnoccluded.color = outline;
57 style._outlineUnoccluded.alpha = 1.0f;
58 style._outlineOccluded.alpha = 0.0f;
59 style._fillUnoccluded.alpha = 0.0f;
60 style._fillOccluded.alpha = 0.0f;
61 style._isOutlineSmooth =
false;
66 glm::vec4 viewPos = glm::inverse(viewFrustum.getView()) * glm::vec4(position, 1.0f);
68 const glm::mat4& projection = viewFrustum.getProjection();
69 glm::vec4 p1 = projection * (viewPos + glm::vec4(0.0f, 0.5f * outlineWidth, 0.0f, 0.0f));
71 glm::vec4 p2 = projection * (viewPos - glm::vec4(0.0f, 0.5f * outlineWidth, 0.0f, 0.0f));
74 style._outlineWidth = floor(0.5f * (
float)screenHeight * fabs(p1.y - p2.y));
76 style._outlineWidth = floor(outlineWidth * (
float)screenHeight);