Compare commits

..

No commits in common. "9a7969b63a37ddfa1a35ba738b9a783aa5a4932d" and "a39effb4b24214b10c47fec4b340279013c64e65" have entirely different histories.

9 changed files with 41 additions and 48 deletions

View file

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.22)
project(perlin-shadows)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD 14)
include_directories(src)

View file

@ -26,18 +26,16 @@ class Camera {
aspect_ = static_cast<float>(width) / static_cast<float>(height);
}
[[nodiscard]] const glm::vec3 &getPosition() const { return position_; }
const glm::vec3 &getPosition() const { return position_; }
private:
[[nodiscard]] glm::vec3 look_vector() const {
glm::vec3 look_vector() const {
return rotateZ(rotateY(glm::vec3(1., 0., 0.), rotation_.y), rotation_.z);
}
[[nodiscard]] glm::vec3 up_vector() const {
glm::vec3 up_vector() const {
return rotateZ(rotateY(glm::vec3(0., 0., 1.), rotation_.y), rotation_.z);
}
[[nodiscard]] glm::vec3 normal_vector() const {
return cross(up_vector(), look_vector());
}
glm::vec3 normal_vector() const { return cross(up_vector(), look_vector()); }
glm::vec3 position_{kGeographyShort / 2,
kGeographyLong *kGeographyCountLong / 2,

View file

@ -10,8 +10,8 @@ class Geography final : public Renderable {
void Randomize(bool);
[[nodiscard]] float min() const { return height_.min(); }
[[nodiscard]] float max() const { return height_.max(); }
float min() const { return height_.min(); }
float max() const { return height_.max(); }
protected:
void SetData() override;

View file

@ -1,6 +1,7 @@
#include "grid.h"
#include <glm/glm.hpp>
#include <iostream>
#include <vector>
#include "constants.h"
@ -58,10 +59,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 * ((*this)[high_x, y] - (*this)[low_x, y]));
amplification * (get(high_x, y) - get(low_x, y)));
const auto y_diff =
glm::vec3(0, static_cast<float>(high_y - low_y),
amplification * ((*this)[x, high_y] - (*this)[x, low_y]));
amplification * (get(x, high_y) - get(x, low_y)));
return normalize(cross(x_diff, y_diff));
}
@ -135,11 +136,12 @@ Grid *Grid::PerlinNoise(const int globalX, const int globalY,
// Interpolates between the dot_major results of the four grid vectors
// around the current point
(*grid)[x, y] = Interpolate(
const auto val = 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);
}
}

View file

@ -17,37 +17,33 @@ constexpr std::size_t index(const std::size_t x, const std::size_t y) {
class Grid {
public:
float &operator[](const std::size_t x, const std::size_t y) {
float get(const std::size_t x, const std::size_t y) const {
return (*data_)[index(x, y)];
}
float &operator[](const std::size_t x, const std::size_t y) const {
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;
}
[[nodiscard]] Grid operator+(const Grid &) const;
Grid operator+(const Grid &) const;
void operator+=(const Grid &) const;
[[nodiscard]] Grid operator-() const;
[[nodiscard]] Grid operator-(const Grid &) const;
Grid operator-() const;
Grid operator-(const Grid &) const;
void operator-=(const Grid &) const;
[[nodiscard]] Grid operator*(float) const;
Grid operator*(float) const;
void operator*=(float) const;
[[nodiscard]] Grid operator/(float) const;
Grid operator/(float) const;
void operator/=(float) const;
[[nodiscard]] glm::vec3 normal_at(std::size_t, std::size_t, float = 1.) const;
glm::vec3 normal_at(std::size_t, std::size_t, float = 1.) const;
[[nodiscard]] static Grid *PerlinNoise(int, int, std::size_t);
static Grid *PerlinNoise(int, int, std::size_t);
[[nodiscard]] std::array<Vertex, kTotalVertices> *vertices() const;
[[nodiscard]] static std::array<unsigned int, kTotalIndices> *indices();
std::array<Vertex, kTotalVertices> *vertices() const;
static std::array<unsigned int, kTotalIndices> *indices();
static void RandomizeBase() { base_random_ = device_() << 4; }
[[nodiscard]] float min() const {
return *std::min_element(data_->begin(), data_->end());
}
[[nodiscard]] float max() const {
return *std::max_element(data_->begin(), data_->end());
}
float min() const { return *std::min_element(data_->begin(), data_->end()); }
float max() const { return *std::max_element(data_->begin(), data_->end()); }
private:
std::unique_ptr<std::array<float, kGeographyShort * kGeographyLong>> data_{
@ -58,6 +54,6 @@ class Grid {
std::uniform_real_distribution<float> dist_{0, glm::two_pi<float>()};
static std::mt19937::result_type base_random_;
[[nodiscard]] float RandomAngle() { return dist_(engine_); }
float RandomAngle() { return dist_(engine_); }
void AngleSeed(const std::mt19937::result_type seed) { engine_.seed(seed); }
};

View file

@ -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]
[[nodiscard]] constexpr float SmootherStep(const float x) {
constexpr float SmootherStep(const float x) {
if (x < 0) {
return 0;
}
@ -17,7 +17,7 @@
// Interpolates between two doubles
// If x <= 0 returns bound_0, if x >= 1 returns bound_1,
// otherwise smoothly transitions between the two
[[nodiscard]] constexpr float Interpolate(const float x, const float bound_0,
const float bound_1) {
constexpr float Interpolate(const float x, const float bound_0,
const float bound_1) {
return bound_0 + SmootherStep(x) * (bound_1 - bound_0);
}

View file

@ -16,7 +16,7 @@ class PointLight final : public Renderable {
void LoadData(const Shader *) const;
void GenerateCubeMaps(const std::vector<Renderable *> &) const;
[[nodiscard]] GLuint getDepthTexture() const { return depth_; }
GLuint getDepthTexture() const { return depth_; }
void setPosition(const glm::vec3 &pos) {
pos_ = pos;
CleanUp();

View file

@ -1,5 +1,6 @@
#include "shader.h"
#include <fstream>
#include <iostream>
#include <string>

View file

@ -15,26 +15,22 @@ class Shader {
Shader(const std::string &, const std::string &, const std::string & = "");
~Shader();
[[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;
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;
void PrintStatus() const;
[[nodiscard]] GLuint id() const { return id_; }
GLuint id() const { return id_; }
private:
GLuint id_;
[[nodiscard]] static GLuint CompileShader(const std::string &, GLenum);
static GLuint CompileShader(const std::string &, GLenum);
static void CheckGLError(const std::string &);
static void CheckProgramivError(GLuint, GLenum, const std::string &);