post processing

This commit is contained in:
j3d1 2016-10-05 20:53:37 +02:00
parent fc7213fe03
commit f15213db1b
5 changed files with 129 additions and 10 deletions

View file

@ -0,0 +1,26 @@
#version 120
uniform sampler2D tex0;
uniform sampler2D tex1;
varying vec3 vertex;
varying vec2 uv;
const int gaussRadius = 11;
const float gaussFilter[gaussRadius] = float[gaussRadius](
0.0402,0.0623,0.0877,0.1120,0.1297,0.1362,0.1297,0.1120,0.0877,0.0623,0.0402
);
uniform vec2 scale;
void main()
{
vec2 texCoord = uv.xy - float(int(gaussRadius/2)) * scale;
vec3 color = vec3(0.0, 0.0, 0.0);
for (int i=0; i<gaussRadius; ++i) {
color += gaussFilter[i] * texture2D(tex0, texCoord).xyz;
texCoord += scale;
}
gl_FragColor = vec4(color, 1.0);
}

View file

@ -0,0 +1,12 @@
#version 120
uniform vec2 uvScale;
varying vec3 vertex;
varying vec2 uv;
void main()
{
gl_Position = gl_Vertex;
vertex = gl_Position.xyz;
uv = uvScale * (0.5 + vertex.xy / 2.0);
}

21
game/network/server.cpp Normal file
View file

@ -0,0 +1,21 @@
#define ASIO_STANDALONE
#include "server.hpp"
#include <memory>
void Server::do_accept()
{
m_acceptor.async_accept(m_socket,
[this](std::error_code ec)
{
if (!ec)
{
auto s = std::make_shared<Session>(std::move(m_socket),state);
m_sessions.push_back(s);
s->start();
}
do_accept();
});
}

View file

@ -37,22 +37,32 @@ namespace endofthejedi {
m_shader_background.loadFile(fss_background, GL_FRAGMENT_SHADER);
//addModel("../data/mesh/small_atomic_bomb.stl", &m_missileModel);
addModel("../data/mesh/rocket.stl", &m_missileModel);
addModel("../data/mesh/rocket.stl", &m_missileModel);
addModel("../data/mesh/planet_128.stl", &m_planetModel);
addModel("../data/mesh/ship_ufo.stl", &m_shipModel);
addModel("../data/mesh/ship_ufo.stl", &m_shipModel);
m_texture = nullptr;
m_backgroundTexturePath = "../data/img/background_3.png";
loadBackgroundTexture();
developer::DeveloperConsole::instance().addCallback("reload_bg", [=](const std::string &)
{
m_postprocess_shader.init();
m_postprocess_shader.loadFile("../data/shader/postprocess.vert",
GL_VERTEX_SHADER);
m_postprocess_shader.loadFile("../data/shader/postprocess.frag",
GL_FRAGMENT_SHADER);
m_postprocess_fbo.init();
m_postprocess_tex0.init();
m_postprocess_tex1.init();
developer::DeveloperConsole::instance().addCallback(
"reload_bg", [=](const std::string &) {
loadBackgroundTexture();
return developer::resultOkay();
});
developer::DeveloperConsole::instance().addCallback("set_bg", [=](const std::string &str)
{
developer::DeveloperConsole::instance().addCallback(
"set_bg", [=](const std::string &str) {
std::string token;
std::string rest;
util::splitIntoTokenAndRest(str, token, rest);
@ -127,6 +137,20 @@ namespace endofthejedi {
glClearColor(0.0, 0.0, 0.0, 1.0);
m_postprocess_fbo.bind();
m_postprocess_tex0.bind();
m_postprocess_tex0.fill(0, 3, m_w, m_h, 0, GL_RGB, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
m_postprocess_tex1.bind();
m_postprocess_tex1.fill(0, 3, m_w, m_h, 0, GL_RGB, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
m_postprocess_fbo.attachTexture(GL_COLOR_ATTACHMENT0,
m_postprocess_tex0.getName());
renderBackgroundImage();
//float s = 0.1;
@ -150,13 +174,30 @@ namespace endofthejedi {
renderTraces();
m_postprocess_fbo.unbind();
//glColor3f(1.0, 0.0, 0.0);
glActiveTexture(GL_TEXTURE0);
m_postprocess_tex0.bind();
glActiveTexture(GL_TEXTURE1);
m_postprocess_tex1.bind();
//glBegin(GL_QUADS);
m_postprocess_shader.bind();
glUniform1i(m_postprocess_shader.location("tex0"), 0);
glUniform1i(m_postprocess_shader.location("tex1"), 1);
glUniform2f(m_postprocess_shader.location("uvScale"), 1, 1);
glUniform2f(m_postprocess_shader.location("scale"), 1.0f / 1000.0f, 0.0f);
//glVertex2f(-1.0f, -1.0f);
//glVertex2f(1.0f, -1.0f);
//glVertex2f(1.0f, 1.0f);
//glVertex2f(-1.0f, 1.0f);
//glEnd();
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_QUADS);
glVertex2f(-1.0f, -1.0f);
glVertex2f(1.0f, -1.0f);
glVertex2f(1.0f, 1.0f);
glVertex2f(-1.0f, 1.0f);
glEnd();
m_lastTime = state->timestamp();
}
@ -471,7 +512,18 @@ namespace endofthejedi {
*dest = new PolygonModel(filename);
if (!(*dest)->import()) {
std::cout<<"error: failed to load needed model!!!" << std::endl << std::endl;
std::cout << "error: failed to load needed model!!!" << std::endl
<< std::endl;
exit(-1);
}
(*dest)->setup(&m_shader_game_objects);
(*dest)->uploadToOpenGl();
*dest = new PolygonModel(filename);
if (!(*dest)->import()) {
std::cout << "error: failed to load needed model!!!" << std::endl
<< std::endl;
exit(-1);
}
@ -609,9 +661,10 @@ namespace endofthejedi {
}
}
void RendererPolygon3d::setWindowSize(int px, int py)
{
m_aspectRatio = (float) px / (float) py;
void RendererPolygon3d::setWindowSize(int px, int py) {
m_aspectRatio = (float)px / (float)py;
m_w = px;
m_h = py;
}
void RendererPolygon3d::setCameraMatrix(const glm::mat4 &cam)

View file

@ -96,5 +96,12 @@ namespace endofthejedi {
std::string m_backgroundTexturePath;
ImageTexture *m_texture;
Shader m_postprocess_shader;
Texture m_postprocess_tex0;
Texture m_postprocess_tex1;
Framebuffer m_postprocess_fbo;
int m_w;
int m_h;
};
}