mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-07 20:11:50 +00:00
cleanup
This commit is contained in:
parent
895a496f6e
commit
2475a7e8f5
20 changed files with 88 additions and 79 deletions
|
|
@ -96,40 +96,54 @@ void Shadows::setQuality(int quality) {
|
|||
}
|
||||
|
||||
void Shadows::setup(Shader& shader, const Weather& weather) {
|
||||
if (shadows) {
|
||||
const auto& worldInfo = level.getWorld()->getInfo();
|
||||
float cloudsIntensity = glm::max(worldInfo.fog, weather.clouds());
|
||||
float shadowsOpacity = 1.0f - cloudsIntensity;
|
||||
shadowsOpacity *= glm::sqrt(glm::abs(
|
||||
glm::mod((worldInfo.daytime + 0.5f) * 2.0f, 1.0f) * 2.0f - 1.0f
|
||||
));
|
||||
shader.uniform1i("u_screen", 0);
|
||||
shader.uniformMatrix("u_shadowsMatrix[0]", shadowCamera.getProjView());
|
||||
shader.uniformMatrix("u_shadowsMatrix[1]", wideShadowCamera.getProjView());
|
||||
shader.uniform3f("u_sunDir", shadowCamera.front);
|
||||
shader.uniform1i("u_shadowsRes", shadowMap->getResolution());
|
||||
shader.uniform1f("u_shadowsOpacity", shadowsOpacity); // TODO: make it configurable
|
||||
shader.uniform1f("u_shadowsSoftness", 1.0f + cloudsIntensity * 4); // TODO: make it configurable
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + TARGET_SHADOWS0);
|
||||
shader.uniform1i("u_shadows[0]", TARGET_SHADOWS0);
|
||||
glBindTexture(GL_TEXTURE_2D, shadowMap->getDepthMap());
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + TARGET_SHADOWS1);
|
||||
shader.uniform1i("u_shadows[1]", TARGET_SHADOWS1);
|
||||
glBindTexture(GL_TEXTURE_2D, wideShadowMap->getDepthMap());
|
||||
|
||||
glActiveTexture(TEXTURE_MAIN);
|
||||
if (!shadows) {
|
||||
return;
|
||||
}
|
||||
const auto& worldInfo = level.getWorld()->getInfo();
|
||||
float cloudsIntensity = glm::max(worldInfo.fog, weather.clouds());
|
||||
float shadowsOpacity = 1.0f - cloudsIntensity;
|
||||
shadowsOpacity *= glm::sqrt(glm::abs(
|
||||
glm::mod((worldInfo.daytime + 0.5f) * 2.0f, 1.0f) * 2.0f - 1.0f
|
||||
));
|
||||
shader.uniform1i("u_screen", 0);
|
||||
shader.uniformMatrix("u_shadowsMatrix[0]", shadowCamera.getProjView());
|
||||
shader.uniformMatrix("u_shadowsMatrix[1]", wideShadowCamera.getProjView());
|
||||
shader.uniform3f("u_sunDir", shadowCamera.front);
|
||||
shader.uniform1i("u_shadowsRes", shadowMap->getResolution());
|
||||
shader.uniform1f("u_shadowsOpacity", shadowsOpacity); // TODO: make it configurable
|
||||
shader.uniform1f("u_shadowsSoftness", 1.0f + cloudsIntensity * 4); // TODO: make it configurable
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + TARGET_SHADOWS0);
|
||||
shader.uniform1i("u_shadows[0]", TARGET_SHADOWS0);
|
||||
glBindTexture(GL_TEXTURE_2D, shadowMap->getDepthMap());
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + TARGET_SHADOWS1);
|
||||
shader.uniform1i("u_shadows[1]", TARGET_SHADOWS1);
|
||||
glBindTexture(GL_TEXTURE_2D, wideShadowMap->getDepthMap());
|
||||
|
||||
glActiveTexture(TEXTURE_MAIN);
|
||||
}
|
||||
|
||||
void Shadows::refresh(const Camera& camera, const DrawContext& pctx, std::function<void(Camera&)> renderShadowPass) {
|
||||
void Shadows::refresh(
|
||||
const Camera& camera,
|
||||
const DrawContext& pctx,
|
||||
const std::function<void(Camera&)>& renderShadowPass
|
||||
) {
|
||||
static int frameid = 0;
|
||||
if (shadows) {
|
||||
if (frameid % 2 == 0) {
|
||||
generateShadowsMap(camera, pctx, *shadowMap, shadowCamera, 1.0f, renderShadowPass);
|
||||
generateShadowsMap(
|
||||
camera, pctx, *shadowMap, shadowCamera, 1.0f, renderShadowPass
|
||||
);
|
||||
} else {
|
||||
generateShadowsMap(camera, pctx, *wideShadowMap, wideShadowCamera, 3.0f, renderShadowPass);
|
||||
generateShadowsMap(
|
||||
camera,
|
||||
pctx,
|
||||
*wideShadowMap,
|
||||
wideShadowCamera,
|
||||
3.0f,
|
||||
renderShadowPass
|
||||
);
|
||||
}
|
||||
}
|
||||
frameid++;
|
||||
|
|
@ -141,7 +155,7 @@ void Shadows::generateShadowsMap(
|
|||
ShadowMap& shadowMap,
|
||||
Camera& shadowCamera,
|
||||
float scale,
|
||||
std::function<void(Camera&)> renderShadowPass
|
||||
const std::function<void(Camera&)>& renderShadowPass
|
||||
) {
|
||||
auto world = level.getWorld();
|
||||
const auto& worldInfo = world->getInfo();
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class DrawContext;
|
|||
struct EngineSettings;
|
||||
class ShadowMap;
|
||||
|
||||
class Shadows {
|
||||
class Shadows final {
|
||||
public:
|
||||
Shadows(const Level& level);
|
||||
~Shadows();
|
||||
|
|
@ -24,7 +24,7 @@ public:
|
|||
void refresh(
|
||||
const Camera& camera,
|
||||
const DrawContext& pctx,
|
||||
std::function<void(Camera&)> renderShadowPass
|
||||
const std::function<void(Camera&)>& renderShadowPass
|
||||
);
|
||||
private:
|
||||
const Level& level;
|
||||
|
|
@ -41,6 +41,6 @@ private:
|
|||
ShadowMap& shadowMap,
|
||||
Camera& shadowCamera,
|
||||
float scale,
|
||||
std::function<void(Camera&)> renderShadowPass
|
||||
const std::function<void(Camera&)>& renderShadowPass
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ void ChunksRenderer::drawShadowsPass(
|
|||
continue;
|
||||
}
|
||||
glm::ivec2 pos {chunk->x, chunk->z};
|
||||
const auto& found = meshes.find({chunk->x, chunk->z});
|
||||
const auto& found = meshes.find(pos);
|
||||
if (found == meshes.end()) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -250,11 +250,11 @@ void ChunksRenderer::drawShadowsPass(
|
|||
pos.x * CHUNK_W + 0.5f, 0.5f, pos.y * CHUNK_D + 0.5f
|
||||
);
|
||||
|
||||
glm::vec3 min(chunk->x * CHUNK_W, chunk->bottom, chunk->z * CHUNK_D);
|
||||
glm::vec3 min(pos.x * CHUNK_W, chunk->bottom, pos.y * CHUNK_D);
|
||||
glm::vec3 max(
|
||||
chunk->x * CHUNK_W + CHUNK_W,
|
||||
pos.x * CHUNK_W + CHUNK_W,
|
||||
chunk->top,
|
||||
chunk->z * CHUNK_D + CHUNK_D
|
||||
pos.y * CHUNK_D + CHUNK_D
|
||||
);
|
||||
|
||||
if (!frustum.isBoxVisible(min, max)) {
|
||||
|
|
|
|||
|
|
@ -86,16 +86,16 @@ WorldRenderer::WorldRenderer(
|
|||
frontend.getContentGfxCache(),
|
||||
engine.getSettings()
|
||||
)),
|
||||
precipitation(std::make_unique<PrecipitationRenderer>(
|
||||
assets, level, *player.chunks, &engine.getSettings().graphics
|
||||
)),
|
||||
particles(std::make_unique<ParticlesRenderer>(
|
||||
assets, level, *player.chunks, engine.getSettings().graphics
|
||||
)),
|
||||
texts(std::make_unique<TextsRenderer>(*batch3d, assets, *frustumCulling)),
|
||||
blockWraps(
|
||||
std::make_unique<BlockWrapsRenderer>(assets, level, *player.chunks)
|
||||
),
|
||||
precipitation(std::make_unique<PrecipitationRenderer>(
|
||||
assets, level, *player.chunks, &engine.getSettings().graphics
|
||||
)) {
|
||||
) {
|
||||
auto& settings = engine.getSettings();
|
||||
level.events->listen(
|
||||
LevelEventType::CHUNK_HIDDEN,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "commons.hpp"
|
||||
|
||||
#include "typedefs.hpp"
|
||||
|
||||
#include "presets/WeatherPreset.hpp"
|
||||
|
|
@ -16,7 +15,6 @@
|
|||
class Assets;
|
||||
class Batch3D;
|
||||
class BlockWrapsRenderer;
|
||||
class Camera;
|
||||
class ChunksRenderer;
|
||||
class DebugLinesRenderer;
|
||||
class DrawContext;
|
||||
|
|
@ -58,6 +56,7 @@ class WorldRenderer {
|
|||
std::unique_ptr<Skybox> skybox;
|
||||
std::unique_ptr<Shadows> shadowMapping;
|
||||
std::unique_ptr<DebugLinesRenderer> debugLines;
|
||||
std::unique_ptr<PrecipitationRenderer> precipitation;
|
||||
Weather weather {};
|
||||
|
||||
float timer = 0.0f;
|
||||
|
|
@ -102,7 +101,6 @@ public:
|
|||
std::unique_ptr<ParticlesRenderer> particles;
|
||||
std::unique_ptr<TextsRenderer> texts;
|
||||
std::unique_ptr<BlockWrapsRenderer> blockWraps;
|
||||
std::unique_ptr<PrecipitationRenderer> precipitation;
|
||||
std::unique_ptr<NamedSkeletons> skeletons;
|
||||
|
||||
static bool showChunkBorders;
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ GUI::GUI(Engine& engine)
|
|||
|
||||
rootDocument = std::make_unique<UiDocument>(
|
||||
"core:root",
|
||||
uidocscript {},
|
||||
UiDocScript {},
|
||||
std::dynamic_pointer_cast<gui::UINode>(container),
|
||||
nullptr
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue