add multisampling
This commit is contained in:
parent
105681fd2a
commit
86c01377e5
|
@ -0,0 +1,26 @@
|
|||
|
||||
#version 460 core
|
||||
|
||||
uniform int samples;
|
||||
uniform sampler2D tex;
|
||||
|
||||
in vec2 texPos;
|
||||
|
||||
out vec4 FragColour;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texel_size = 1.f / vec2(textureSize(tex, 0));
|
||||
float samples_n = pow(samples * 2 + 1, 2);
|
||||
vec4 colour;
|
||||
|
||||
for(int x = -samples; x <= samples; x++)
|
||||
for(int y = -samples; y <= samples; y++)
|
||||
{
|
||||
vec2 off = texel_size * vec2(x, y);
|
||||
colour += texture2D(tex, texPos + off);
|
||||
}
|
||||
|
||||
FragColour = vec4((colour / samples_n).rgb, 1);
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
#version 460 core
|
||||
|
||||
layout (location = 1) in vec2 aTexPos;
|
||||
layout (location = 2) in vec4 aPos;
|
||||
|
||||
out vec2 texPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
texPos = aTexPos;
|
||||
gl_Position = aPos;
|
||||
}
|
||||
|
|
@ -19,8 +19,8 @@ out vec2 texPos;
|
|||
void main()
|
||||
{
|
||||
vec4 pos = camera * model * aPos;
|
||||
vec3 cNormal = vec3(0.f, 0.f, 1.f) * mat3(camera * model);
|
||||
|
||||
// vec3 cNormal = vec3(0.f, 0.f, 1.f) * mat3(camera * model);
|
||||
// float brightness = dot(normalize(aNormal), normalize(cNormal)) * 0.25f + 0.75f;
|
||||
|
||||
colour = aColour;// * vec4(vec3(brightness), 1);
|
||||
|
|
|
@ -53,7 +53,7 @@ struct Fluid
|
|||
constexpr double l_to_mol(double l) const { return g_to_mol(l_to_g(l)); }
|
||||
};
|
||||
|
||||
constexpr const Fluid WATER = Fluid(1000, 18, 2257, {8.07131 + 2.124903, 1730.63, 233.426 - 273.15});
|
||||
constexpr Fluid WATER = Fluid(1000, 18, 2257, {8.07131 + 2.124903, 1730.63, 233.426 - 273.15});
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -81,8 +81,8 @@ void Font::init()
|
|||
|
||||
glTextureParameteri(texids[i], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTextureParameteri(texids[i], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTextureParameteri(texids[i], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTextureParameteri(texids[i], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTextureParameteri(texids[i], GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTextureParameteri(texids[i], GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
c.handle = glGetTextureHandleARB(texids[i]);
|
||||
glMakeTextureHandleResidentARB(c.handle);
|
||||
|
|
|
@ -59,8 +59,8 @@ void GLMesh::bind()
|
|||
|
||||
void GLMesh::uniform()
|
||||
{
|
||||
glUniformMatrix4fv(Shader::gl_model, 1, false, &model_matrix[0][0]);
|
||||
glUniformMatrix4fv(Shader::gl_tex_mat, 1, false, &colour_matrix[0][0]);
|
||||
glUniformMatrix4fv(Shader::MAIN["model"], 1, false, &model_matrix[0][0]);
|
||||
glUniformMatrix4fv(Shader::MAIN["tex_mat"], 1, false, &colour_matrix[0][0]);
|
||||
}
|
||||
|
||||
void GLMesh::set(const Mesh& m, int mode)
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "window.hpp"
|
||||
|
||||
using namespace Sim::Graphics;
|
||||
using namespace Sim::Graphics::Resize;
|
||||
|
||||
static bool is_fullscreen = false;
|
||||
|
||||
|
|
|
@ -11,13 +11,8 @@
|
|||
|
||||
using namespace Sim::Graphics;
|
||||
|
||||
static unsigned int prog_id;
|
||||
|
||||
int Shader::gl_tex_mat;
|
||||
int Shader::gl_model;
|
||||
int Shader::gl_camera;
|
||||
int Shader::gl_projection;
|
||||
int Shader::gl_brightness;
|
||||
Shader Shader::MAIN;
|
||||
Shader Shader::BLUR;
|
||||
|
||||
static int load_shader(const char* src, int type)
|
||||
{
|
||||
|
@ -44,11 +39,32 @@ static std::string read_shader(const char* path)
|
|||
return ss.str();
|
||||
}
|
||||
|
||||
unsigned int Shader::init_program()
|
||||
Shader::Shader()
|
||||
{
|
||||
std::string shader_vsh = read_shader("../assets/shader/main.vsh");
|
||||
std::string shader_fsh = read_shader("../assets/shader/main.fsh");
|
||||
|
||||
|
||||
}
|
||||
|
||||
Shader::Shader(Shader&& o)
|
||||
{
|
||||
prog_id = o.prog_id;
|
||||
o.prog_id = 0;
|
||||
}
|
||||
|
||||
Shader::~Shader()
|
||||
{
|
||||
if(prog_id)
|
||||
{
|
||||
glDeleteProgram(prog_id);
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::load(const char* path, const char* file_vsh, const char* file_fsh)
|
||||
{
|
||||
std::string path_vsh = std::string(path) + "/" + std::string(file_vsh);
|
||||
std::string path_fsh = std::string(path) + "/" + std::string(file_fsh);
|
||||
std::string shader_vsh = read_shader(path_vsh.c_str());
|
||||
std::string shader_fsh = read_shader(path_fsh.c_str());
|
||||
|
||||
int success;
|
||||
int vsh_id = load_shader(shader_vsh.c_str(), GL_VERTEX_SHADER);
|
||||
int fsh_id = load_shader(shader_fsh.c_str(), GL_FRAGMENT_SHADER);
|
||||
|
@ -63,21 +79,30 @@ unsigned int Shader::init_program()
|
|||
{
|
||||
char infoLog[512];
|
||||
glGetProgramInfoLog(prog_id, 512, NULL, infoLog);
|
||||
std::cout << "Shader Link Error: " << infoLog << std::endl;
|
||||
std::cout << "Shader Link Error (" << path << "," << file_vsh << "," << file_fsh << "): " << infoLog << std::endl;
|
||||
Window::close();
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
gl_tex_mat = glGetUniformLocation(prog_id, "tex_mat");
|
||||
gl_model = glGetUniformLocation(prog_id, "model");
|
||||
gl_camera = glGetUniformLocation(prog_id, "camera");
|
||||
gl_projection = glGetUniformLocation(prog_id, "projection");
|
||||
gl_brightness = glGetUniformLocation(prog_id, "brightness");
|
||||
|
||||
glUseProgram(prog_id);
|
||||
glDeleteShader(vsh_id);
|
||||
glDeleteShader(fsh_id);
|
||||
|
||||
return prog_id;
|
||||
}
|
||||
|
||||
void Shader::use()
|
||||
{
|
||||
glUseProgram(prog_id);
|
||||
}
|
||||
|
||||
unsigned int Shader::operator [](const char* pos)
|
||||
{
|
||||
auto it = uniform_locations.find(pos);
|
||||
|
||||
if(it != uniform_locations.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return uniform_locations[pos] = glGetUniformLocation(prog_id, pos);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,32 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
namespace Sim::Graphics::Shader
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Sim::Graphics
|
||||
{
|
||||
|
||||
extern int gl_tex_mat;
|
||||
extern int gl_model;
|
||||
extern int gl_camera;
|
||||
extern int gl_projection;
|
||||
extern int gl_brightness;
|
||||
class Shader
|
||||
{
|
||||
unsigned int prog_id = 0;
|
||||
|
||||
unsigned int init_program();
|
||||
std::unordered_map<const char*, unsigned int> uniform_locations;
|
||||
|
||||
public:
|
||||
|
||||
static Shader MAIN;
|
||||
static Shader BLUR;
|
||||
|
||||
Shader();
|
||||
Shader(const Shader& o) = delete;
|
||||
Shader(Shader&& o);
|
||||
~Shader();
|
||||
|
||||
void load(const char* path, const char* file_vsh, const char* file_fsh);
|
||||
void use();
|
||||
|
||||
unsigned int operator[](const char* pos);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -55,8 +55,8 @@ void UI::render()
|
|||
|
||||
glm::mat4 mat_projection = glm::mat4(1);
|
||||
glm::mat4 mat_camera = glm::scale(glm::mat4(1), glm::vec3(1.0f / wsize * glm::vec2(1, -1), -1));
|
||||
glUniformMatrix4fv(Shader::gl_projection, 1, false, &mat_projection[0][0]);
|
||||
glUniformMatrix4fv(Shader::gl_camera, 1, false, &mat_camera[0][0]);
|
||||
glUniformMatrix4fv(Shader::MAIN["projection"], 1, false, &mat_projection[0][0]);
|
||||
glUniformMatrix4fv(Shader::MAIN["camera"], 1, false, &mat_camera[0][0]);
|
||||
|
||||
s_mesh.bind();
|
||||
s_mesh.uniform();
|
||||
|
|
|
@ -34,6 +34,7 @@ static GLFWwindow* win;
|
|||
static bool win_should_close = false;
|
||||
|
||||
static GLMesh mesh_scene;
|
||||
|
||||
static Monitor::Vessel monitor_vessel;
|
||||
static Monitor::Core monitor_core;
|
||||
static Monitor::PrimaryLoop monitor_primary_loop;
|
||||
|
@ -42,7 +43,7 @@ static Monitor::Turbine monitor_turbine;
|
|||
|
||||
glm::mat4 Window::projection_matrix;
|
||||
|
||||
void GLAPIENTRY cb_debug_message(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam)
|
||||
static void GLAPIENTRY cb_debug_message(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam)
|
||||
{
|
||||
if(severity != GL_DEBUG_SEVERITY_NOTIFICATION)
|
||||
{
|
||||
|
@ -58,6 +59,7 @@ void Window::create()
|
|||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true);
|
||||
glfwWindowHint(GLFW_VISIBLE, false);
|
||||
glfwWindowHint(GLFW_SAMPLES, 16);
|
||||
|
||||
#ifdef __APPLE__
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);
|
||||
|
@ -90,6 +92,7 @@ void Window::create()
|
|||
return;
|
||||
}
|
||||
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
@ -107,7 +110,9 @@ void Window::create()
|
|||
Font::init();
|
||||
UI::init();
|
||||
|
||||
Shader::init_program();
|
||||
Shader::BLUR.load("../assets/shader", "blur.vsh", "blur.fsh");
|
||||
Shader::MAIN.load("../assets/shader", "main.vsh", "main.fsh");
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
Sim::System& sys = *System::active;
|
||||
Mesh m, m2;
|
||||
|
@ -180,9 +185,9 @@ void Window::render()
|
|||
|
||||
glm::vec3 brightness = glm::vec3(System::active->grid.get_light_intensity());
|
||||
glm::mat4 mat_projection = glm::perspective(glm::radians(90.0f), Resize::get_aspect(), 0.01f, 20.f);
|
||||
glUniformMatrix4fv(Shader::gl_projection, 1, false, &mat_projection[0][0]);
|
||||
glUniformMatrix4fv(Shader::gl_camera, 1, false, &mat_camera[0][0]);
|
||||
glUniform3fv(Shader::gl_brightness, 1, &brightness[0]);
|
||||
glUniformMatrix4fv(Shader::MAIN["projection"], 1, false, &mat_projection[0][0]);
|
||||
glUniformMatrix4fv(Shader::MAIN["camera"], 1, false, &mat_camera[0][0]);
|
||||
glUniform3fv(Shader::MAIN["brightness"], 1, &brightness[0]);
|
||||
projection_matrix = mat_projection;
|
||||
|
||||
glClearColor(0, 0, 0, 1.0f);
|
||||
|
@ -192,14 +197,14 @@ void Window::render()
|
|||
render_scene();
|
||||
|
||||
mat_camera = Camera::get_matrix();
|
||||
glUniformMatrix4fv(Shader::gl_camera, 1, false, &mat_camera[0][0]);
|
||||
glUniformMatrix4fv(Shader::MAIN["camera"], 1, false, &mat_camera[0][0]);
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
glFrontFace(GL_CCW);
|
||||
|
||||
render_scene();
|
||||
|
||||
brightness = glm::vec3(1);
|
||||
glUniform3fv(Shader::gl_brightness, 1, &brightness[0]);
|
||||
glUniform3fv(Shader::MAIN["brightness"], 1, &brightness[0]);
|
||||
|
||||
UI::render();
|
||||
Focus::render_ui();
|
||||
|
|
Loading…
Reference in New Issue