snow test

This commit is contained in:
MihailRis 2025-01-13 19:02:08 +03:00
parent fa6e2e1b1d
commit d36eb85dba
3 changed files with 28 additions and 15 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 716 B

View File

@ -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<Texture>("misc/rain");
auto& texture = assets.require<Texture>("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
)
);

View File

@ -20,6 +20,8 @@ namespace util {
class PseudoRandom {
unsigned short seed;
public:
PseudoRandom(unsigned short seed) : seed(seed) {}
PseudoRandom() {
seed = static_cast<unsigned short>(time(0));
}