Compare commits
4 commits
a39effb4b2
...
9a7969b63a
Author | SHA1 | Date | |
---|---|---|---|
9a7969b63a | |||
b564918e1c | |||
618b75792b | |||
2ce6365b3f |
9 changed files with 48 additions and 41 deletions
|
@ -1,7 +1,7 @@
|
|||
cmake_minimum_required(VERSION 3.22)
|
||||
project(perlin-shadows)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
include_directories(src)
|
||||
|
||||
|
|
10
src/camera.h
10
src/camera.h
|
@ -26,16 +26,18 @@ class Camera {
|
|||
aspect_ = static_cast<float>(width) / static_cast<float>(height);
|
||||
}
|
||||
|
||||
const glm::vec3 &getPosition() const { return position_; }
|
||||
[[nodiscard]] const glm::vec3 &getPosition() const { return position_; }
|
||||
|
||||
private:
|
||||
glm::vec3 look_vector() const {
|
||||
[[nodiscard]] glm::vec3 look_vector() const {
|
||||
return rotateZ(rotateY(glm::vec3(1., 0., 0.), rotation_.y), rotation_.z);
|
||||
}
|
||||
glm::vec3 up_vector() const {
|
||||
[[nodiscard]] glm::vec3 up_vector() const {
|
||||
return rotateZ(rotateY(glm::vec3(0., 0., 1.), rotation_.y), rotation_.z);
|
||||
}
|
||||
glm::vec3 normal_vector() const { return cross(up_vector(), look_vector()); }
|
||||
[[nodiscard]] glm::vec3 normal_vector() const {
|
||||
return cross(up_vector(), look_vector());
|
||||
}
|
||||
|
||||
glm::vec3 position_{kGeographyShort / 2,
|
||||
kGeographyLong *kGeographyCountLong / 2,
|
||||
|
|
|
@ -10,8 +10,8 @@ class Geography final : public Renderable {
|
|||
|
||||
void Randomize(bool);
|
||||
|
||||
float min() const { return height_.min(); }
|
||||
float max() const { return height_.max(); }
|
||||
[[nodiscard]] float min() const { return height_.min(); }
|
||||
[[nodiscard]] float max() const { return height_.max(); }
|
||||
|
||||
protected:
|
||||
void SetData() override;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "grid.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "constants.h"
|
||||
|
@ -59,10 +58,10 @@ glm::vec3 Grid::normal_at(const size_t x, const size_t y,
|
|||
|
||||
const auto x_diff =
|
||||
glm::vec3(static_cast<float>(high_x - low_x), 0,
|
||||
amplification * (get(high_x, y) - get(low_x, y)));
|
||||
amplification * ((*this)[high_x, y] - (*this)[low_x, y]));
|
||||
const auto y_diff =
|
||||
glm::vec3(0, static_cast<float>(high_y - low_y),
|
||||
amplification * (get(x, high_y) - get(x, low_y)));
|
||||
amplification * ((*this)[x, high_y] - (*this)[x, low_y]));
|
||||
return normalize(cross(x_diff, y_diff));
|
||||
}
|
||||
|
||||
|
@ -136,12 +135,11 @@ Grid *Grid::PerlinNoise(const int globalX, const int globalY,
|
|||
|
||||
// Interpolates between the dot_major results of the four grid vectors
|
||||
// around the current point
|
||||
const auto val = Interpolate(
|
||||
(*grid)[x, y] = Interpolate(
|
||||
x_offset,
|
||||
Interpolate(y_offset, dot_major(false, false),
|
||||
dot_major(false, true)),
|
||||
Interpolate(y_offset, dot_major(true, false), dot_major(true, true)));
|
||||
grid->set(x, y, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
34
src/grid.h
34
src/grid.h
|
@ -17,33 +17,37 @@ constexpr std::size_t index(const std::size_t x, const std::size_t y) {
|
|||
|
||||
class Grid {
|
||||
public:
|
||||
float get(const std::size_t x, const std::size_t y) const {
|
||||
float &operator[](const std::size_t x, const std::size_t y) {
|
||||
return (*data_)[index(x, y)];
|
||||
}
|
||||
void set(const std::size_t x, const std::size_t y, const float value) const {
|
||||
(*data_)[index(x, y)] = value;
|
||||
float &operator[](const std::size_t x, const std::size_t y) const {
|
||||
return (*data_)[index(x, y)];
|
||||
}
|
||||
|
||||
Grid operator+(const Grid &) const;
|
||||
[[nodiscard]] Grid operator+(const Grid &) const;
|
||||
void operator+=(const Grid &) const;
|
||||
Grid operator-() const;
|
||||
Grid operator-(const Grid &) const;
|
||||
[[nodiscard]] Grid operator-() const;
|
||||
[[nodiscard]] Grid operator-(const Grid &) const;
|
||||
void operator-=(const Grid &) const;
|
||||
Grid operator*(float) const;
|
||||
[[nodiscard]] Grid operator*(float) const;
|
||||
void operator*=(float) const;
|
||||
Grid operator/(float) const;
|
||||
[[nodiscard]] Grid operator/(float) const;
|
||||
void operator/=(float) const;
|
||||
|
||||
glm::vec3 normal_at(std::size_t, std::size_t, float = 1.) const;
|
||||
[[nodiscard]] glm::vec3 normal_at(std::size_t, std::size_t, float = 1.) const;
|
||||
|
||||
static Grid *PerlinNoise(int, int, std::size_t);
|
||||
[[nodiscard]] static Grid *PerlinNoise(int, int, std::size_t);
|
||||
|
||||
std::array<Vertex, kTotalVertices> *vertices() const;
|
||||
static std::array<unsigned int, kTotalIndices> *indices();
|
||||
[[nodiscard]] std::array<Vertex, kTotalVertices> *vertices() const;
|
||||
[[nodiscard]] static std::array<unsigned int, kTotalIndices> *indices();
|
||||
static void RandomizeBase() { base_random_ = device_() << 4; }
|
||||
|
||||
float min() const { return *std::min_element(data_->begin(), data_->end()); }
|
||||
float max() const { return *std::max_element(data_->begin(), data_->end()); }
|
||||
[[nodiscard]] float min() const {
|
||||
return *std::min_element(data_->begin(), data_->end());
|
||||
}
|
||||
[[nodiscard]] float max() const {
|
||||
return *std::max_element(data_->begin(), data_->end());
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<std::array<float, kGeographyShort * kGeographyLong>> data_{
|
||||
|
@ -54,6 +58,6 @@ class Grid {
|
|||
std::uniform_real_distribution<float> dist_{0, glm::two_pi<float>()};
|
||||
static std::mt19937::result_type base_random_;
|
||||
|
||||
float RandomAngle() { return dist_(engine_); }
|
||||
[[nodiscard]] float RandomAngle() { return dist_(engine_); }
|
||||
void AngleSeed(const std::mt19937::result_type seed) { engine_.seed(seed); }
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// Based on Ken Perlin's smoother step function:
|
||||
// https://en.wikipedia.org/wiki/Smoothstep#Variations Returns value in range
|
||||
// [0, 1]
|
||||
constexpr float SmootherStep(const float x) {
|
||||
[[nodiscard]] constexpr float SmootherStep(const float x) {
|
||||
if (x < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ constexpr float SmootherStep(const float x) {
|
|||
// Interpolates between two doubles
|
||||
// If x <= 0 returns bound_0, if x >= 1 returns bound_1,
|
||||
// otherwise smoothly transitions between the two
|
||||
constexpr float Interpolate(const float x, const float bound_0,
|
||||
[[nodiscard]] constexpr float Interpolate(const float x, const float bound_0,
|
||||
const float bound_1) {
|
||||
return bound_0 + SmootherStep(x) * (bound_1 - bound_0);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class PointLight final : public Renderable {
|
|||
void LoadData(const Shader *) const;
|
||||
void GenerateCubeMaps(const std::vector<Renderable *> &) const;
|
||||
|
||||
GLuint getDepthTexture() const { return depth_; }
|
||||
[[nodiscard]] GLuint getDepthTexture() const { return depth_; }
|
||||
void setPosition(const glm::vec3 &pos) {
|
||||
pos_ = pos;
|
||||
CleanUp();
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "shader.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
|
22
src/shader.h
22
src/shader.h
|
@ -15,22 +15,26 @@ class Shader {
|
|||
Shader(const std::string &, const std::string &, const std::string & = "");
|
||||
~Shader();
|
||||
|
||||
bool CopyDataToUniform(const glm::mat4 &, const std::string &) const;
|
||||
bool CopyDataToUniform(int, const glm::mat4 *, const std::string &) const;
|
||||
bool CopyDataToUniform(const glm::vec4 &, const std::string &) const;
|
||||
bool CopyDataToUniform(const glm::vec3 &, const std::string &) const;
|
||||
bool CopyDataToUniform(float, const std::string &) const;
|
||||
bool CopyDataToUniform(int, const std::string &) const;
|
||||
bool CopyDataToUniform(bool, const std::string &) const;
|
||||
[[nodiscard]] bool CopyDataToUniform(const glm::mat4 &,
|
||||
const std::string &) const;
|
||||
[[nodiscard]] bool CopyDataToUniform(int, const glm::mat4 *,
|
||||
const std::string &) const;
|
||||
[[nodiscard]] bool CopyDataToUniform(const glm::vec4 &,
|
||||
const std::string &) const;
|
||||
[[nodiscard]] bool CopyDataToUniform(const glm::vec3 &,
|
||||
const std::string &) const;
|
||||
[[nodiscard]] bool CopyDataToUniform(float, const std::string &) const;
|
||||
[[nodiscard]] bool CopyDataToUniform(int, const std::string &) const;
|
||||
[[nodiscard]] bool CopyDataToUniform(bool, const std::string &) const;
|
||||
|
||||
void PrintStatus() const;
|
||||
|
||||
GLuint id() const { return id_; }
|
||||
[[nodiscard]] GLuint id() const { return id_; }
|
||||
|
||||
private:
|
||||
GLuint id_;
|
||||
|
||||
static GLuint CompileShader(const std::string &, GLenum);
|
||||
[[nodiscard]] static GLuint CompileShader(const std::string &, GLenum);
|
||||
|
||||
static void CheckGLError(const std::string &);
|
||||
static void CheckProgramivError(GLuint, GLenum, const std::string &);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue