diff --git a/res/textures/misc/snow.png b/res/textures/misc/snow.png index 810806ff..a687e841 100644 Binary files a/res/textures/misc/snow.png and b/res/textures/misc/snow.png differ diff --git a/src/graphics/render/PrecipitationRenderer.cpp b/src/graphics/render/PrecipitationRenderer.cpp index b8369ae2..25762f01 100644 --- a/src/graphics/render/PrecipitationRenderer.cpp +++ b/src/graphics/render/PrecipitationRenderer.cpp @@ -4,6 +4,7 @@ #include "assets/assets_util.hpp" #include "graphics/core/Shader.hpp" #include "graphics/core/Texture.hpp" +#include "maths/util.hpp" #include "window/Camera.hpp" #include "world/Level.hpp" #include "voxels/Chunks.hpp" @@ -41,30 +42,34 @@ int PrecipitationRenderer::getHeightAt(int x, int z) { void PrecipitationRenderer::render(const Camera& camera, float delta) { - timer += delta * 1.6f; + timer += delta * 0.5f; batch->begin(); + util::PseudoRandom random(0); + int x = glm::floor(camera.position.x); int y = glm::floor(camera.position.y); int z = glm::floor(camera.position.z); - auto& texture = assets.require("misc/rain"); + auto& texture = assets.require("misc/snow"); texture.setMipMapping(false); batch->setTexture(&texture, {}); const auto& front = camera.front; glm::vec2 size {1, 40}; - glm::vec4 light(1, 1, 1, 0); + glm::vec4 light(0, 0, 0, 1); - float horizontal = 0.0f; + float horizontal = 0.5f; - int radius = 5; - int depth = 8; - float scale = 0.1f; + int radius = 6; + int depth = 12; + float scale = 0.4f; int quads = 0; float k = 21.41149; for (int lx = -radius; lx <= radius; lx++) { for (int lz = -depth; lz < 0; lz++) { + random.setSeed(lx + x, lz + z); + float hspeed = (random.randFloat() * 2.0f - 1.0f) * horizontal; glm::vec3 pos { x + lx + 0.5f, glm::max(y - 20, getHeightAt(x + lx, z + lz)) + 21, @@ -77,9 +82,9 @@ void PrecipitationRenderer::render(const Camera& camera, float delta) { light, glm::vec3(1.0f), UVRegion( - (lx + x) * scale + timer * horizontal, + (lx + x) * scale + timer * hspeed, timer + y * scale + (z + lz) * k, - (lx + x + 1) * scale + timer * horizontal, + (lx + x + 1) * scale + timer * hspeed, timer + (40 + y) * scale + (z + lz) * k ) ); @@ -87,6 +92,8 @@ void PrecipitationRenderer::render(const Camera& camera, float delta) { } for (int lx = -radius; lx <= radius; lx++) { for (int lz = depth; lz > 0; lz--) { + random.setSeed(lx + x, lz + z); + float hspeed = (random.randFloat() * 2.0f - 1.0f) * horizontal; glm::vec3 pos { x + lx + 0.5f, glm::max(y - 20, getHeightAt(x + lx, z + lz)) + 21, @@ -99,9 +106,9 @@ void PrecipitationRenderer::render(const Camera& camera, float delta) { light, glm::vec3(1.0f), UVRegion( - (lx + x) * scale + timer * horizontal, + (lx + x) * scale + timer * hspeed, timer + y * scale + (z + lz) * k, - (lx + x + 1) * scale + timer * horizontal, + (lx + x + 1) * scale + timer * hspeed, timer + (40 + y) * scale + (z + lz) * k ) ); @@ -109,6 +116,8 @@ void PrecipitationRenderer::render(const Camera& camera, float delta) { } for (int lz = -radius; lz <= radius; lz++) { for (int lx = -depth; lx < 0; lx++) { + random.setSeed(lx + x, lz + z); + float hspeed = (random.randFloat() * 2.0f - 1.0f) * horizontal; glm::vec3 pos { x + lx + 0.5f, glm::max(y - 20, getHeightAt(x + lx, z + lz)) + 21, @@ -121,9 +130,9 @@ void PrecipitationRenderer::render(const Camera& camera, float delta) { light, glm::vec3(1.0f), UVRegion( - (lz + z) * scale + timer * horizontal, + (lz + z) * scale + timer * hspeed, timer + y * scale + (x + lx) * k, - (lz + z + 1) * scale + timer * horizontal, + (lz + z + 1) * scale + timer * hspeed, timer + (40 + y) * scale + (x + lx) * k ) ); @@ -131,6 +140,8 @@ void PrecipitationRenderer::render(const Camera& camera, float delta) { } for (int lz = -radius; lz <= radius; lz++) { for (int lx = depth; lx > 0; lx--) { + random.setSeed(lx + x, lz + z); + float hspeed = (random.randFloat() * 2.0f - 1.0f) * horizontal; glm::vec3 pos { x + lx + 0.5f, glm::max(y - 20, getHeightAt(x + lx, z + lz)) + 21, @@ -143,9 +154,9 @@ void PrecipitationRenderer::render(const Camera& camera, float delta) { light, glm::vec3(1.0f), UVRegion( - (lz + z) * scale + timer * horizontal, + (lz + z) * scale + timer * hspeed, timer + y * scale + (x + lx) * k, - (lz + z + 1) * scale + timer * horizontal, + (lz + z + 1) * scale + timer * hspeed, timer + (40 + y) * scale + (x + lx) * k ) ); diff --git a/src/maths/util.hpp b/src/maths/util.hpp index df39cf41..f417384d 100644 --- a/src/maths/util.hpp +++ b/src/maths/util.hpp @@ -20,6 +20,8 @@ namespace util { class PseudoRandom { unsigned short seed; public: + PseudoRandom(unsigned short seed) : seed(seed) {} + PseudoRandom() { seed = static_cast(time(0)); }