trackbar track-width semantic update + gamma setting trackbar

This commit is contained in:
MihailRis 2024-04-25 06:00:35 +03:00
parent b1a79e3a6e
commit 8be0d157c2
11 changed files with 30 additions and 26 deletions

View File

@ -1,4 +1,4 @@
function create_setting(id, name, step, track_width, postfix)
function create_setting(id, name, step, postfix)
local info = core.get_setting_info(id)
if postfix == nil then
postfix = ""
@ -10,7 +10,7 @@ function create_setting(id, name, step, track_width, postfix)
min=info.min,
max=info.max,
step=step,
track_width=track_width,
track_width=12,
postfix=postfix
}))
end
@ -31,10 +31,11 @@ function create_checkbox(id, name)
end
function on_open()
create_setting("chunks.load-distance", "Load Distance", 1, 3)
create_setting("chunks.load-speed", "Load Speed", 1, 1)
create_setting("graphics.fog-curve", "Fog Curve", 0.1, 2)
create_setting("camera.fov", "FOV", 1, 4, "°")
create_setting("chunks.load-distance", "Load Distance", 1)
create_setting("chunks.load-speed", "Load Speed", 1)
create_setting("graphics.fog-curve", "Fog Curve", 0.1)
create_setting("graphics.gamma", "Gamma", 0.05)
create_setting("camera.fov", "FOV", 1, "°")
create_checkbox("display.vsync", "V-Sync")
create_checkbox("graphics.backlight", "Backlight")
create_checkbox("camera.shaking", "Camera Shaking")

View File

@ -41,6 +41,7 @@ settings.Load Distance=Дистанция Загрузки
settings.Load Speed=Скорость Загрузки
settings.Fog Curve=Кривая Тумана
settings.Backlight=Подсветка
settings.Gamma=Гамма
settings.V-Sync=Вертикальная Синхронизация
settings.Camera Shaking=Тряска Камеры
settings.Master Volume=Общая Громкость

View File

@ -101,7 +101,7 @@ assetload::postfunc assetload::atlas(
atlas->prepare();
assets->store(atlas, name);
// FIXME
// TODO
for (const auto& file : names) {
animation(assets, paths, "textures", file, atlas);
}

View File

@ -28,6 +28,7 @@ SettingsHandler::SettingsHandler(EngineSettings& settings) {
map.emplace("graphics.fog-curve", &settings.graphics.fogCurve);
map.emplace("graphics.backlight", &settings.graphics.backlight);
map.emplace("graphics.gamma", &settings.graphics.gamma);
}
std::unique_ptr<dynamic::Value> SettingsHandler::getValue(const std::string& name) const {
@ -128,7 +129,7 @@ toml::Wrapper* create_wrapper(EngineSettings& settings) {
camera.add("sensitivity", &*settings.camera.sensitivity);
toml::Section& graphics = wrapper->add("graphics");
graphics.add("gamma", &settings.graphics.gamma);
graphics.add("gamma", &*settings.graphics.gamma);
graphics.add("fog-curve", &*settings.graphics.fogCurve);
graphics.add("backlight", &*settings.graphics.backlight);
graphics.add("frustum-culling", &settings.graphics.frustumCulling);

View File

@ -9,6 +9,7 @@
#include "../../voxels/ChunksStorage.h"
#include "../../lighting/Lightmap.h"
#include "../../frontend/ContentGfxCache.h"
#include "../../settings.h"
#include <glm/glm.hpp>
@ -23,7 +24,7 @@ BlocksRenderer::BlocksRenderer(
size_t capacity,
const Content* content,
const ContentGfxCache* cache,
const EngineSettings& settings
const EngineSettings* settings
) : content(content),
vertexOffset(0),
indexOffset(0),
@ -448,7 +449,7 @@ void BlocksRenderer::render(const voxel* voxels) {
void BlocksRenderer::build(const Chunk* chunk, const ChunksStorage* chunks) {
this->chunk = chunk;
voxelsBuffer->setPosition(chunk->x * CHUNK_W - 1, 0, chunk->z * CHUNK_D - 1);
chunks->getVoxels(voxelsBuffer, settings.graphics.backlight.get());
chunks->getVoxels(voxelsBuffer, settings->graphics.backlight.get());
overflow = false;
vertexOffset = 0;
indexOffset = indexSize = 0;

View File

@ -6,7 +6,6 @@
#include <glm/glm.hpp>
#include "../../voxels/voxel.h"
#include "../../typedefs.h"
#include "../../settings.h"
class Content;
class Mesh;
@ -16,6 +15,7 @@ class Chunks;
class VoxelsVolume;
class ChunksStorage;
class ContentGfxCache;
struct EngineSettings;
struct UVRegion;
class BlocksRenderer {
@ -35,7 +35,7 @@ class BlocksRenderer {
const Block* const* blockDefsCache;
const ContentGfxCache* const cache;
const EngineSettings& settings;
const EngineSettings* settings;
void vertex(const glm::vec3& coord, float u, float v, const glm::vec4& light);
void index(int a, int b, int c, int d, int e, int f);
@ -90,7 +90,7 @@ class BlocksRenderer {
glm::vec4 pickSoftLight(float x, float y, float z, const glm::ivec3& right, const glm::ivec3& up) const;
void render(const voxel* voxels);
public:
BlocksRenderer(size_t capacity, const Content* content, const ContentGfxCache* cache, const EngineSettings& settings);
BlocksRenderer(size_t capacity, const Content* content, const ContentGfxCache* cache, const EngineSettings* settings);
virtual ~BlocksRenderer();
void build(const Chunk* chunk, const ChunksStorage* chunks);

View File

@ -4,6 +4,7 @@
#include "../../graphics/core/Mesh.hpp"
#include "../../voxels/Chunk.h"
#include "../../world/Level.h"
#include "../../settings.h"
#include <iostream>
#include <glm/glm.hpp>
@ -20,7 +21,7 @@ public:
RendererWorker(
Level* level,
const ContentGfxCache* cache,
const EngineSettings& settings
const EngineSettings* settings
) : level(level),
renderer(RENDERER_CAPACITY, level->content, cache, settings)
{}
@ -34,7 +35,7 @@ public:
ChunksRenderer::ChunksRenderer(
Level* level,
const ContentGfxCache* cache,
const EngineSettings& settings
const EngineSettings* settings
) : level(level),
threadPool(
"chunks-render-pool",

View File

@ -10,13 +10,13 @@
#include "../../voxels/Block.h"
#include "../../voxels/ChunksStorage.h"
#include "../../util/ThreadPool.hpp"
#include "../../settings.h"
class Mesh;
class Chunk;
class Level;
class BlocksRenderer;
class ContentGfxCache;
struct EngineSettings;
struct RendererResult {
glm::ivec2 key;
@ -34,7 +34,7 @@ public:
ChunksRenderer(
Level* level,
const ContentGfxCache* cache,
const EngineSettings& settings
const EngineSettings* settings
);
virtual ~ChunksRenderer();

View File

@ -45,7 +45,7 @@ WorldRenderer::WorldRenderer(Engine* engine, LevelFrontend* frontend, Player* pl
renderer = std::make_unique<ChunksRenderer>(
level,
frontend->getContentGfxCache(),
engine->getSettings()
&engine->getSettings()
);
batch3d = std::make_unique<Batch3D>(4096);
@ -154,7 +154,7 @@ void WorldRenderer::renderLevel(
shader->use();
shader->uniformMatrix("u_proj", camera->getProjection());
shader->uniformMatrix("u_view", camera->getView());
shader->uniform1f("u_gamma", settings.graphics.gamma);
shader->uniform1f("u_gamma", settings.graphics.gamma.get());
shader->uniform1f("u_fogFactor", fogFactor);
shader->uniform1f("u_fogCurve", settings.graphics.fogCurve.get());
shader->uniform1f("u_dayTime", level->getWorld()->daytime);

View File

@ -33,12 +33,11 @@ void TrackBar::draw(const GfxContext* pctx, Assets* assets) {
batch->setColor(hover ? hoverColor : color);
batch->rect(pos.x, pos.y, size.x, size.y);
float width = size.x;
float t = (value - min) / (max-min+trackWidth*step);
float width = size.x - trackWidth;
float t = (value - min) / (max-min);
batch->setColor(trackColor);
int actualWidth = size.x * (trackWidth / (max-min+trackWidth*step) * step);
batch->rect(pos.x + width * t, pos.y, actualWidth, size.y);
batch->rect(pos.x + width * t, pos.y, trackWidth, size.y);
}
void TrackBar::setSupplier(doublesupplier supplier) {
@ -51,9 +50,9 @@ void TrackBar::setConsumer(doubleconsumer consumer) {
void TrackBar::mouseMove(GUI*, int x, int y) {
glm::vec2 pos = calcPos();
value = x;
value = x - trackWidth/2;
value -= pos.x;
value = (value)/size.x * (max-min+trackWidth*step);
value = (value)/(size.x-trackWidth) * (max-min);
value += min;
value = (value > max) ? max : value;
value = (value < min) ? min : value;

View File

@ -60,7 +60,7 @@ struct GraphicsSettings {
/// @brief Fog opacity is calculated as `pow(depth*k, fogCurve)` where k depends on chunksLoadDistance.
/// 1.0 is linear, 2.0 is quadratic
NumberSetting fogCurve {1.6f, 1.0f, 6.0f};
float gamma = 1.0f;
NumberSetting gamma = {1.0f, 0.5f, 2.0f};
/// @brief Enable blocks backlight to prevent complete darkness
FlagSetting backlight = {true};
/// @brief Enable chunks frustum culling