add 'sky_tint', 'clouds_tint', 'min_sky_light' weather parameters

This commit is contained in:
MihailRis 2026-02-12 20:27:29 +03:00
parent 1194379f99
commit e037462615
22 changed files with 80 additions and 31 deletions

View file

@ -218,7 +218,7 @@ CloudsRenderer::CloudsRenderer() {
CloudsMap map({w, h, d}, voxels);
volumeRenderer.build(map);
testMeshes[layer] = std::make_unique<Mesh<ChunkVertex>>(volumeRenderer.createMesh());
meshes[layer] = std::make_unique<Mesh<ChunkVertex>>(volumeRenderer.createMesh());
}
}
@ -232,13 +232,7 @@ void CloudsRenderer::draw(
const Camera& camera,
int quality
) {
float clouds = weather.clouds();
shader.uniform4f(
"u_tint",
glm::vec4(
1.0f - clouds * 0.5, 1.0f - clouds * 0.45, 1.0f - clouds * 0.4, 1.0f
)
);
shader.uniform4f("u_tint", glm::vec4(weather.cloudsTint(), 1.0f));
float scale = 8;
float totalWidth = WIDTH * scale;
@ -248,7 +242,7 @@ void CloudsRenderer::draw(
int cellZ = glm::floor(camera.position.z / totalDepth + 0.5f);
float speed = 4.0f;
for (int i = 0; i < std::min<int>(quality, testMeshes.size()); i++) {
for (int i = 0; i < std::min<int>(quality, meshes.size()); i++) {
float speedX = glm::sin(i * 0.3f + 0.4f) * speed / (i + 1);
float speedZ = -glm::cos(i * 0.3f + 0.4f) * speed / (i + 1);
for (int x = -2; x <= 2; x++) {
@ -268,7 +262,7 @@ void CloudsRenderer::draw(
shader.uniform1f("u_fogFactor", fogFactor * 0.03f);
shader.uniform1f("u_fogCurve", 0.7f - 0.3f);
shader.uniformMatrix("u_model", matrix);
testMeshes[i]->draw();
meshes[i]->draw();
}
}
}

View file

@ -22,5 +22,5 @@ public:
int quality
);
private:
std::array<std::unique_ptr<Mesh<ChunkVertex>>, 2> testMeshes;
std::array<std::unique_ptr<Mesh<ChunkVertex>>, 2> meshes;
};

View file

@ -151,7 +151,7 @@ void PrecipitationRenderer::render(
glm::cross(glm::vec3(0, 1, 0), face.right),
FACE_SIZE,
light_at(chunks, pos.x, y, pos.z),
glm::vec3(3.0f),
glm::vec3(1.0f),
calc_uv(pos, face.right, timer, weather)
);
}

View file

@ -170,7 +170,7 @@ void Skybox::draw(
drawStars(angle, opacity);
}
void Skybox::refresh(const DrawContext& pctx, float t, float mie, uint quality) {
void Skybox::refresh(const DrawContext& pctx, float t, float mie, const glm::vec3& tint, const glm::vec3& hightlight, uint quality) {
frameid++;
float dayTime = t;
DrawContext ctx = pctx.sub();
@ -201,11 +201,13 @@ void Skybox::refresh(const DrawContext& pctx, float t, float mie, uint quality)
shader.uniform1i("u_quality", quality);
shader.uniform1f("u_mie", mie);
shader.uniform3f("u_tint", tint);
shader.uniform3f("u_hightlight", hightlight);
shader.uniform1f("u_fog", mie - 1.0f);
shader.uniform3f("u_lightDir", lightDir);
shader.uniform1f("u_dayTime", dayTime);
if (glm::abs(mie-prevMie) + glm::abs(t-prevT) >= 0.01) {
if (glm::abs(mie-prevMie) + glm::abs(t-prevT) + glm::abs(prevHighlight.r - hightlight.r) >= 0.01) {
for (uint face = 0; face < 6; face++) {
refreshFace(face, cubemap);
}
@ -215,6 +217,7 @@ void Skybox::refresh(const DrawContext& pctx, float t, float mie, uint quality)
}
prevMie = mie;
prevT = t;
prevHighlight = hightlight;
cubemap->unbind();
glActiveTexture(GL_TEXTURE0);

View file

@ -49,6 +49,7 @@ class Skybox {
float prevMie = -1.0f;
float prevT = -1.0f;
float sunAltitude = 45.0f;
glm::vec3 prevHighlight {1.0f};
glm::mat4 rotation;
void drawStars(float angle, float opacity);
@ -68,7 +69,7 @@ public:
float fog
);
void refresh(const DrawContext& pctx, float t, float mie, uint quality);
void refresh(const DrawContext& pctx, float t, float mie, const glm::vec3& tint, const glm::vec3& hightlight, uint quality);
void bind() const;
void unbind() const;
bool isReady() const {

View file

@ -126,6 +126,7 @@ static void setup_weather(Shader& shader, const Weather& weather) {
shader.uniform1f("u_weatherFogOpacity", weather.fogOpacity());
shader.uniform1f("u_weatherFogDencity", weather.fogDencity());
shader.uniform1f("u_weatherFogCurve", weather.fogCurve());
shader.uniform3f("u_minSkyLight", weather.minSkyLight());
}
static void setup_camera(Shader& shader, const Camera& camera) {
@ -348,7 +349,15 @@ void WorldRenderer::renderFrame(
clouds = glm::max(worldInfo.fog, clouds);
float mie = 1.0f + glm::max(worldInfo.fog, clouds * 0.5f) * 2.0f;
skybox->refresh(pctx, worldInfo.daytime, mie, 4);
float random = rand() / static_cast<float>(RAND_MAX);
skybox->refresh(
pctx,
worldInfo.daytime,
mie,
weather.skyTint(),
weather.highlight * random,
4
);
chunksRenderer->update();
@ -402,15 +411,14 @@ void WorldRenderer::renderFrame(
linesShader.uniformMatrix("u_projview", projView);
lineBatch->flush();
skybox->bind();
// Translucent blocks
{
auto sctx = ctx.sub();
sctx.setCullFace(true);
skybox->bind();
translucentShader.use();
setupWorldShader(translucentShader, camera, settings, fogFactor);
chunksRenderer->drawSortedMeshes(camera, translucentShader);
skybox->unbind();
}
// Weather effects
@ -429,6 +437,7 @@ void WorldRenderer::renderFrame(
precipitation->render(camera, *weather);
}
}
skybox->unbind();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}