Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added res/cubemaps/HDR_placeholder.hdr
Binary file not shown.
8 changes: 4 additions & 4 deletions res/models/test2.mtl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd ../textures/Test/test_basecolor.png
map_Ns ../textures/Test/test_roughness.png
map_refl ../textures/Test/test_metallic.png
map_Bump -bm 1.000000 ../textures/Test/test_normal.png
map_Kd ../textures/test_basecolor.png
map_Ns ../textures/test_roughness.png
map_refl ../textures/test_metallic.png
map_Bump -bm 1.000000 ../textures/test_normal.png
16 changes: 16 additions & 0 deletions res/shaders/BackgroundFragmentShader.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#version 330 core
out vec4 FragColor;
in vec3 World_position;

uniform samplerCube environmentMap;

void main()
{
vec3 envColor = texture(environmentMap, World_position).rgb;

// HDR tonemap and gamma correct
envColor = envColor / (envColor + vec3(1.0));
envColor = pow(envColor, vec3(1.0/2.2));

FragColor = vec4(envColor, 1.0);
}
17 changes: 17 additions & 0 deletions res/shaders/BackgroundVertexShader.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#version 330 core
layout (location = 0) in vec3 aPos;

uniform mat4 projection_matrix;
uniform mat4 view_matrix;

out vec3 World_position;

void main()
{
World_position = aPos;

mat4 rotView = mat4(mat3(view_matrix));
vec4 clipPos = projection_matrix * rotView * vec4(World_position, 1.0);

gl_Position = clipPos.xyww;
}
13 changes: 13 additions & 0 deletions res/shaders/HDRCubemapVertexShader.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#version 330 core
layout (location = 0) in vec3 iv_position;

out vec3 World_position;

uniform mat4 projection_matrix;
uniform mat4 view_matrix;

void main()
{
World_position = iv_position;
gl_Position = projection_matrix * view_matrix * vec4(World_position, 1.0);
}
22 changes: 22 additions & 0 deletions res/shaders/HDREquirectangularToCubemapFragmentShader.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#version 330 core
out vec4 FragColor;
in vec3 World_position;

uniform sampler2D equirectangularMap;

const vec2 invAtan = vec2(0.1591, 0.3183);
vec2 SampleSphericalMap(vec3 v)
{
vec2 uv = vec2(atan(v.z, v.x), asin(v.y));
uv *= invAtan;
uv += 0.5;
return uv;
}

void main()
{
vec2 uv = SampleSphericalMap(normalize(World_position));
vec3 color = texture(equirectangularMap, uv).rgb;

FragColor = vec4(color, 1.0);
}
38 changes: 38 additions & 0 deletions res/shaders/IrradianceConvolutionFragmentShader.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#version 330 core
out vec4 FragColor;
in vec3 World_position;

uniform samplerCube environmentMap;

const float PI = 3.14159265359;

void main()
{
vec3 N = normalize(World_position);

vec3 irradiance = vec3(0.0);

// tangent space calculation from origin point
vec3 up = vec3(0.0, 1.0, 0.0);
vec3 right = normalize(cross(up, N));
up = normalize(cross(N, right));

float sampleDelta = 0.025;
float nrSamples = 0.0;
for(float phi = 0.0; phi < 2.0 * PI; phi += sampleDelta)
{
for(float theta = 0.0; theta < 0.5 * PI; theta += sampleDelta)
{
// spherical to cartesian (in tangent space)
vec3 tangentSample = vec3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
// tangent space to world
vec3 sampleVec = tangentSample.x * right + tangentSample.y * up + tangentSample.z * N;

irradiance += texture(environmentMap, sampleVec).rgb * cos(theta) * sin(theta);
nrSamples++;
}
}
irradiance = PI * irradiance * (1.0 / float(nrSamples));

FragColor = vec4(irradiance, 1.0);
}
35 changes: 27 additions & 8 deletions res/shaders/PBRFragmentShader.frag
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ uniform sampler2D normal_map;
uniform sampler2D metallic_map;
uniform sampler2D roughness_map;
uniform sampler2D ao_map;


// IBL
uniform samplerCube irradiance_map;

const float PI = 3.14159265359;

Expand All @@ -23,6 +27,11 @@ vec3 fresnelSchlick(float cosTheta, vec3 F0)
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
}

vec3 fresnelSchlickRoughness(float cosTheta, vec3 F0, float roughness)
{
return F0 + (max(vec3(1.0 - roughness), F0) - F0) * pow(1.0 - cosTheta, 5.0);
}

float DistributionGGX(vec3 N, vec3 H, float roughness) //funkcja rozk�adu wektor�w normalnych Trowbridge-Reitz GGX
{
float a = roughness * roughness;
Expand Down Expand Up @@ -60,14 +69,16 @@ float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)

void main()
{
vec3 N = normalize(Normal);
vec3 V = normalize(camera_position - World_position);
vec3 R = reflect(-V, N);


vec3 albedo = texture(albedo_map, Texture_coords).rgb;
float metallic = texture(metallic_map, Texture_coords).r;
float roughness = texture(roughness_map, Texture_coords).r;
float ao = texture(ao_map, Texture_coords).r;

vec3 N = normalize(Normal);
vec3 V = normalize(camPos - WorldPos);

vec3 F0 = vec3(0.04);
F0 = mix(F0, albedo, metallic);

Expand All @@ -76,10 +87,10 @@ void main()
for(int i = 0; i < 4; ++i)
{
//radiation
vec3 L = normalize(light_positions[i] - WorldPos);
vec3 L = normalize(light_positions[i] - World_position);
vec3 H = normalize(V + L);

float distance = length(light_positions[i] - WorldPos);
float distance = length(light_positions[i] - World_position);
float attenuation = 1.0 / (distance * distance);
vec3 radiance = light_colors[i] * attenuation;

Expand All @@ -93,7 +104,7 @@ void main()

vec3 numerator = NDF * G * F;
float denominator = 4 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0);
vec3 specular = numerator / max(denominator, 0.001;
vec3 specular = numerator / max(denominator, 0.001);

vec3 kS = F;
vec3 kD = 1.0 - kS;
Expand All @@ -103,12 +114,20 @@ void main()
float NdotL = max(dot(N, L), 0.0);
Lo += (kD * albedo / PI + specular) * radiance * NdotL;
}
vec3 kS = fresnelSchlickRoughness(max(dot(N, V), 0.0), F0, roughness);
vec3 kD = 1.0 - kS;
kD *= 1.0 - metallic;
vec3 irradiance = texture(irradiance_map, N).rgb;
vec3 diffuse = irradiance * albedo;
vec3 ambient = (kD * diffuse) * ao;

vec3 ambient = vec3(0.03) * albedo * ao;
vec3 color = ambient + Lo;
vec3 color = ambient + Lo;

// HDR tonemapping
color = color / (color + vec3(1.0));
// gamma correction
color = pow(color, vec3(1.0/2.2));

FragColor = vec4(color, 1.0);
}

Expand Down
3 changes: 2 additions & 1 deletion res/shaders/PBRVertexShader.vert
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ uniform mat4 projection_matrix;
void main()
{
vec4 mm = model_matrix * vec4(iv_position, 1.0);
gl_Position = projection_matrix * view_matrix * mm;
World_position = vec3(mm);
Normal = normalize(vec3(transpose(inverse(model_matrix)) * vec4(iv_normal, 1.0)));;
Texture_coords = iv_texture;

gl_Position = projection_matrix * view_matrix * mm;
}
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
12 changes: 0 additions & 12 deletions src/headers/Action.h

This file was deleted.

18 changes: 0 additions & 18 deletions src/headers/ActionMappingType.h

This file was deleted.

1 change: 0 additions & 1 deletion src/headers/Collider.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ namespace Components
void Update() override;
void Destroy() override;
void UpdateColliders();
void PredictColliders();
};
}

Expand Down
1 change: 1 addition & 0 deletions src/headers/GamepadAxisType.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum class GamepadAxisType
LEFT = 0,
RIGHT = 2,
TRIGGERS = 4,
KEYBOARD = 6
};

} // namespace Input
Expand Down
34 changes: 34 additions & 0 deletions src/headers/HDRCubemap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef HDRCUBEMAP_H
#define HDRCUBEMAP_H

#include "glad/glad.h"
#include "string"
#include <iostream>
#include "Camera.h"
#include "Shader.h"
#include "Texture.h"
#include "GLFW/glfw3.h"

class HDRCubemap
{
public:
std::string path_;
std::shared_ptr<Shader> BackgroundShader_;
std::shared_ptr<Shader> EquirectangularToCubemapShader_;
std::shared_ptr<Shader> IrrandanceShader_;

unsigned int cubeVAO = 0;
unsigned int cubeVBO = 0;
unsigned int envCubemap = 0;
unsigned int irradianceMap = 0;

HDRCubemap(const std::string& path, std::shared_ptr<Shader> BackgroundShade,
std::shared_ptr<Shader> EquirectangularToCubemapShader, std::shared_ptr<Shader> IrrandanceShader);
~HDRCubemap() = default;

void LoadHDRimg(GLFWwindow* window, std::shared_ptr<llr::Camera> camera);
void RenderCube();

};

#endif // !HDRCUBEMAP_H
42 changes: 18 additions & 24 deletions src/headers/InputManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "InputObserver.h"
#include "GamepadAxisType.h"
#include "ActionMappingType.h"

#include <memory>
#include <iostream>
Expand All @@ -16,7 +15,19 @@
namespace Input
{

static const glm::vec2 axis_directions[] = {glm::vec2(0.0f, -1.0f), glm::vec2(0.0f, 1.0f), glm::vec2(-1.0f, 0.0f), glm::vec2(1.0f, 0.0f)};
static std::unordered_map<int, std::array<int, 4>> axis_keyboard_mappings =
{
{GLFW_JOYSTICK_1, {GLFW_KEY_W, GLFW_KEY_S, GLFW_KEY_A, GLFW_KEY_D}},
{GLFW_JOYSTICK_2, {GLFW_KEY_UP, GLFW_KEY_DOWN, GLFW_KEY_LEFT, GLFW_KEY_RIGHT}}
};

static const glm::vec2 axis_directions[] = {glm::vec2(0.0f, 1.0f), glm::vec2(0.0f, -1.0f), glm::vec2(-1.0f, 0.0f), glm::vec2(1.0f, 0.0f)};

static std::unordered_map<int, std::vector<int>> button_keyboard_mappings =
{
{GLFW_JOYSTICK_1, {GLFW_KEY_E}},
{GLFW_JOYSTICK_2, {GLFW_KEY_SLASH}}
};

class InputManager
{
Expand Down Expand Up @@ -50,38 +61,21 @@ class InputManager

// Input stuff
private:
std::unordered_map<int, std::vector<std::shared_ptr<InputObserver>>> observers_;
std::vector<std::pair<InputObserver *, int>> observers_;
std::unordered_map<int, GLFWgamepadstate> old_gamepad_states_;
std::unordered_map<int, bool> keyboard_state;

std::unordered_map<int, std::unordered_map<Action, ActionMappingType>> keyboard_mappings;
std::unordered_map<int, std::unordered_map<Action, ActionMappingType>> gamepad_mappings;

static void JoystickStateCallback(int jid, int event);

void UpdateGamepadState(int gamepadID);
void UpdateKeyboardState(int gamepadID);

public:
float deadzone_ = 0.1f;

void AddObserver(int gamepadID, std::shared_ptr<InputObserver> observer);
void RemoveObserver(int gamepadID, std::shared_ptr<InputObserver> observer);
void NotifyAction(int gamepadID, Action action, State state);
void AddObserver(InputObserver *observer, int gamepadID);
void RemoveObserver(InputObserver *observer);
void NotifyAxisChange(int gamepadID, GamepadAxisType axis_type, glm::vec2 state);
void NotifyButtonChange(int gamepadID, int buttonID, bool state);

void Update();

glm::vec2 SafeNormalize(glm::vec2 vector)
{
if (glm::length(vector) > 0.0f)
{
return glm::normalize(vector);
}
else
{
return glm::vec2(0.0f);
}
}
};

}; // namespace Input
Expand Down
Loading