Commit 00d67401 authored by unknown's avatar unknown
Browse files

Temporarily fixed GBuffer Framebuffers not resizing correctly.

parent af30eccc
......@@ -86,7 +86,7 @@ void main()
// Now we can add the previously calculated environment reflection or refraction
vec4 reflection_tint = is_transparent ? diffuse : specular;
final_color_part = mix(final_color_part, reflection_tint * environment_reflect, shininess);
// final_color_part = mix(final_color_part, reflection_tint * environment_reflect, shininess);
}
// Add resulting color to the finished image, and compensate for multisampling
......
......@@ -139,20 +139,48 @@ bool sampleLight(const in LightWithShadowmap light_and_map, const in vec3 positi
return u_light_sample[light_and_map.light.data.light_type % 4](light_and_map, position, normal, camera, point_to_light, color);
}
float chiGGX(float v)
{
return v > 0 ? 1 : 0;
}
float GGX_Distribution(vec3 n, vec3 h, float alpha)
{
float NoH = dot(n,h);
float alpha2 = alpha * alpha;
float NoH2 = NoH * NoH;
float den = NoH2 * alpha2 + (1 - NoH2);
return (chiGGX(NoH) * alpha2) / ( 3.141592f * den * den );
}
float GGX_PartialGeometryTerm(vec3 v, vec3 n, vec3 h, float alpha)
{
float VoH2 = clamp(dot(v,h), 0, 1);
float chi = chiGGX( VoH2 / clamp(dot(v,n), 0, 1) );
VoH2 = VoH2 * VoH2;
float tan2 = ( 1 - VoH2 ) / VoH2;
return (chi * 2) / ( 1 + sqrt( 1 + alpha * alpha * tan2 ) );
}
vec4 phong(const in LightWithShadowmap light_and_map, const in vec3 position, const in vec3 normal, const in vec3 camera, const in vec4 diffuse, const in vec4 specular, float shininess, bool metallic = false)
{
vec4 color = vec4(0, 0, 0, 1);
vec3 point_to_light;
if(light_and_map.sampleLight(position, normal, camera, point_to_light, color)) {
vec3 eye = normalize(camera-position.xyz);
// vec3 half_vector = normalize(eye + point_to_light);
vec3 reflection_vec = normalize(reflect(-point_to_light, normalize(normal.xyz)));
//DIFFUSE
float cos_phi = max(dot(normalize(normal.xyz), normalize(point_to_light)), 0.0f);
// GGX_PartialGeometryTerm(point_to_light, normal, half_vector, 1-shininess);
//SPECULAR
vec3 eye = normalize(camera-position.xyz);
vec3 reflection_vec = normalize(reflect(-point_to_light, normalize(normal.xyz)));
float cos_phi_n = pow(max(dot(reflection_vec, eye), 0.0f), 5+shininess*95);
// float cos_phi_n = GGX_Distribution(normal, half_vector, 1-shininess);
vec4 phong_diffuse = (diffuse * cos_phi * color);
//If the material is metallic, tint the specular color with the diffuse color.
vec4 phong_specular = ((metallic ? diffuse : vec4(1)) * specular * cos_phi_n * color);
......
......@@ -152,7 +152,8 @@ namespace glare
gl::polygonMode(gl::Face::eFrontAndBack, gl::PolygonMode::eLine);
bool cull = gl::isEnabled(gl::EnableParameter::eCullFace);
gl::setEnabled(gl::EnableParameter::eCullFace, false);
glare::core::state::graph_root->draw();
if(glare::core::state::graph_root)
glare::core::state::graph_root->draw();
gl::setEnabled(gl::EnableParameter::eCullFace, cull);
gl::polygonMode(gl::Face::eFrontAndBack, gl::PolygonMode::eFill);
}
......@@ -161,7 +162,8 @@ namespace glare
{
m_gbuffer->activate();
m_skybox->draw();
glare::core::state::graph_root->draw();
if(glare::core::state::graph_root)
glare::core::state::graph_root->draw();
m_gbuffer->deactivate();
m_gbuffer->draw();
}
......
......@@ -20,8 +20,11 @@ namespace glare
PlayerController::~PlayerController()
{
core::Callbacks::removeKeyActionCallback("player_controller" + std::to_string(m_id));
core::Callbacks::removeMouseButtonCallback("player_controller" + std::to_string(m_id));
try {
core::Callbacks::removeKeyActionCallback("player_controller" + std::to_string(m_id));
core::Callbacks::removeMouseButtonCallback("player_controller" + std::to_string(m_id));
}catch(...)
{ }
}
void PlayerController::onKeyAction(controls::Key key, controls::ButtonAction action, controls::KeyMods mods)
......
......@@ -80,11 +80,13 @@ namespace glare
m_height = height;
m_samples = samples;
for (auto &&texture : m_color_attachments)
for (auto &&texture : m_color_attachments) {
is_multisampled ? texture.second->resize(width, height, m_samples) : texture.second->resize(width, height);
}
if (m_depth_attachment)
if (m_depth_attachment) {
is_multisampled ? m_depth_attachment->resize(width, height, m_samples) : m_depth_attachment->resize(width, height);
}
}
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
......
......@@ -17,8 +17,10 @@ namespace glare
std::make_shared<glare::core::Shader>(gl::ShaderType::eFragment, files::shader("screenshader/gbuffer/gbuffer.frag"))
};
m_texture_renderer = std::make_unique<TextureRenderer>(std::make_shared<Program>(shaders));
m_gbuffer_framebuffer = std::make_shared<Framebuffer<TextureMultisampled>>(width, height, samples);
const GLFWvidmode * mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
m_gbuffer_framebuffer = std::make_shared<Framebuffer<TextureMultisampled>>(unsigned(mode->width), unsigned(mode->height), samples);
m_gbuffer_framebuffer->attach(gl::Attachment::eColor0);
m_gbuffer_framebuffer->attach(gl::Attachment::eColor1);
m_gbuffer_framebuffer->attach(gl::Attachment::eColor2);
......@@ -107,8 +109,8 @@ namespace glare
void GBuffer::updateSize(unsigned width, unsigned height, unsigned samples)
{
m_width = width;
m_height = height;
m_width = 100;// width;
m_height = 100;// height;
m_gbuffer_framebuffer->resize(width, height, samples);
m_texture_renderer->shader().uniform("screen.width", m_width);
m_texture_renderer->shader().uniform("screen.height", m_height);
......
......@@ -95,6 +95,7 @@ namespace glare
m_samples = samples;
gl::pixelStorei(gl::PixelStoreAlignment::eUnpack, 1);
gl::textureImage2DMS(m_handle, gl::TextureImageTargetMultisample2D::e2DMultisample, samples, InternalFormat, width, height, false);
}
template <gl::TextureFormat Format, gl::TextureInternalFormat InternalFormat, gl::Type T>
......
......@@ -27,9 +27,12 @@ namespace glare
void update()
{
camera->update();
animation_manager->update();
graph_root->update();
if(camera)
camera->update();
if(animation_manager)
animation_manager->update();
if(graph_root)
graph_root->update();
}
void quit()
......
......@@ -55,6 +55,7 @@ namespace glare
while (!glfwWindowShouldClose(m_main_window))
{
glfwPollEvents();
Time::newFrame();
const double current_time = glfwGetTime();
......@@ -65,7 +66,6 @@ namespace glare
loop_function(delta_time);
glfwPollEvents();
glfwSwapBuffers(m_main_window);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment