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>
23 class HighlightStyle {
26 glm::vec3 color { 1.0f, 0.7f, 0.2f };
29 RGBA(
const glm::vec3& c,
float a) : color(c), alpha(a) {}
31 std::string toString()
const {
return glm::to_string(color) +
" " + std::to_string(alpha); }
34 RGBA _outlineUnoccluded { { 1.0f, 0.7f, 0.2f }, 0.9f };
35 RGBA _outlineOccluded { { 1.0f, 0.7f, 0.2f }, 0.9f };
36 RGBA _fillUnoccluded { { 0.2f, 0.7f, 1.0f }, 0.0f };
37 RGBA _fillOccluded { { 0.2f, 0.7f, 1.0f }, 0.0f };
39 float _outlineWidth { 2.0f };
40 bool _isOutlineSmooth {
false };
42 bool isFilled()
const {
43 return _fillUnoccluded.alpha > 5e-3f || _fillOccluded.alpha > 5e-3f;
46 std::string toString()
const {
47 return _outlineUnoccluded.toString() + _outlineOccluded.toString() + _fillUnoccluded.toString() +
48 _fillOccluded.toString() + std::to_string(_outlineWidth) + std::to_string(_isOutlineSmooth);
51 static HighlightStyle calculateOutlineStyle(uint8_t mode,
float outlineWidth,
const glm::vec3& outline,
52 const glm::vec3& position,
const ViewFrustum& viewFrustum,
size_t screenHeight) {
54 style._outlineUnoccluded.color = outline;
55 style._outlineUnoccluded.alpha = 1.0f;
56 style._outlineOccluded.alpha = 0.0f;
57 style._fillUnoccluded.alpha = 0.0f;
58 style._fillOccluded.alpha = 0.0f;
59 style._isOutlineSmooth =
false;
64 glm::vec4 viewPos = glm::inverse(viewFrustum.getView()) * glm::vec4(position, 1.0f);
66 const glm::mat4& projection = viewFrustum.getProjection();
67 glm::vec4 p1 = projection * (viewPos + glm::vec4(0.0f, 0.5f * outlineWidth, 0.0f, 0.0f));
69 glm::vec4 p2 = projection * (viewPos - glm::vec4(0.0f, 0.5f * outlineWidth, 0.0f, 0.0f));
72 style._outlineWidth = floor(0.5f * (
float)screenHeight * fabs(p1.y - p2.y));
74 style._outlineWidth = floor(outlineWidth * (
float)screenHeight);