mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 00:49:19 +02:00
configurable renderer
This commit is contained in:
@@ -92,6 +92,7 @@ set(SOURCES
|
||||
"gl/renderbuffer.cpp"
|
||||
"gl/postfx.cpp"
|
||||
"gl/cubemap.cpp"
|
||||
"gl/glsl_common.cpp"
|
||||
|
||||
"imgui/imgui.cpp"
|
||||
"imgui/imgui_demo.cpp"
|
||||
|
||||
47
Globals.cpp
47
Globals.cpp
@@ -73,16 +73,6 @@ global_settings::ConfigParse(cParser &Parser) {
|
||||
Parser.getTokens(1, false);
|
||||
Parser >> iWindowHeight;
|
||||
}
|
||||
else if (token == "renderwidth")
|
||||
{
|
||||
Parser.getTokens(1, false);
|
||||
Parser >> render_width;
|
||||
}
|
||||
else if (token == "renderheight")
|
||||
{
|
||||
Parser.getTokens(1, false);
|
||||
Parser >> render_height;
|
||||
}
|
||||
else if (token == "heightbase")
|
||||
{
|
||||
|
||||
@@ -339,18 +329,6 @@ global_settings::ConfigParse(cParser &Parser) {
|
||||
Parser.getTokens();
|
||||
Parser >> ScaleSpecularValues;
|
||||
}
|
||||
else if( token == "gfxrenderer" ) {
|
||||
// shadow render toggle
|
||||
std::string gfxrenderer;
|
||||
Parser.getTokens();
|
||||
Parser >> gfxrenderer;
|
||||
BasicRenderer = ( gfxrenderer == "simple" );
|
||||
}
|
||||
else if( token == "shadows" ) {
|
||||
// shadow render toggle
|
||||
Parser.getTokens();
|
||||
Parser >> RenderShadows;
|
||||
}
|
||||
else if( token == "shadowtune" ) {
|
||||
Parser.getTokens( 4, false );
|
||||
Parser
|
||||
@@ -671,6 +649,31 @@ global_settings::ConfigParse(cParser &Parser) {
|
||||
Parser.getTokens( 1 );
|
||||
Parser >> captureonstart;
|
||||
}
|
||||
else if (token == "gfx.framebuffer.width")
|
||||
{
|
||||
Parser.getTokens(1, false);
|
||||
Parser >> render_width;
|
||||
}
|
||||
else if (token == "gfx.framebuffer.height")
|
||||
{
|
||||
Parser.getTokens(1, false);
|
||||
Parser >> render_height;
|
||||
}
|
||||
else if (token == "gfx.shadowmap.enabled")
|
||||
{
|
||||
Parser.getTokens(1);
|
||||
Parser >> gfx_shadowmap_enabled;
|
||||
}
|
||||
else if (token == "gfx.envmap.enabled")
|
||||
{
|
||||
Parser.getTokens(1);
|
||||
Parser >> gfx_envmap_enabled;
|
||||
}
|
||||
else if (token == "gfx.postfx.motionblur.enabled")
|
||||
{
|
||||
Parser.getTokens(1);
|
||||
Parser >> gfx_postfx_motionblur_enabled;
|
||||
}
|
||||
else if (token == "gfx.postfx.motionblur.shutter")
|
||||
{
|
||||
Parser.getTokens(1);
|
||||
|
||||
@@ -108,8 +108,7 @@ struct global_settings {
|
||||
float BaseDrawRange{ 2500.f };
|
||||
int DynamicLightCount{ 8 };
|
||||
bool ScaleSpecularValues{ true };
|
||||
bool BasicRenderer{ false };
|
||||
bool RenderShadows{ true };
|
||||
bool gfx_shadowmap_enabled{ true };
|
||||
struct shadowtune_t {
|
||||
unsigned int map_size{ 2048 };
|
||||
float width{ 250.f }; // no longer used
|
||||
@@ -177,6 +176,8 @@ struct global_settings {
|
||||
bool dds_upper_origin = false;
|
||||
bool captureonstart = true;
|
||||
|
||||
bool gfx_envmap_enabled = true;
|
||||
bool gfx_postfx_motionblur_enabled = true;
|
||||
float gfx_postfx_motionblur_shutter = 0.01f;
|
||||
|
||||
// methods
|
||||
|
||||
@@ -187,7 +187,7 @@ void scroll_callback( GLFWwindow* window, double xoffset, double yoffset )
|
||||
|
||||
if( Global.ctrlState ) {
|
||||
// ctrl + scroll wheel adjusts fov in debug mode
|
||||
Global.FieldOfView = clamp( static_cast<float>( Global.FieldOfView - yoffset * 20.0 / Global.fFpsAverage ), 15.0f, 75.0f );
|
||||
Global.FieldOfView = clamp( static_cast<float>( Global.FieldOfView - yoffset ), 15.0f, 75.0f );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
63
gl/glsl_common.cpp
Normal file
63
gl/glsl_common.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "glsl_common.h"
|
||||
|
||||
std::string gl::glsl_common;
|
||||
|
||||
void gl::glsl_common_setup()
|
||||
{
|
||||
glsl_common =
|
||||
"#define SHADOWMAP_ENABLED " + std::to_string((int)Global.gfx_shadowmap_enabled) + "\n" +
|
||||
"#define ENVMAP_ENABLED " + std::to_string((int)Global.gfx_envmap_enabled) + "\n" +
|
||||
"#define MOTIONBLUR_ENABLED " + std::to_string((int)Global.gfx_postfx_motionblur_enabled) + "\n" +
|
||||
"const uint MAX_LIGHTS = " + std::to_string(MAX_LIGHTS) + "U;\n" +
|
||||
"const uint MAX_PARAMS = " + std::to_string(MAX_PARAMS) + "U;\n" +
|
||||
R"STRING(
|
||||
const uint LIGHT_SPOT = 0U;
|
||||
const uint LIGHT_POINT = 1U;
|
||||
const uint LIGHT_DIR = 2U;
|
||||
|
||||
struct light_s
|
||||
{
|
||||
vec3 pos;
|
||||
uint type;
|
||||
|
||||
vec3 dir;
|
||||
float in_cutoff;
|
||||
|
||||
vec3 color;
|
||||
float out_cutoff;
|
||||
|
||||
float linear;
|
||||
float quadratic;
|
||||
};
|
||||
|
||||
layout(std140) uniform light_ubo
|
||||
{
|
||||
vec3 ambient;
|
||||
float fog_density;
|
||||
|
||||
vec3 fog_color;
|
||||
uint lights_count;
|
||||
|
||||
light_s lights[MAX_LIGHTS];
|
||||
};
|
||||
|
||||
layout (std140) uniform model_ubo
|
||||
{
|
||||
mat4 modelview;
|
||||
mat3 modelviewnormal;
|
||||
vec4 param[MAX_PARAMS];
|
||||
|
||||
mat4 future;
|
||||
float opacity;
|
||||
float emission;
|
||||
};
|
||||
|
||||
layout (std140) uniform scene_ubo
|
||||
{
|
||||
mat4 projection;
|
||||
mat4 lightview;
|
||||
float time;
|
||||
};
|
||||
|
||||
)STRING";
|
||||
}
|
||||
@@ -1,59 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "ubo.h"
|
||||
#include "Globals.h"
|
||||
|
||||
namespace gl
|
||||
{
|
||||
const std::string glsl_common =
|
||||
"const uint MAX_LIGHTS = " + std::to_string(MAX_LIGHTS) + "U;\n" +
|
||||
"const uint MAX_PARAMS = " + std::to_string(MAX_PARAMS) + "U;\n" +
|
||||
"const uint ENVMAP_SIZE = " + std::to_string(ENVMAP_SIZE) + "U;\n" +
|
||||
R"STRING(
|
||||
const uint LIGHT_SPOT = 0U;
|
||||
const uint LIGHT_POINT = 1U;
|
||||
const uint LIGHT_DIR = 2U;
|
||||
|
||||
struct light_s
|
||||
{
|
||||
vec3 pos;
|
||||
uint type;
|
||||
|
||||
vec3 dir;
|
||||
float in_cutoff;
|
||||
|
||||
vec3 color;
|
||||
float out_cutoff;
|
||||
|
||||
float linear;
|
||||
float quadratic;
|
||||
};
|
||||
|
||||
layout(std140) uniform light_ubo
|
||||
{
|
||||
vec3 ambient;
|
||||
float fog_density;
|
||||
|
||||
vec3 fog_color;
|
||||
uint lights_count;
|
||||
|
||||
light_s lights[MAX_LIGHTS];
|
||||
};
|
||||
|
||||
layout (std140) uniform model_ubo
|
||||
{
|
||||
mat4 modelview;
|
||||
mat3 modelviewnormal;
|
||||
vec4 param[MAX_PARAMS];
|
||||
|
||||
mat4 future;
|
||||
float opacity;
|
||||
float emission;
|
||||
};
|
||||
|
||||
layout (std140) uniform scene_ubo
|
||||
{
|
||||
mat4 projection;
|
||||
mat4 lightview;
|
||||
float time;
|
||||
};
|
||||
|
||||
)STRING";
|
||||
extern std::string glsl_common;
|
||||
void glsl_common_setup();
|
||||
}
|
||||
|
||||
220
renderer.cpp
220
renderer.cpp
@@ -75,11 +75,10 @@ void opengl_camera::draw(glm::vec3 const &Offset) const
|
||||
|
||||
bool opengl_renderer::Init(GLFWwindow *Window)
|
||||
{
|
||||
if (!Init_caps())
|
||||
return false;
|
||||
|
||||
if (false == Init_caps())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
WriteLog("preparing renderer..");
|
||||
|
||||
m_window = Window;
|
||||
|
||||
@@ -101,6 +100,8 @@ bool opengl_renderer::Init(GLFWwindow *Window)
|
||||
if (GLEW_ARB_clip_control)
|
||||
glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
|
||||
|
||||
gl::glsl_common_setup();
|
||||
|
||||
if (true == Global.ScaleSpecularValues)
|
||||
{
|
||||
m_specularopaquescalefactor = 0.25f;
|
||||
@@ -177,32 +178,40 @@ bool opengl_renderer::Init(GLFWwindow *Window)
|
||||
m_msaa_rbc = std::make_unique<gl::renderbuffer>();
|
||||
m_msaa_rbc->alloc(GL_RGB16F, Global.render_width, Global.render_height, samples);
|
||||
|
||||
m_msaa_rbv = std::make_unique<gl::renderbuffer>();
|
||||
m_msaa_rbv->alloc(GL_RG16F, Global.render_width, Global.render_height, samples);
|
||||
|
||||
m_msaa_rbd = std::make_unique<gl::renderbuffer>();
|
||||
m_msaa_rbd->alloc(GL_DEPTH_COMPONENT32F, Global.render_width, Global.render_height, samples);
|
||||
|
||||
m_msaa_fb = std::make_unique<gl::framebuffer>();
|
||||
m_msaa_fb->attach(*m_msaa_rbc, GL_COLOR_ATTACHMENT0);
|
||||
m_msaa_fb->attach(*m_msaa_rbv, GL_COLOR_ATTACHMENT1);
|
||||
m_msaa_fb->attach(*m_msaa_rbd, GL_DEPTH_ATTACHMENT);
|
||||
|
||||
if (!m_msaa_fb->is_complete())
|
||||
return false;
|
||||
if (Global.gfx_postfx_motionblur_enabled)
|
||||
{
|
||||
m_msaa_rbv = std::make_unique<gl::renderbuffer>();
|
||||
m_msaa_rbv->alloc(GL_RG16F, Global.render_width, Global.render_height, samples);
|
||||
m_msaa_fb->attach(*m_msaa_rbv, GL_COLOR_ATTACHMENT1);
|
||||
|
||||
m_main_tex = std::make_unique<opengl_texture>();
|
||||
m_main_tex->alloc_rendertarget(GL_RGB16F, GL_RGB, GL_FLOAT, Global.render_width, Global.render_height);
|
||||
m_main_tex = std::make_unique<opengl_texture>();
|
||||
m_main_tex->alloc_rendertarget(GL_RGB16F, GL_RGB, GL_FLOAT, Global.render_width, Global.render_height);
|
||||
|
||||
m_main_texv = std::make_unique<opengl_texture>();
|
||||
m_main_texv->alloc_rendertarget(GL_RG16F, GL_RG, GL_FLOAT, Global.render_width, Global.render_height);
|
||||
m_main_fb = std::make_unique<gl::framebuffer>();
|
||||
m_main_fb->attach(*m_main_tex, GL_COLOR_ATTACHMENT0);
|
||||
|
||||
m_main_fb = std::make_unique<gl::framebuffer>();
|
||||
m_main_fb->attach(*m_main_tex, GL_COLOR_ATTACHMENT0);
|
||||
m_main_fb->attach(*m_main_texv, GL_COLOR_ATTACHMENT1);
|
||||
m_main_fb->setup_drawing(2);
|
||||
if (!m_main_fb->is_complete())
|
||||
return false;
|
||||
m_main_texv = std::make_unique<opengl_texture>();
|
||||
m_main_texv->alloc_rendertarget(GL_RG16F, GL_RG, GL_FLOAT, Global.render_width, Global.render_height);
|
||||
m_main_fb->attach(*m_main_texv, GL_COLOR_ATTACHMENT1);
|
||||
m_main_fb->setup_drawing(2);
|
||||
|
||||
if (!m_main_fb->is_complete())
|
||||
return false;
|
||||
|
||||
m_pfx_motionblur = std::make_unique<gl::postfx>("motionblur");
|
||||
|
||||
WriteLog("motion blur enabled");
|
||||
}
|
||||
|
||||
if (!m_msaa_fb->is_complete())
|
||||
return false;
|
||||
|
||||
m_main2_tex = std::make_unique<opengl_texture>();
|
||||
m_main2_tex->alloc_rendertarget(GL_RGB16F, GL_RGB, GL_FLOAT, Global.render_width, Global.render_height);
|
||||
@@ -213,23 +222,27 @@ bool opengl_renderer::Init(GLFWwindow *Window)
|
||||
return false;
|
||||
|
||||
m_pfx_tonemapping = std::make_unique<gl::postfx>("tonemapping");
|
||||
m_pfx_motionblur = std::make_unique<gl::postfx>("motionblur");
|
||||
|
||||
m_shadow_fb = std::make_unique<gl::framebuffer>();
|
||||
m_shadow_tex = std::make_unique<opengl_texture>();
|
||||
m_shadow_tex->alloc_rendertarget(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, m_shadowbuffersize, m_shadowbuffersize);
|
||||
m_shadow_fb->attach(*m_shadow_tex, GL_DEPTH_ATTACHMENT);
|
||||
if (Global.gfx_shadowmap_enabled)
|
||||
{
|
||||
m_shadow_fb = std::make_unique<gl::framebuffer>();
|
||||
m_shadow_tex = std::make_unique<opengl_texture>();
|
||||
m_shadow_tex->alloc_rendertarget(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, m_shadowbuffersize, m_shadowbuffersize);
|
||||
m_shadow_fb->attach(*m_shadow_tex, GL_DEPTH_ATTACHMENT);
|
||||
|
||||
if (!m_shadow_fb->is_complete())
|
||||
return false;
|
||||
if (!m_shadow_fb->is_complete())
|
||||
return false;
|
||||
|
||||
m_cabshadows_fb = std::make_unique<gl::framebuffer>();
|
||||
m_cabshadows_tex = std::make_unique<opengl_texture>();
|
||||
m_cabshadows_tex->alloc_rendertarget(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, m_shadowbuffersize, m_shadowbuffersize);
|
||||
m_cabshadows_fb->attach(*m_cabshadows_tex, GL_DEPTH_ATTACHMENT);
|
||||
m_cabshadows_fb = std::make_unique<gl::framebuffer>();
|
||||
m_cabshadows_tex = std::make_unique<opengl_texture>();
|
||||
m_cabshadows_tex->alloc_rendertarget(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, m_shadowbuffersize, m_shadowbuffersize);
|
||||
m_cabshadows_fb->attach(*m_cabshadows_tex, GL_DEPTH_ATTACHMENT);
|
||||
|
||||
if (!m_cabshadows_fb->is_complete())
|
||||
return false;
|
||||
if (!m_cabshadows_fb->is_complete())
|
||||
return false;
|
||||
|
||||
WriteLog("shadows enabled");
|
||||
}
|
||||
|
||||
m_pick_tex = std::make_unique<opengl_texture>();
|
||||
m_pick_tex->alloc_rendertarget(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, EU07_PICKBUFFERSIZE, EU07_PICKBUFFERSIZE);
|
||||
@@ -242,24 +255,31 @@ bool opengl_renderer::Init(GLFWwindow *Window)
|
||||
if (!m_pick_fb->is_complete())
|
||||
return false;
|
||||
|
||||
m_env_rb = std::make_unique<gl::renderbuffer>();
|
||||
m_env_rb->alloc(GL_DEPTH_COMPONENT32F, gl::ENVMAP_SIZE, gl::ENVMAP_SIZE);
|
||||
m_env_tex = std::make_unique<gl::cubemap>();
|
||||
m_env_tex->alloc(GL_RGB16F, gl::ENVMAP_SIZE, gl::ENVMAP_SIZE, GL_RGB, GL_FLOAT);
|
||||
m_empty_cubemap = std::make_unique<gl::cubemap>();
|
||||
m_empty_cubemap->alloc(GL_RGB16F, 16, 16, GL_RGB, GL_FLOAT);
|
||||
|
||||
m_env_fb = std::make_unique<gl::framebuffer>();
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
for (int i = 0; i < 6; i++)
|
||||
if (Global.gfx_envmap_enabled)
|
||||
{
|
||||
m_env_fb->attach(*m_empty_cubemap, i, GL_COLOR_ATTACHMENT0);
|
||||
m_env_fb->clear(GL_COLOR_BUFFER_BIT);
|
||||
m_env_rb = std::make_unique<gl::renderbuffer>();
|
||||
m_env_rb->alloc(GL_DEPTH_COMPONENT32F, gl::ENVMAP_SIZE, gl::ENVMAP_SIZE);
|
||||
m_env_tex = std::make_unique<gl::cubemap>();
|
||||
m_env_tex->alloc(GL_RGB16F, gl::ENVMAP_SIZE, gl::ENVMAP_SIZE, GL_RGB, GL_FLOAT);
|
||||
m_empty_cubemap = std::make_unique<gl::cubemap>();
|
||||
m_empty_cubemap->alloc(GL_RGB16F, 16, 16, GL_RGB, GL_FLOAT);
|
||||
|
||||
m_env_fb = std::make_unique<gl::framebuffer>();
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
m_env_fb->attach(*m_empty_cubemap, i, GL_COLOR_ATTACHMENT0);
|
||||
m_env_fb->clear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
m_env_fb->detach(GL_COLOR_ATTACHMENT0);
|
||||
m_env_fb->attach(*m_env_rb, GL_DEPTH_ATTACHMENT);
|
||||
|
||||
WriteLog("envmap enabled");
|
||||
}
|
||||
|
||||
m_env_fb->detach(GL_COLOR_ATTACHMENT0);
|
||||
m_env_fb->attach(*m_env_rb, GL_DEPTH_ATTACHMENT);
|
||||
WriteLog("renderer initialization finished!");
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -372,9 +392,12 @@ void opengl_renderer::Render_pass(rendermode const Mode)
|
||||
else
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
{
|
||||
setup_shadow_map(nullptr, m_renderpass);
|
||||
|
||||
setup_shadow_map(nullptr, m_renderpass);
|
||||
setup_env_map(nullptr);
|
||||
|
||||
if (Global.gfx_shadowmap_enabled)
|
||||
{
|
||||
glDebug("render shadowmap start");
|
||||
Timer::subsystem.gfx_shadows.start();
|
||||
|
||||
@@ -387,16 +410,23 @@ void opengl_renderer::Render_pass(rendermode const Mode)
|
||||
glDebug("render shadowmap end");
|
||||
}
|
||||
|
||||
// potentially update environmental cube map
|
||||
if (Render_reflections())
|
||||
setup_pass(m_renderpass, Mode); // restore color pass settings
|
||||
setup_env_map(m_env_tex.get());
|
||||
if (Global.gfx_envmap_enabled)
|
||||
{
|
||||
// potentially update environmental cube map
|
||||
if (Render_reflections())
|
||||
setup_pass(m_renderpass, Mode); // restore color pass settings
|
||||
setup_env_map(m_env_tex.get());
|
||||
}
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
// setup
|
||||
m_msaa_fb->bind();
|
||||
m_msaa_fb->setup_drawing(2);
|
||||
|
||||
if (Global.gfx_postfx_motionblur_enabled)
|
||||
m_msaa_fb->setup_drawing(2);
|
||||
else
|
||||
m_msaa_fb->setup_drawing(1);
|
||||
|
||||
glViewport(0, 0, Global.render_width, Global.render_height);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
@@ -428,7 +458,8 @@ void opengl_renderer::Render_pass(rendermode const Mode)
|
||||
if (false == FreeFlyModeFlag)
|
||||
{
|
||||
glDebug("render cab opaque");
|
||||
setup_shadow_map(m_cabshadows_tex.get(), m_cabshadowpass);
|
||||
if (Global.gfx_shadowmap_enabled)
|
||||
setup_shadow_map(m_cabshadows_tex.get(), m_cabshadowpass);
|
||||
|
||||
auto const *vehicle = World.Train->Dynamic();
|
||||
Render_cab(vehicle, false);
|
||||
@@ -438,7 +469,9 @@ void opengl_renderer::Render_pass(rendermode const Mode)
|
||||
|
||||
model_ubs.future = future;
|
||||
|
||||
setup_shadow_map(m_shadow_tex.get(), m_shadowpass);
|
||||
if (Global.gfx_shadowmap_enabled)
|
||||
setup_shadow_map(m_shadow_tex.get(), m_shadowpass);
|
||||
|
||||
Render(simulation::Region);
|
||||
|
||||
// ...translucent parts
|
||||
@@ -450,7 +483,8 @@ void opengl_renderer::Render_pass(rendermode const Mode)
|
||||
glDebug("render translucent cab");
|
||||
model_ubs.future = glm::mat4();
|
||||
// cab render is performed without shadows, due to low resolution and number of models without windows :|
|
||||
setup_shadow_map(m_cabshadows_tex.get(), m_cabshadowpass);
|
||||
if (Global.gfx_shadowmap_enabled)
|
||||
setup_shadow_map(m_cabshadows_tex.get(), m_cabshadowpass);
|
||||
// cache shadow colour in case we need to account for cab light
|
||||
auto const *vehicle{World.Train->Dynamic()};
|
||||
Render_cab(vehicle, true);
|
||||
@@ -459,16 +493,23 @@ void opengl_renderer::Render_pass(rendermode const Mode)
|
||||
setup_shadow_map(nullptr, m_renderpass);
|
||||
setup_env_map(nullptr);
|
||||
|
||||
m_main_fb->clear(GL_COLOR_BUFFER_BIT);
|
||||
m_msaa_fb->blit_to(*m_main_fb.get(), Global.render_width, Global.render_height, GL_COLOR_BUFFER_BIT, GL_COLOR_ATTACHMENT0);
|
||||
m_msaa_fb->blit_to(*m_main_fb.get(), Global.render_width, Global.render_height, GL_COLOR_BUFFER_BIT, GL_COLOR_ATTACHMENT1);
|
||||
if (Global.gfx_postfx_motionblur_enabled)
|
||||
{
|
||||
m_main_fb->clear(GL_COLOR_BUFFER_BIT);
|
||||
m_msaa_fb->blit_to(*m_main_fb.get(), Global.render_width, Global.render_height, GL_COLOR_BUFFER_BIT, GL_COLOR_ATTACHMENT0);
|
||||
m_msaa_fb->blit_to(*m_main_fb.get(), Global.render_width, Global.render_height, GL_COLOR_BUFFER_BIT, GL_COLOR_ATTACHMENT1);
|
||||
|
||||
model_ubs.param[0].x = m_framerate / (1.0 / Global.gfx_postfx_motionblur_shutter);
|
||||
model_ubo->update(model_ubs);
|
||||
m_pfx_motionblur->apply({m_main_tex.get(), m_main_texv.get()}, m_main2_fb.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_main2_fb->clear(GL_COLOR_BUFFER_BIT);
|
||||
m_msaa_fb->blit_to(*m_main2_fb.get(), Global.render_width, Global.render_height, GL_COLOR_BUFFER_BIT, GL_COLOR_ATTACHMENT0);
|
||||
}
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
model_ubs.param[0].x = m_framerate / (1.0 / Global.gfx_postfx_motionblur_shutter);
|
||||
model_ubo->update(model_ubs);
|
||||
m_pfx_motionblur->apply({m_main_tex.get(), m_main_texv.get()}, m_main2_fb.get());
|
||||
|
||||
glEnable(GL_FRAMEBUFFER_SRGB);
|
||||
glViewport(0, 0, Global.iWindowWidth, Global.iWindowHeight);
|
||||
m_pfx_tonemapping->apply(*m_main2_tex, nullptr);
|
||||
@@ -3356,20 +3397,21 @@ void opengl_renderer::Update_Lights(light_array &Lights)
|
||||
|
||||
bool opengl_renderer::Init_caps()
|
||||
{
|
||||
std::string oglversion = ((char *)glGetString(GL_VERSION));
|
||||
|
||||
WriteLog("Gfx Renderer: " + std::string((char *)glGetString(GL_RENDERER)) + " Vendor: " + std::string((char *)glGetString(GL_VENDOR)) + " OpenGL Version: " + oglversion);
|
||||
WriteLog("MaSzyna GL3.3+ Renderer");
|
||||
WriteLog("Renderer: " + std::string((char *)glGetString(GL_RENDERER)));
|
||||
WriteLog("Vendor: " + std::string((char *)glGetString(GL_VENDOR)));
|
||||
WriteLog("GL version: " + std::string((char *)glGetString(GL_VERSION)));
|
||||
|
||||
if (!GLEW_VERSION_3_3)
|
||||
{
|
||||
ErrorLog("Requires openGL >= 3.3");
|
||||
ErrorLog("requires OpenGL >= 3.3!");
|
||||
return false;
|
||||
}
|
||||
|
||||
GLint extCount = 0;
|
||||
glGetIntegerv(GL_NUM_EXTENSIONS, &extCount);
|
||||
|
||||
WriteLog("Supported extensions: ");
|
||||
WriteLog("Supported extensions:");
|
||||
for (int i = 0; i < extCount; i++)
|
||||
{
|
||||
const char *ext = (const char *)glGetStringi(GL_EXTENSIONS, i);
|
||||
@@ -3377,6 +3419,12 @@ bool opengl_renderer::Init_caps()
|
||||
}
|
||||
WriteLog("--------");
|
||||
|
||||
if (!GLEW_EXT_texture_sRGB)
|
||||
ErrorLog("EXT_texture_sRGB not supported!");
|
||||
|
||||
if (!GLEW_EXT_texture_compression_s3tc)
|
||||
ErrorLog("EXT_texture_compression_s3tc not supported!");
|
||||
|
||||
if (GLEW_ARB_multi_bind)
|
||||
WriteLog("ARB_multi_bind supported!");
|
||||
|
||||
@@ -3384,23 +3432,35 @@ bool opengl_renderer::Init_caps()
|
||||
WriteLog("ARB_direct_state_access supported!");
|
||||
|
||||
if (GLEW_ARB_clip_control)
|
||||
WriteLog("ARB_direct_state_access supported!");
|
||||
WriteLog("ARB_clip_control supported!");
|
||||
|
||||
glGetError();
|
||||
glLineWidth(2.0f);
|
||||
if (!glGetError())
|
||||
{
|
||||
WriteLog("wide lines supported!");
|
||||
m_widelines_supported = true;
|
||||
}
|
||||
else
|
||||
WriteLog("warning: wide lines not supported");
|
||||
|
||||
WriteLog("--------");
|
||||
|
||||
// ograniczenie maksymalnego rozmiaru tekstur - parametr dla skalowania tekstur
|
||||
{
|
||||
GLint texturesize;
|
||||
::glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texturesize);
|
||||
Global.iMaxTextureSize = std::min(Global.iMaxTextureSize, texturesize);
|
||||
WriteLog("Texture sizes capped at " + std::to_string(Global.iMaxTextureSize) + " pixels");
|
||||
WriteLog("texture sizes capped at " + std::to_string(Global.iMaxTextureSize) + "px");
|
||||
m_shadowbuffersize = Global.shadowtune.map_size;
|
||||
m_shadowbuffersize = std::min(m_shadowbuffersize, texturesize);
|
||||
WriteLog("Shadows map size capped at " + std::to_string(m_shadowbuffersize) + " pixels");
|
||||
WriteLog("shadows map size capped at " + std::to_string(m_shadowbuffersize) + "px");
|
||||
}
|
||||
Global.DynamicLightCount = std::min(Global.DynamicLightCount, 8);
|
||||
|
||||
if (Global.iMultisampling)
|
||||
{
|
||||
WriteLog("Using multisampling x" + std::to_string(1 << Global.iMultisampling));
|
||||
WriteLog("using multisampling x" + std::to_string(1 << Global.iMultisampling));
|
||||
}
|
||||
|
||||
if (Global.render_width == -1)
|
||||
@@ -3410,16 +3470,6 @@ bool opengl_renderer::Init_caps()
|
||||
|
||||
WriteLog("rendering at " + std::to_string(Global.render_width) + "x" + std::to_string(Global.render_height));
|
||||
|
||||
glGetError();
|
||||
glLineWidth(2.0f);
|
||||
if (!glGetError())
|
||||
{
|
||||
WriteLog("wide lines supported");
|
||||
m_widelines_supported = true;
|
||||
}
|
||||
else
|
||||
WriteLog("warning: wide lines not supported");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
29
renderer.h
29
renderer.h
@@ -25,6 +25,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "gl/postfx.h"
|
||||
#include "gl/shader.h"
|
||||
#include "gl/cubemap.h"
|
||||
#include "gl/glsl_common.h"
|
||||
|
||||
#define EU07_USE_PICKING_FRAMEBUFFER
|
||||
//#define EU07_USE_DEBUG_SHADOWMAP
|
||||
@@ -282,35 +283,13 @@ class opengl_renderer
|
||||
gfx::geometry_handle m_billboardgeometry{0, 0};
|
||||
texture_handle m_glaretexture{-1};
|
||||
texture_handle m_suntexture{-1};
|
||||
texture_handle m_moontexture{-1};
|
||||
texture_handle m_reflectiontexture{-1};
|
||||
// TODO: refactor framebuffer stuff into an object
|
||||
bool m_framebuffersupport{false};
|
||||
#ifdef EU07_USE_PICKING_FRAMEBUFFER
|
||||
GLuint m_pickframebuffer{0};
|
||||
GLuint m_picktexture{0};
|
||||
GLuint m_pickdepthbuffer{0};
|
||||
#endif
|
||||
texture_handle m_moontexture{-1};
|
||||
|
||||
// main shadowmap resources
|
||||
int m_shadowbuffersize{2048};
|
||||
GLuint m_shadowframebuffer{0};
|
||||
GLuint m_shadowtexture{0};
|
||||
#ifdef EU07_USE_DEBUG_SHADOWMAP
|
||||
GLuint m_shadowdebugtexture{0};
|
||||
#endif
|
||||
#ifdef EU07_USE_DEBUG_CABSHADOWMAP
|
||||
GLuint m_cabshadowdebugtexture{0};
|
||||
#endif
|
||||
glm::mat4 m_shadowtexturematrix; // conversion from camera-centric world space to light-centric clip space
|
||||
// cab shadowmap resources
|
||||
GLuint m_cabshadowframebuffer{0};
|
||||
GLuint m_cabshadowtexture{0};
|
||||
glm::mat4 m_cabshadowtexturematrix; // conversion from cab-centric world space to light-centric clip space
|
||||
// environment map resources
|
||||
GLuint m_environmentframebuffer{0};
|
||||
GLuint m_environmentcubetexture{0};
|
||||
GLuint m_environmentdepthbuffer{0};
|
||||
bool m_environmentcubetexturesupport{false}; // indicates whether we can use the dynamic environment cube map
|
||||
|
||||
int m_environmentcubetextureface{0}; // helper, currently processed cube map face
|
||||
int m_environmentupdatetime{0}; // time of the most recent environment map update
|
||||
glm::dvec3 m_environmentupdatelocation; // coordinates of most recent environment map update
|
||||
|
||||
@@ -12,5 +12,7 @@ void main()
|
||||
{
|
||||
vec4 tex_color = texture(tex1, f_coord);
|
||||
gl_FragData[0] = tex_color * param[0];
|
||||
#ifdef MOTIONBLUR_ENABLED
|
||||
gl_FragData[1] = vec4(0.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -7,5 +7,7 @@ in vec3 f_color;
|
||||
void main()
|
||||
{
|
||||
gl_FragData[0] = vec4(f_color, 1.0f);
|
||||
#ifdef MOTIONBLUR_ENABLED
|
||||
gl_FragData[1] = vec4(0.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -13,10 +13,12 @@ void main()
|
||||
if (dist2 > 0.5f * 0.5f)
|
||||
discard;
|
||||
gl_FragData[0] = vec4(param[0].rgb * emission, 1.0f);
|
||||
#ifdef MOTIONBLUR_ENABLED
|
||||
{
|
||||
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
|
||||
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
|
||||
|
||||
gl_FragData[1] = vec4(a - b, 0.0f, 0.0f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
float calc_shadow()
|
||||
{
|
||||
#ifdef SHADOWMAP_ENABLED
|
||||
vec3 coords = f_light_pos.xyz / f_light_pos.w;
|
||||
|
||||
if (coords.z < 0.0f)
|
||||
@@ -17,6 +18,9 @@ float calc_shadow()
|
||||
shadow /= 16.0;
|
||||
|
||||
return 1.0 - shadow;
|
||||
#else
|
||||
return 1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
vec3 apply_fog(vec3 color)
|
||||
|
||||
@@ -13,5 +13,7 @@ void main()
|
||||
{
|
||||
vec4 tex_color = texture(tex1, f_coord);
|
||||
gl_FragData[0] = tex_color * param[0];
|
||||
#ifdef MOTIONBLUR_ENABLED
|
||||
gl_FragData[1] = vec4(0.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -15,8 +15,13 @@ in vec4 f_clip_future_pos;
|
||||
#param (specular, 1, 1, 1, specular)
|
||||
#param (reflection, 1, 2, 1, zero)
|
||||
|
||||
#ifdef SHADOWMAP_ENABLED
|
||||
uniform sampler2DShadow shadowmap;
|
||||
#endif
|
||||
|
||||
#ifdef ENVMAP_ENABLED
|
||||
uniform samplerCube envmap;
|
||||
#endif
|
||||
|
||||
#include <light_common.glsl>
|
||||
|
||||
@@ -26,7 +31,11 @@ void main()
|
||||
|
||||
vec3 normal = normalize(f_normal);
|
||||
vec3 refvec = reflect(f_pos.xyz, normal);
|
||||
#ifdef ENVMAP_ENABLED
|
||||
vec3 envcolor = texture(envmap, refvec).rgb;
|
||||
#else
|
||||
vec3 envcolor = vec3(0.5);
|
||||
#endif
|
||||
|
||||
vec3 result = ambient * 0.5 + param[0].rgb * emission;
|
||||
|
||||
@@ -53,10 +62,12 @@ void main()
|
||||
}
|
||||
|
||||
gl_FragData[0] = vec4(apply_fog(result * tex_color.rgb), tex_color.a);
|
||||
#ifdef MOTIONBLUR_ENABLED
|
||||
{
|
||||
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
|
||||
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
|
||||
|
||||
gl_FragData[1] = vec4(a - b, 0.0f, 0.0f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -18,8 +18,13 @@ in vec4 f_clip_future_pos;
|
||||
#texture (diffuse, 0, sRGB_A)
|
||||
uniform sampler2D diffuse;
|
||||
|
||||
#ifdef SHADOWMAP_ENABLED
|
||||
uniform sampler2DShadow shadowmap;
|
||||
#endif
|
||||
|
||||
#ifdef ENVMAP_ENABLED
|
||||
uniform samplerCube envmap;
|
||||
#endif
|
||||
|
||||
#include <light_common.glsl>
|
||||
|
||||
@@ -32,7 +37,11 @@ void main()
|
||||
|
||||
vec3 normal = normalize(f_normal);
|
||||
vec3 refvec = reflect(f_pos.xyz, normal);
|
||||
#ifdef ENVMAP_ENABLED
|
||||
vec3 envcolor = texture(envmap, refvec).rgb;
|
||||
#else
|
||||
vec3 envcolor = vec3(0.5);
|
||||
#endif
|
||||
|
||||
vec3 result = ambient * 0.5 + param[0].rgb * emission;
|
||||
|
||||
@@ -60,11 +69,12 @@ void main()
|
||||
|
||||
gl_FragData[0] = vec4(apply_fog(result * tex_color.rgb), tex_color.a);
|
||||
|
||||
|
||||
#ifdef MOTIONBLUR_ENABLED
|
||||
{
|
||||
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
|
||||
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
|
||||
|
||||
gl_FragData[1] = vec4(a - b, 0.0f, tex_color.a < 0.9f ? 0.0f : 1.0f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -5,5 +5,7 @@
|
||||
void main()
|
||||
{
|
||||
gl_FragData[0] = vec4(1.0, 0.0, 1.0, 1.0);
|
||||
#ifdef MOTIONBLUR_ENABLED
|
||||
gl_FragData[1] = vec4(0.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -22,8 +22,13 @@ uniform sampler2D diffuse;
|
||||
#texture (normalmap, 1, RGB)
|
||||
uniform sampler2D normalmap;
|
||||
|
||||
#ifdef SHADOWMAP_ENABLED
|
||||
uniform sampler2DShadow shadowmap;
|
||||
#endif
|
||||
|
||||
#ifdef ENVMAP_ENABLED
|
||||
uniform samplerCube envmap;
|
||||
#endif
|
||||
|
||||
#define NORMALMAP
|
||||
#include <light_common.glsl>
|
||||
@@ -37,7 +42,11 @@ void main()
|
||||
|
||||
vec3 normal = f_tbn * normalize(texture(normalmap, f_coord).rgb * 2.0 - 1.0);
|
||||
vec3 refvec = reflect(f_pos.xyz, normal);
|
||||
#ifdef ENVMAP_ENABLED
|
||||
vec3 envcolor = texture(envmap, refvec).rgb;
|
||||
#else
|
||||
vec3 envcolor = vec3(0.5);
|
||||
#endif
|
||||
|
||||
vec3 result = ambient * 0.5 + param[0].rgb * emission;
|
||||
|
||||
@@ -64,10 +73,13 @@ void main()
|
||||
}
|
||||
|
||||
gl_FragData[0] = vec4(apply_fog(result * tex_color.rgb), tex_color.a);
|
||||
|
||||
#ifdef MOTIONBLUR_ENABLED
|
||||
{
|
||||
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
|
||||
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
|
||||
|
||||
gl_FragData[1] = vec4(a - b, 0.0f, 0.0f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -21,8 +21,13 @@ uniform sampler2D diffuse;
|
||||
#texture (reflmap, 1, R)
|
||||
uniform sampler2D reflmap;
|
||||
|
||||
#ifdef SHADOWMAP_ENABLED
|
||||
uniform sampler2DShadow shadowmap;
|
||||
#endif
|
||||
|
||||
#ifdef ENVMAP_ENABLED
|
||||
uniform samplerCube envmap;
|
||||
#endif
|
||||
|
||||
#include <light_common.glsl>
|
||||
|
||||
@@ -35,7 +40,11 @@ void main()
|
||||
|
||||
vec3 normal = normalize(f_normal);
|
||||
vec3 refvec = reflect(f_pos.xyz, normal);
|
||||
#ifdef ENVMAP_ENABLED
|
||||
vec3 envcolor = texture(envmap, refvec).rgb;
|
||||
#else
|
||||
vec3 envcolor = vec3(0.5);
|
||||
#endif
|
||||
|
||||
vec3 result = ambient * 0.5 + param[0].rgb * emission;
|
||||
|
||||
@@ -63,10 +72,12 @@ void main()
|
||||
|
||||
gl_FragData[0] = vec4(apply_fog(result * tex_color.rgb), tex_color.a);
|
||||
|
||||
#ifdef MOTIONBLUR_ENABLED
|
||||
{
|
||||
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
|
||||
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
|
||||
|
||||
gl_FragData[1] = vec4(a - b, 0.0f, 0.0f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -14,5 +14,7 @@ void main()
|
||||
|
||||
// color data is shared with normals, ugh
|
||||
gl_FragData[0] = vec4(f_normal_raw.bgr, 1.0f);
|
||||
#ifdef MOTIONBLUR_ENABLED
|
||||
gl_FragData[1] = vec4(0.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -8,10 +8,12 @@ in vec4 f_clip_future_pos;
|
||||
void main()
|
||||
{
|
||||
gl_FragData[0] = param[0];
|
||||
#ifdef MOTIONBLUR_ENABLED
|
||||
{
|
||||
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
|
||||
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
|
||||
|
||||
gl_FragData[1] = vec4(a - b, 0.0f, 0.0f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user