Browse Source

new font / blur+chromatic aberration boosted on screen corners / various optimization in postfx

master
parent
commit
1e4b5ca759
8 changed files with 90 additions and 84 deletions
  1. +7
    -9
      neercs/neercs.cpp
  2. +15
    -13
      neercs/video/blurh.lolfx
  3. +15
    -13
      neercs/video/blurv.lolfx
  4. +10
    -10
      neercs/video/postfx.lolfx
  5. +1
    -1
      neercs/video/remanency.lolfx
  6. +40
    -35
      neercs/video/render.cpp
  7. BIN
      neercs/video/resource/charset_p0t-noodle.png
  8. +2
    -3
      neercs/video/text-render.cpp

+ 7
- 9
neercs/neercs.cpp View File

@@ -78,7 +78,7 @@ void Neercs::TickGame(float seconds)

m_time += seconds;

/* draw something */
/* draw something awesome */
int bg_color = 0x222;
int w = caca_get_canvas_width(m_caca);
int h = caca_get_canvas_height(m_caca);
@@ -86,7 +86,7 @@ void Neercs::TickGame(float seconds)
caca_set_color_argb(m_caca, 0xfff, bg_color);
caca_clear_canvas(m_caca);

caca_set_color_argb(m_caca, 0xa46, bg_color);
caca_set_color_argb(m_caca, 0x545, bg_color);
for(int i = 0; i < h; i++)
{
float a = M_PI / 180 * i * 16 + m_time * 4;
@@ -105,20 +105,18 @@ void Neercs::TickGame(float seconds)
caca_draw_line(m_caca, i, y - 1, i, y + 1,'%');
}

/*
__ _________ ______ ______ ______ ______
/ \/ / __ Y __ Y __ Y ___// ___/
/* __ _________ ______ ______ ______ ______
/ \/ / __ > __ > __ > ___// ___/ \x0a9
/ / ____/ ____/ __ < <____\___ \
/__/\__/\_______________/ \________________\
*/
/__/\__/\_______________/ \________________\ */

int logo_x = (w - 46) / 2;
int logo_y = h / 2 - 2;
int logo_y = h / 2 - 2;// + h / 4 * lol::cos(m_time * 2);

caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 ), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 )), bg_color);
caca_put_str(m_caca, logo_x + 3, logo_y ,"__ _________ ______ ______ ______ ______");
caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 + M_PI / 4 * 1), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 1)), bg_color);
caca_put_str(m_caca, logo_x + 2, logo_y + 1, "/ \\/ / __ Y __ Y __ Y ___// ___/");
caca_put_str(m_caca, logo_x + 2, logo_y + 1, "/ \\/ / __ > __ > __ > ___// ___/");
caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 + M_PI / 4 * 2), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 2)), bg_color);
caca_put_str(m_caca, logo_x + 1, logo_y + 2, "/ / ____/ ____/ __ < <____\\___ \\");
caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 + M_PI / 4 * 3), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 3)), bg_color);


+ 15
- 13
neercs/video/blurh.lolfx View File

@@ -14,23 +14,25 @@ void main()

uniform sampler2D texture;
uniform vec2 screen_size;
uniform float time;
uniform float value;
uniform float blur;
uniform float deform;

float blur=value;
const float PI=3.14159265358979323846;

void main(void)
{
vec4 total=vec4(0.0);
vec2 p=gl_TexCoord[0].xy/screen_size;
total+=texture2D(texture,vec2(p.x-blur*4.0,p.y))*0.04;
total+=texture2D(texture,vec2(p.x-blur*3.0,p.y))*0.08;
total+=texture2D(texture,vec2(p.x-blur*2.0,p.y))*0.12;
total+=texture2D(texture,vec2(p.x-blur ,p.y))*0.16;
total+=texture2D(texture,vec2(p.x ,p.y))*0.20;
total+=texture2D(texture,vec2(p.x+blur ,p.y))*0.16;
total+=texture2D(texture,vec2(p.x+blur*2.0,p.y))*0.12;
total+=texture2D(texture,vec2(p.x+blur*3.0,p.y))*0.08;
total+=texture2D(texture,vec2(p.x+blur*4.0,p.y))*0.04;
float mask=2.0-p.x*(6.0-p.x*6.0)*p.y*(6.0-p.y*6.0);
float b=blur+deform*mask;
total+=texture2D(texture,vec2(p.x-b*4.0,p.y))*0.04;
total+=texture2D(texture,vec2(p.x-b*3.0,p.y))*0.08;
total+=texture2D(texture,vec2(p.x-b*2.0,p.y))*0.12;
total+=texture2D(texture,vec2(p.x-b ,p.y))*0.16;
total+=texture2D(texture,vec2(p.x ,p.y))*0.20;
total+=texture2D(texture,vec2(p.x+b ,p.y))*0.16;
total+=texture2D(texture,vec2(p.x+b*2.0,p.y))*0.12;
total+=texture2D(texture,vec2(p.x+b*3.0,p.y))*0.08;
total+=texture2D(texture,vec2(p.x+b*4.0,p.y))*0.04;
gl_FragColor=total;
}
}

+ 15
- 13
neercs/video/blurv.lolfx View File

@@ -14,23 +14,25 @@ void main()

uniform sampler2D texture;
uniform vec2 screen_size;
uniform float time;
uniform float value;
uniform float blur;
uniform float deform;

float blur=value;
const float PI=3.14159265358979323846;

void main(void)
{
vec4 total=vec4(0.0);
vec2 p=gl_TexCoord[0].xy/screen_size;
total+=texture2D(texture,vec2(p.x,p.y-blur*4.0))*0.04;
total+=texture2D(texture,vec2(p.x,p.y-blur*3.0))*0.08;
total+=texture2D(texture,vec2(p.x,p.y-blur*2.0))*0.12;
total+=texture2D(texture,vec2(p.x,p.y-blur ))*0.16;
total+=texture2D(texture,vec2(p.x,p.y ))*0.20;
total+=texture2D(texture,vec2(p.x,p.y+blur ))*0.16;
total+=texture2D(texture,vec2(p.x,p.y+blur*2.0))*0.12;
total+=texture2D(texture,vec2(p.x,p.y+blur*3.0))*0.08;
total+=texture2D(texture,vec2(p.x,p.y+blur*4.0))*0.04;
float mask=2.0-p.x*(6.0-p.x*6.0)*p.y*(6.0-p.y*6.0);
float b=blur+deform*mask;
total+=texture2D(texture,vec2(p.x,p.y-b*4.0))*0.04;
total+=texture2D(texture,vec2(p.x,p.y-b*3.0))*0.08;
total+=texture2D(texture,vec2(p.x,p.y-b*2.0))*0.12;
total+=texture2D(texture,vec2(p.x,p.y-b ))*0.16;
total+=texture2D(texture,vec2(p.x,p.y ))*0.20;
total+=texture2D(texture,vec2(p.x,p.y+b ))*0.16;
total+=texture2D(texture,vec2(p.x,p.y+b*2.0))*0.12;
total+=texture2D(texture,vec2(p.x,p.y+b*3.0))*0.08;
total+=texture2D(texture,vec2(p.x,p.y+b*4.0))*0.04;
gl_FragColor=total;
}
}

+ 10
- 10
neercs/video/postfx.lolfx View File

@@ -16,17 +16,18 @@ uniform sampler2D texture;
uniform vec2 screen_size;
uniform float time;
uniform float flash;
uniform float value;
uniform float noise;
uniform float aberration;
uniform float deform;
uniform bool scanline;
uniform float sync;

const float PI=3.14159265358979323846;
float lens=deform+sync*0.0625;

vec2 zoom(in vec2 p,in float radius)
{
float zoom=1.5-(radius*cos(p.x*lens)+radius*cos(p.y*lens));
float d=deform+sync*0.0625;
float zoom=1.5-(radius*cos(p.x*d)+radius*cos(p.y*d));
return p*zoom-0.5;
}

@@ -53,14 +54,14 @@ void main(void)
vec2 z =zoom(p,0.5250);
vec2 z1=zoom(p,0.5225);
vec2 z2=zoom(p,0.5275);
float g=(2.0-cos(lens*0.5+z.x*lens)-cos(lens*0.5+z.y*lens))*32.0;
float mask=q.x*(6.0-q.x*6.0)*q.y*(6.0-q.y*6.0);

float rnd1=rand(vec2(p.x+time,p.y-time));
float rnd2=rand(vec2(p.x-time,p.y+time));
float d1=rnd1*value/float(screen_size.x);
float d2=rnd2*value/float(screen_size.y);
float d1=rnd1*noise/float(screen_size.x);
float d2=rnd2*noise/float(screen_size.y);

vec3 source;//=get_color(texture,z);
vec3 source;
source.x=get_color(texture,vec2(z.x+d1,z.y)).x;
source.y=get_color(texture,vec2(z.x+d1,z.y)).y;
source.z=get_color(texture,vec2(z.x+d1,z.y)).z;
@@ -68,7 +69,7 @@ void main(void)
vec3 glass1=get_color(texture,z1);
vec3 glass2=get_color(texture,z2);

float v=value/float(screen_size.x)*g;
float v=aberration/float(screen_size.x)+aberration/float(screen_size.x)*(2.0-mask);

vec3 noise;
noise.x=get_color(texture,vec2(z.x+d1-v,z.y+d2)).x;
@@ -90,8 +91,7 @@ void main(void)
color*=0.675;
}
color=vec3(color.x*0.875,color.y*1.0,color.z*0.75);
color*=q.x*(6.0-q.x*6.0)*q.y*(6.0-q.y*6.0); // vignetting
//color*=2.0*letterbox(z,-0.75,0.125)*2.0; // vignetting
color*=mask; // vignetting
color*=letterbox(z,-0.75,0.95); // letterbox
gl_FragColor=vec4(color,1.0);
}

+ 1
- 1
neercs/video/remanency.lolfx View File

@@ -15,7 +15,7 @@ void main()
uniform sampler2D texture;
uniform sampler2D texture_buffer;
uniform vec2 screen_size;
uniform float time;
uniform float screen_color;
uniform float value1;
uniform float value2;



+ 40
- 35
neercs/video/render.cpp View File

@@ -84,7 +84,7 @@ float beat_speed = 2.0f; // speed
/* window variable */
ivec2 border; // border width
/* text variable */
ivec2 ratio_2d(2,4); // 2d ratio
ivec2 ratio_2d(2,3); // 2d ratio
ivec2 map_size(256,256); // texture map size
ivec2 font_size(8,8); // font size
ivec2 canvas_char(0,0); // canvas char number
@@ -99,8 +99,10 @@ float glow_mix_ratio2 = 0.5f; // source mixing ratio
float radial_value1 = 2.0f;
float radial_value2 = 0.8f;
float radial_color = 0; // color
bool postfx_scanline = true;
float postfx_deform = 0.625f; // deformation ratio
float postfx_noise = 4.0f; // noise
float postfx_aberration = 3.0f; // chromatic aberration
bool postfx_scanline = true; // scanline

Shader *shader_simple;
Shader *shader_blur_h, *shader_blur_v;
@@ -109,16 +111,16 @@ Shader *shader_remanency, *shader_glow, *shader_radial, *shader_postfx;
ShaderUniform shader_simple_texture;
ShaderUniform shader_blur_h_texture,
shader_blur_h_screen_size,
shader_blur_h_time,
shader_blur_h_value;
shader_blur_h_blur,
shader_blur_h_deform;
ShaderUniform shader_blur_v_texture,
shader_blur_v_screen_size,
shader_blur_v_time,
shader_blur_v_value;
shader_blur_v_blur,
shader_blur_v_deform;
ShaderUniform shader_remanency_texture,
shader_remanency_texture_buffer,
shader_remanency_screen_size,
shader_remanency_time,
shader_remanency_screen_color,
shader_remanency_value1,
shader_remanency_value2;
ShaderUniform shader_glow_texture,
@@ -138,10 +140,11 @@ ShaderUniform shader_postfx_texture,
shader_postfx_texture_2d,
shader_postfx_screen_size,
shader_postfx_time,
shader_postfx_flash,
shader_postfx_value,
shader_postfx_deform,
shader_postfx_noise,
shader_postfx_aberration,
shader_postfx_scanline,
shader_postfx_flash,
shader_postfx_sync;

FrameBuffer *fbo_back, *fbo_front, *fbo_buffer;
@@ -195,20 +198,20 @@ int Render::InitDraw(void)
shader_blur_h = Shader::Create(lolfx_blurh);
shader_blur_h_texture = shader_blur_h->GetUniformLocation("texture");
shader_blur_h_screen_size = shader_blur_h->GetUniformLocation("screen_size");
shader_blur_h_time = shader_blur_h->GetUniformLocation("time");
shader_blur_h_value = shader_blur_h->GetUniformLocation("value");
shader_blur_h_blur = shader_blur_h->GetUniformLocation("blur");
shader_blur_h_deform = shader_blur_h->GetUniformLocation("deform");
// shader blur vertical
shader_blur_v = Shader::Create(lolfx_blurv);
shader_blur_v_texture = shader_blur_v->GetUniformLocation("texture");
shader_blur_v_screen_size = shader_blur_v->GetUniformLocation("screen_size");
shader_blur_v_time = shader_blur_v->GetUniformLocation("time");
shader_blur_v_value = shader_blur_v->GetUniformLocation("value");
shader_blur_v_blur = shader_blur_v->GetUniformLocation("blur");
shader_blur_v_deform = shader_blur_v->GetUniformLocation("deform");
// shader remanency
shader_remanency = Shader::Create(lolfx_remanency);
shader_remanency_texture = shader_remanency->GetUniformLocation("texture");
shader_remanency_texture_buffer = shader_remanency->GetUniformLocation("texture_buffer");
shader_remanency_screen_size = shader_remanency->GetUniformLocation("screen_size");
shader_remanency_time = shader_remanency->GetUniformLocation("time");
shader_remanency_screen_color = shader_remanency->GetUniformLocation("screen_color");
shader_remanency_value1 = shader_remanency->GetUniformLocation("value1");
shader_remanency_value2 = shader_remanency->GetUniformLocation("value2");
// shader glow
@@ -234,10 +237,11 @@ int Render::InitDraw(void)
shader_postfx_texture_2d = shader_postfx->GetUniformLocation("texture_2d");
shader_postfx_screen_size = shader_postfx->GetUniformLocation("screen_size");
shader_postfx_time = shader_postfx->GetUniformLocation("time");
shader_postfx_flash = shader_postfx->GetUniformLocation("flash");
shader_postfx_value = shader_postfx->GetUniformLocation("value");
shader_postfx_deform = shader_postfx->GetUniformLocation("deform");
shader_postfx_noise = shader_postfx->GetUniformLocation("noise");
shader_postfx_aberration = shader_postfx->GetUniformLocation("aberration");
shader_postfx_scanline = shader_postfx->GetUniformLocation("scanline");
shader_postfx_flash = shader_postfx->GetUniformLocation("flash");
shader_postfx_sync = shader_postfx->GetUniformLocation("sync");

return true;
@@ -265,8 +269,8 @@ Render::Render(caca_canvas_t *caca)
m_pause(false),
m_polygon(true),
m_shader(true),
m_shader_blur(true),
m_shader_remanency(true),
m_shader_blur(true),
m_shader_glow(true),
m_shader_fx(true),
m_shader_postfx(true),
@@ -432,7 +436,7 @@ void Render::Draw3D()
shader_remanency->SetTexture(shader_remanency_texture, fbo_back->GetTexture(), 0);
shader_remanency->SetTexture(shader_remanency_texture_buffer, fbo_buffer->GetTexture(), 1);
shader_remanency->SetUniform(shader_remanency_screen_size, vec2(1.0f));
shader_remanency->SetUniform(shader_remanency_time, fx_angle);
shader_remanency->SetUniform(shader_remanency_screen_color, screen_color);
shader_remanency->SetUniform(shader_remanency_value1, 0.25f);
shader_remanency->SetUniform(shader_remanency_value2, 0.75f);
fs_quad();
@@ -448,9 +452,9 @@ void Render::Draw3D()
shader_remanency->SetTexture(shader_remanency_texture, fbo_front->GetTexture(), 0);
shader_remanency->SetTexture(shader_remanency_texture_buffer, fbo_buffer->GetTexture(), 1);
shader_remanency->SetUniform(shader_remanency_screen_size, vec2(1.0f));
shader_remanency->SetUniform(shader_remanency_time, fx_angle);
shader_remanency->SetUniform(shader_remanency_value1, 0.25f);
shader_remanency->SetUniform(shader_remanency_value2, 0.75f);
shader_remanency->SetUniform(shader_remanency_screen_color, screen_color);
shader_remanency->SetUniform(shader_remanency_value1, 0.75f);
shader_remanency->SetUniform(shader_remanency_value2, 0.25f);
fs_quad();
shader_remanency->Unbind();
fbo_ping->Unbind();
@@ -467,8 +471,8 @@ void Render::Draw3D()
shader_blur_h->Bind();
shader_blur_h->SetTexture(shader_blur_h_texture, fbo_back->GetTexture(), 0);
shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f));
shader_blur_h->SetUniform(shader_blur_h_time, fx_angle);
shader_blur_h->SetUniform(shader_blur_h_value, 0.375f/screen_size.x);
shader_blur_h->SetUniform(shader_blur_h_blur, 0.25f / screen_size.x);
shader_blur_h->SetUniform(shader_blur_h_deform, 0.375f / screen_size.x);
fs_quad();
shader_blur_h->Unbind();
fbo_ping->Unbind();
@@ -477,8 +481,8 @@ void Render::Draw3D()
shader_blur_v->Bind();
shader_blur_v->SetTexture(shader_blur_v_texture, fbo_ping->GetTexture(), 0);
shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f));
shader_blur_v->SetUniform(shader_blur_v_time, fx_angle);
shader_blur_v->SetUniform(shader_blur_v_value, 0.375f/screen_size.y);
shader_blur_v->SetUniform(shader_blur_v_blur, 0.25f / screen_size.y);
shader_blur_v->SetUniform(shader_blur_v_deform, 0.375f / screen_size.y);
fs_quad();
shader_blur_v->Unbind();
}
@@ -497,8 +501,8 @@ void Render::Draw3D()
shader_blur_h->Bind();
shader_blur_h->SetTexture(shader_blur_h_texture, fbo_ping->GetTexture(), 0);
shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f / glow_fbo_size));
shader_blur_h->SetUniform(shader_blur_h_time, fx_angle);
shader_blur_h->SetUniform(shader_blur_h_value, 2.5f / screen_size.x);
shader_blur_h->SetUniform(shader_blur_h_blur, 2.5f / screen_size.x);
shader_blur_h->SetUniform(shader_blur_h_deform, 0.5f / screen_size.x);
fs_quad();
shader_blur_h->Unbind();
fbo_blur_h->Unbind();
@@ -507,8 +511,8 @@ void Render::Draw3D()
shader_blur_v->Bind();
shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f / glow_fbo_size));
shader_blur_v->SetUniform(shader_blur_v_time, fx_angle);
shader_blur_v->SetUniform(shader_blur_h_value, 2.5f / screen_size.y);
shader_blur_v->SetUniform(shader_blur_v_blur, 2.5f / screen_size.y);
shader_blur_v->SetUniform(shader_blur_v_deform, 0.5f / screen_size.y);
fs_quad();
shader_blur_v->Unbind();
fbo_blur_v->Unbind();
@@ -517,8 +521,8 @@ void Render::Draw3D()
shader_blur_h->Bind();
shader_blur_h->SetTexture(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0);
shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f / glow_fbo_size));
shader_blur_h->SetUniform(shader_blur_h_time, fx_angle);
shader_blur_h->SetUniform(shader_blur_h_value, 1.0f / screen_size.x);
shader_blur_h->SetUniform(shader_blur_h_blur, 1.0f / screen_size.x);
shader_blur_h->SetUniform(shader_blur_h_deform, 0.5f / screen_size.x);
fs_quad();
shader_blur_h->Unbind();
fbo_blur_h->Unbind();
@@ -527,8 +531,8 @@ void Render::Draw3D()
shader_blur_v->Bind();
shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f / glow_fbo_size));
shader_blur_v->SetUniform(shader_blur_v_time, fx_angle);
shader_blur_v->SetUniform(shader_blur_h_value, 1.0f / screen_size.y);
shader_blur_v->SetUniform(shader_blur_v_blur, 1.0f / screen_size.y);
shader_blur_h->SetUniform(shader_blur_v_deform, 0.5f / screen_size.y);
fs_quad();
shader_blur_v->Unbind();
fbo_blur_v->Unbind();
@@ -559,10 +563,11 @@ void Render::Draw3D()
shader_postfx->SetTexture(shader_postfx_texture, fbo_pong->GetTexture(), 0);
shader_postfx->SetUniform(shader_postfx_screen_size, (vec2)screen_size);
shader_postfx->SetUniform(shader_postfx_time, fx_angle);
shader_postfx->SetUniform(shader_postfx_flash, flash_value);
shader_postfx->SetUniform(shader_postfx_value, 4.0f);
shader_postfx->SetUniform(shader_postfx_deform, postfx_deform);
shader_postfx->SetUniform(shader_postfx_noise, postfx_noise);
shader_postfx->SetUniform(shader_postfx_aberration, postfx_aberration);
shader_postfx->SetUniform(shader_postfx_scanline, postfx_scanline);
shader_postfx->SetUniform(shader_postfx_flash, flash_value);
shader_postfx->SetUniform(shader_postfx_sync, (float)fabs(beat_value*cosf((main_angle-beat_angle)*8.0f)));
fs_quad();
shader_postfx->Unbind();


BIN
neercs/video/resource/charset_p0t-noodle.png View File

Before After
Width: 256  |  Height: 256  |  Size: 4.0 KiB

+ 2
- 3
neercs/video/text-render.cpp View File

@@ -40,7 +40,7 @@ TextRender::TextRender(caca_canvas_t *caca, ivec2 font_size)

void TextRender::Init()
{
m_font = new TileSet("tools/neercs/video/resource/charset_amiga.png",
m_font = new TileSet("tools/neercs/video/resource/charset_p0t-noodle.png",
ivec2(256, 256), ivec2(1));

m_shader = Shader::Create(lolfx_text);
@@ -168,5 +168,4 @@ void TextRender::Blit(ivec2 pos, ivec2 size)
glTexCoord2f(tc.x, 0.0f);
glVertex2i(pos.x + size.x, pos.y + size.y);
glEnd();
}

}

Loading…
Cancel
Save