mirror of
https://github.com/Kbz-8/42_vox.git
synced 2026-01-11 14:43:34 +00:00
adding noise generator base class
This commit is contained in:
@@ -27,9 +27,8 @@ void Chunk::GenerateChunk()
|
|||||||
{
|
{
|
||||||
for(std::uint32_t z = 0; z < CHUNK_SIZE.z; z++)
|
for(std::uint32_t z = 0; z < CHUNK_SIZE.z; z++)
|
||||||
{
|
{
|
||||||
// Implement noise here
|
std::uint32_t height = m_world.GetNoiseGenerator().GetHeight(m_position + Scop::Vec2i(x, z));
|
||||||
std::uint32_t height = std::abs(std::sin((float)m_offset.x / 20.0f) * std::cos((float)m_offset.y / 20.0f) * 60.0f) + 1;
|
for(std::uint32_t y = 0; y < std::min(height, CHUNK_SIZE.y); y++)
|
||||||
for(std::uint32_t y = 0; y < height; y++)
|
|
||||||
m_data[x][z][y] = 1;
|
m_data[x][z][y] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
Application/Noise.cpp
git.filemode.normal_file
6
Application/Noise.cpp
git.filemode.normal_file
@@ -0,0 +1,6 @@
|
|||||||
|
#include <Noise.h>
|
||||||
|
|
||||||
|
[[nodiscard]] std::uint32_t Noise::GetHeight(Scop::Vec2i pos)
|
||||||
|
{
|
||||||
|
return std::abs(std::sin((float)pos.x / 20.0f) * std::cos((float)pos.y / 20.0f) * 60.0f) + 1;
|
||||||
|
}
|
||||||
18
Application/Noise.h
git.filemode.normal_file
18
Application/Noise.h
git.filemode.normal_file
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef NOISE_H
|
||||||
|
#define NOISE_H
|
||||||
|
|
||||||
|
#include <ScopMaths.h>
|
||||||
|
|
||||||
|
class Noise
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Noise() = default;
|
||||||
|
|
||||||
|
[[nodiscard]] std::uint32_t GetHeight(Scop::Vec2i pos);
|
||||||
|
|
||||||
|
~Noise() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <Chunk.h>
|
#include <Chunk.h>
|
||||||
#include <Utils.h>
|
#include <Utils.h>
|
||||||
|
#include <Noise.h>
|
||||||
|
|
||||||
constexpr std::uint8_t RENDER_DISTANCE = 12;
|
constexpr std::uint8_t RENDER_DISTANCE = 12;
|
||||||
constexpr std::uint8_t CHUNKS_UPLOAD_PER_FRAME = 3;
|
constexpr std::uint8_t CHUNKS_UPLOAD_PER_FRAME = 3;
|
||||||
@@ -27,6 +28,7 @@ class World
|
|||||||
[[nodiscard]] inline Scop::Scene& GetScene() noexcept { return m_scene; }
|
[[nodiscard]] inline Scop::Scene& GetScene() noexcept { return m_scene; }
|
||||||
[[nodiscard]] inline std::shared_ptr<Scop::Material> GetBlockMaterial() const { return p_block_material; }
|
[[nodiscard]] inline std::shared_ptr<Scop::Material> GetBlockMaterial() const { return p_block_material; }
|
||||||
[[nodiscard]] Scop::NonOwningPtr<Chunk> GetChunk(Scop::Vec2i position);
|
[[nodiscard]] Scop::NonOwningPtr<Chunk> GetChunk(Scop::Vec2i position);
|
||||||
|
[[nodiscard]] Noise& GetNoiseGenerator() noexcept { return m_noise; }
|
||||||
|
|
||||||
~World() = default;
|
~World() = default;
|
||||||
|
|
||||||
@@ -36,6 +38,7 @@ class World
|
|||||||
void Upload();
|
void Upload();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Noise m_noise;
|
||||||
std::unordered_map<Scop::Vec2i, Chunk> m_chunks;
|
std::unordered_map<Scop::Vec2i, Chunk> m_chunks;
|
||||||
ThreadSafeQueue<std::reference_wrapper<Chunk>> m_chunks_to_upload;
|
ThreadSafeQueue<std::reference_wrapper<Chunk>> m_chunks_to_upload;
|
||||||
std::shared_ptr<Scop::Material> p_block_material;
|
std::shared_ptr<Scop::Material> p_block_material;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ fn main(input: VertOut) -> FragOut
|
|||||||
const ambient = vec3[f32](0.1, 0.1, 0.1);
|
const ambient = vec3[f32](0.1, 0.1, 0.1);
|
||||||
const directional_color = vec3[f32](5.0, 5.0, 5.0);
|
const directional_color = vec3[f32](5.0, 5.0, 5.0);
|
||||||
const specular_strength = 0.5;
|
const specular_strength = 0.5;
|
||||||
let directional_vector = normalize(vec3[f32](0.85, 0.8, 0.75));
|
let directional_vector = normalize(vec3[f32](1.0, 0.8, 0.75));
|
||||||
|
|
||||||
let directional: f32 = max(dot(input.transformed_norm.xyz, directional_vector), 0.0);
|
let directional: f32 = max(dot(input.transformed_norm.xyz, directional_vector), 0.0);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user