add 'xray_opacity' NotePreset property

This commit is contained in:
MihailRis 2024-11-15 00:38:41 +03:00
parent 3a1e90f517
commit ef644ca56d
6 changed files with 30 additions and 15 deletions

View File

@ -30,7 +30,8 @@ function on_hud_open()
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, scale=0.005,
color={0, 0, 0, 1}, color={0, 0, 0, 1},
displayMode="static_billboard" display_mode="static_billboard",
xray_opacity=0.2
}) })
end end

View File

@ -16,12 +16,13 @@ TextsRenderer::TextsRenderer(
: batch(batch), assets(assets), frustum(frustum) { : batch(batch), assets(assets), frustum(frustum) {
} }
void TextsRenderer::renderText( void TextsRenderer::renderNote(
const TextNote& note, const TextNote& note,
const DrawContext& context, const DrawContext& context,
const Camera& camera, const Camera& camera,
const EngineSettings& settings, const EngineSettings& settings,
bool hudVisible bool hudVisible,
bool frontLayer
) { ) {
const auto& text = note.getText(); const auto& text = note.getText();
const auto& preset = note.getPreset(); const auto& preset = note.getPreset();
@ -31,12 +32,18 @@ void TextsRenderer::renderText(
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) {
return; return;
} }
auto& font = assets.require<Font>("normal"); float opacity = 1.0f;
if (frontLayer) {
if (preset.xrayOpacity <= 0.0001f) {
return;
}
opacity = preset.xrayOpacity;
}
const auto& font = assets.require<Font>("normal");
glm::vec3 xvec {1, 0, 0}; glm::vec3 xvec {1, 0, 0};
glm::vec3 yvec {0, 1, 0}; glm::vec3 yvec {0, 1, 0};
@ -53,15 +60,14 @@ void TextsRenderer::renderText(
yvec = camera.up; yvec = camera.up;
} }
} }
if (preset.displayMode != NoteDisplayMode::PROJECTED) { if (preset.displayMode != NoteDisplayMode::PROJECTED) {
if (!frustum.isBoxVisible(pos - xvec * (width * 0.5f), if (!frustum.isBoxVisible(pos - xvec * (width * 0.5f),
pos + xvec * (width * 0.5f))) { pos + xvec * (width * 0.5f))) {
return; return;
} }
} }
auto color = preset.color;
batch.setColor(preset.color); batch.setColor(glm::vec4(color.r, color.g, color.b, color.a * opacity));
font.draw( font.draw(
batch, batch,
text, text,
@ -71,7 +77,7 @@ void TextsRenderer::renderText(
); );
} }
void TextsRenderer::renderTexts( void TextsRenderer::render(
const DrawContext& context, const DrawContext& context,
const Camera& camera, const Camera& camera,
const EngineSettings& settings, const EngineSettings& settings,
@ -85,7 +91,7 @@ void TextsRenderer::renderTexts(
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& [id, note] : notes) {
renderText(*note, context, camera, settings, hudVisible); renderNote(*note, context, camera, settings, hudVisible, frontLayer);
} }
batch.flush(); batch.flush();
} }

View File

@ -21,17 +21,18 @@ class TextsRenderer {
std::unordered_map<u64id_t, std::unique_ptr<TextNote>> notes; std::unordered_map<u64id_t, std::unique_ptr<TextNote>> notes;
u64id_t nextNote = 1; u64id_t nextNote = 1;
void renderText( void renderNote(
const TextNote& note, const TextNote& note,
const DrawContext& context, const DrawContext& context,
const Camera& camera, const Camera& camera,
const EngineSettings& settings, const EngineSettings& settings,
bool hudVisible bool hudVisible,
bool frontLayer
); );
public: public:
TextsRenderer(Batch3D& batch, const Assets& assets, const Frustum& frustum); TextsRenderer(Batch3D& batch, const Assets& assets, const Frustum& frustum);
void renderTexts( void render(
const DrawContext& context, const DrawContext& context,
const Camera& camera, const Camera& camera,
const EngineSettings& settings, const EngineSettings& settings,

View File

@ -139,7 +139,7 @@ void WorldRenderer::renderLevel(
bool pause, bool pause,
bool hudVisible bool hudVisible
) { ) {
texts->renderTexts(ctx, camera, settings, hudVisible, false); texts->render(ctx, camera, settings, hudVisible, false);
bool culling = engine->getSettings().graphics.frustumCulling.get(); bool culling = engine->getSettings().graphics.frustumCulling.get();
float fogFactor = float fogFactor =
@ -332,6 +332,10 @@ void WorldRenderer::draw(
} }
} }
} }
{
DrawContext ctx = wctx.sub();
texts->render(ctx, camera, settings, hudVisible, true);
}
renderBlockOverlay(wctx); renderBlockOverlay(wctx);
} }

View File

@ -34,7 +34,8 @@ dv::value NotePreset::serialize() const {
{"display", to_string(displayMode)}, {"display", to_string(displayMode)},
{"color", dv::to_value(color)}, {"color", dv::to_value(color)},
{"scale", scale}, {"scale", scale},
{"render_distance", renderDistance} {"render_distance", renderDistance},
{"xray_opacity", xrayOpacity},
}); });
} }
@ -47,4 +48,5 @@ void NotePreset::deserialize(const dv::value& src) {
} }
src.at("scale").get(scale); src.at("scale").get(scale);
src.at("render_distance").get(renderDistance); src.at("render_distance").get(renderDistance);
src.at("xray_opacity").get(xrayOpacity);
} }

View File

@ -21,6 +21,7 @@ struct NotePreset : public Serializable {
glm::vec4 color {1.0f}; glm::vec4 color {1.0f};
float scale = 1.0f; float scale = 1.0f;
float renderDistance = 10.0f; float renderDistance = 10.0f;
float xrayOpacity = 0.0f;
dv::value serialize() const override; dv::value serialize() const override;
void deserialize(const dv::value& src) override; void deserialize(const dv::value& src) override;