add 'projected' display mode support
This commit is contained in:
@@ -28,10 +28,8 @@ function on_hud_open()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
note = gfx.text3d.new({0.5, 99.5, 0.0015}, "Segmentation fault", {
|
note = gfx.text3d.new({0.5, 99.5, 0.0015}, "Segmentation fault", {
|
||||||
scale=0.005,
|
|
||||||
color={0, 0, 0, 1},
|
color={0, 0, 0, 1},
|
||||||
display_mode="static_billboard",
|
display="projected"
|
||||||
xray_opacity=0.2
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "maths/util.hpp"
|
#include "maths/util.hpp"
|
||||||
#include "assets/Assets.hpp"
|
#include "assets/Assets.hpp"
|
||||||
#include "window/Camera.hpp"
|
#include "window/Camera.hpp"
|
||||||
|
#include "window/Window.hpp"
|
||||||
#include "maths/FrustumCulling.hpp"
|
#include "maths/FrustumCulling.hpp"
|
||||||
#include "graphics/core/Font.hpp"
|
#include "graphics/core/Font.hpp"
|
||||||
#include "graphics/core/Batch3D.hpp"
|
#include "graphics/core/Batch3D.hpp"
|
||||||
@@ -22,22 +23,23 @@ void TextsRenderer::renderNote(
|
|||||||
const Camera& camera,
|
const Camera& camera,
|
||||||
const EngineSettings& settings,
|
const EngineSettings& settings,
|
||||||
bool hudVisible,
|
bool hudVisible,
|
||||||
bool frontLayer
|
bool frontLayer,
|
||||||
|
bool projected
|
||||||
) {
|
) {
|
||||||
const auto& text = note.getText();
|
const auto& text = note.getText();
|
||||||
const auto& preset = note.getPreset();
|
const auto& preset = note.getPreset();
|
||||||
const auto& pos = note.getPosition();
|
auto pos = note.getPosition();
|
||||||
|
|
||||||
if (util::distance2(pos, camera.position) >
|
if (util::distance2(pos, camera.position) >
|
||||||
util::sqr(preset.renderDistance / camera.zoom)) {
|
util::sqr(preset.renderDistance / camera.zoom)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Projected notes are displayed on the front layer only
|
// Projected notes are displayed on the front layer only
|
||||||
if (preset.displayMode == NoteDisplayMode::PROJECTED) {
|
if ((preset.displayMode == NoteDisplayMode::PROJECTED) != projected) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
float opacity = 1.0f;
|
float opacity = 1.0f;
|
||||||
if (frontLayer) {
|
if (frontLayer && preset.displayMode != NoteDisplayMode::PROJECTED) {
|
||||||
if (preset.xrayOpacity <= 0.0001f) {
|
if (preset.xrayOpacity <= 0.0001f) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -65,6 +67,13 @@ void TextsRenderer::renderNote(
|
|||||||
pos + xvec * (width * 0.5f))) {
|
pos + xvec * (width * 0.5f))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
auto projpos = camera.getProjView() * glm::vec4(pos, 1.0f);
|
||||||
|
pos = projpos;
|
||||||
|
pos /= pos.z;
|
||||||
|
pos.z = 0;
|
||||||
|
xvec = {2.0f/Window::width, 0, 0};
|
||||||
|
yvec = {0, 2.0f/Window::height, 0};
|
||||||
}
|
}
|
||||||
auto color = preset.color;
|
auto color = preset.color;
|
||||||
batch.setColor(glm::vec4(color.r, color.g, color.b, color.a * opacity));
|
batch.setColor(glm::vec4(color.r, color.g, color.b, color.a * opacity));
|
||||||
@@ -90,10 +99,20 @@ void TextsRenderer::render(
|
|||||||
shader.uniformMatrix("u_projview", camera.getProjView());
|
shader.uniformMatrix("u_projview", camera.getProjView());
|
||||||
shader.uniformMatrix("u_apply", glm::mat4(1.0f));
|
shader.uniformMatrix("u_apply", glm::mat4(1.0f));
|
||||||
batch.begin();
|
batch.begin();
|
||||||
for (const auto& [id, note] : notes) {
|
for (const auto& [_, note] : notes) {
|
||||||
renderNote(*note, context, camera, settings, hudVisible, frontLayer);
|
renderNote(*note, context, camera, settings, hudVisible, frontLayer, false);
|
||||||
}
|
}
|
||||||
batch.flush();
|
batch.flush();
|
||||||
|
if (frontLayer) {
|
||||||
|
shader.uniformMatrix(
|
||||||
|
"u_projview",
|
||||||
|
glm::mat4(1.0f)
|
||||||
|
);
|
||||||
|
for (const auto& [_, note] : notes) {
|
||||||
|
renderNote(*note, context, camera, settings, hudVisible, true, true);
|
||||||
|
}
|
||||||
|
batch.flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u64id_t TextsRenderer::add(std::unique_ptr<TextNote> note) {
|
u64id_t TextsRenderer::add(std::unique_ptr<TextNote> note) {
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ class TextsRenderer {
|
|||||||
const Camera& camera,
|
const Camera& camera,
|
||||||
const EngineSettings& settings,
|
const EngineSettings& settings,
|
||||||
bool hudVisible,
|
bool hudVisible,
|
||||||
bool frontLayer
|
bool frontLayer,
|
||||||
|
bool projected
|
||||||
);
|
);
|
||||||
public:
|
public:
|
||||||
TextsRenderer(Batch3D& batch, const Assets& assets, const Frustum& frustum);
|
TextsRenderer(Batch3D& batch, const Assets& assets, const Frustum& frustum);
|
||||||
|
|||||||
Reference in New Issue
Block a user