diff --git a/neercs/Makefile.am b/neercs/Makefile.am index ef43fee..d872855 100644 --- a/neercs/Makefile.am +++ b/neercs/Makefile.am @@ -17,8 +17,8 @@ neercs_SOURCES = \ video/text-render.cpp video/text-render.h \ video/simple.lolfx \ video/blurh.lolfx video/blurv.lolfx video/glow.lolfx \ - video/remanence.lolfx video/copper.lolfx video/color.lolfx \ - video/noise.lolfx video/postfx.lolfx video/mirror.lolfx \ + video/remanence.lolfx video/copper.lolfx video/color.lolfx video/noise.lolfx \ + video/postfx.lolfx video/mirror.lolfx video/radial.lolfx \ video/text.lolfx neercs_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ @CACA_CFLAGS@ -Iold neercs_LDADD = diff --git a/neercs/neercs.vcxproj b/neercs/neercs.vcxproj index d6c1e84..1070b1e 100644 --- a/neercs/neercs.vcxproj +++ b/neercs/neercs.vcxproj @@ -92,6 +92,7 @@ + {587FCCE9-1D8D-4398-B8B6-E8F4E9A92233} diff --git a/neercs/neercs.vcxproj.filters b/neercs/neercs.vcxproj.filters index bef2019..009e547 100644 --- a/neercs/neercs.vcxproj.filters +++ b/neercs/neercs.vcxproj.filters @@ -159,5 +159,8 @@ video + + video + \ No newline at end of file diff --git a/neercs/term/term.cpp b/neercs/term/term.cpp index 57e6b09..dcc16d9 100644 --- a/neercs/term/term.cpp +++ b/neercs/term/term.cpp @@ -253,4 +253,4 @@ void Term::DrawFancyShit() caca_put_str(m_caca, 0, 2, "root@lol:~/ echo LOL"); caca_put_str(m_caca, 0, 3, "LOL"); caca_put_str(m_caca, 0, 4, "root@lol:~/"); -} +} \ No newline at end of file diff --git a/neercs/video/color.lolfx b/neercs/video/color.lolfx index c186810..e3fac7a 100644 --- a/neercs/video/color.lolfx +++ b/neercs/video/color.lolfx @@ -23,13 +23,13 @@ void main(void) vec2 p = gl_FragCoord.xy/screen_size.xy; vec3 c = texture2D(texture,p).xyz; - float a = (c.x+c.y+c.z)/3.0; - c = mix(c,vec3(a),color.w); // grayscale + float a = (c.x + c.y + c.z) / 3.0; + c = mix(c, vec3(a), color.w); // grayscale c *= filter; // filter - c += color.z*0.1; // level + c += color.z * 0.1; // level c *= color.x; // brightness - c = 0.5+(c-0.5)*color.y; // contrast + c = 0.5 + (c - 0.5) * color.y; // contrast c += flash; // flash - gl_FragColor = vec4(c,1.0); + gl_FragColor = vec4(c, 1.0); } \ No newline at end of file diff --git a/neercs/video/mirror.lolfx b/neercs/video/mirror.lolfx index 67eb8fc..8972a8d 100644 --- a/neercs/video/mirror.lolfx +++ b/neercs/video/mirror.lolfx @@ -19,13 +19,13 @@ uniform vec4 mirror; void main(void) { vec2 p = gl_TexCoord[0].xy; - vec3 source = texture2D(texture, p).xyz; + vec3 s = texture2D(texture, p).xyz; - vec3 color = vec3(0.0); - if(p.x < mirror.x) color = (texture2D(texture, vec2(mirror.x + (mirror.x - p.x) * mirror.w, p.y)).xyz) * (mirror.z / mirror.x * p.x); - if(p.x > 1.0 - mirror.x) color = (texture2D(texture, vec2(- mirror.x - (mirror.x + p.x) * mirror.w, p.y)).xyz) * (mirror.z / mirror.x * (1.0 - p.x)); - if(p.y < mirror.y) color = (texture2D(texture, vec2(p.x, mirror.y + (mirror.y - p.y) * mirror.w)).xyz) * (mirror.z / mirror.y * p.y); - if(p.y > 1.0 - mirror.y) color = (texture2D(texture, vec2(p.x, - mirror.y - (mirror.y + p.y) * mirror.w)).xyz) * (mirror.z / mirror.y * (1.0 - p.y)); + vec3 c = vec3(0.0); + if(p.x < mirror.x) c = (texture2D(texture, vec2(mirror.x + (mirror.x - p.x) * mirror.w, p.y)).xyz) * (mirror.z / mirror.x * p.x); + if(p.x > 1.0 - mirror.x) c = (texture2D(texture, vec2(- mirror.x - (mirror.x + p.x) * mirror.w, p.y)).xyz) * (mirror.z / mirror.x * (1.0 - p.x)); + if(p.y < mirror.y) c = (texture2D(texture, vec2(p.x, mirror.y + (mirror.y - p.y) * mirror.w)).xyz) * (mirror.z / mirror.y * p.y); + if(p.y > 1.0 - mirror.y) c = (texture2D(texture, vec2(p.x, - mirror.y - (mirror.y + p.y) * mirror.w)).xyz) * (mirror.z / mirror.y * (1.0 - p.y)); - gl_FragColor = vec4(source + color + color * color, 1.0); + gl_FragColor = vec4(s + c, 1.0); } \ No newline at end of file diff --git a/neercs/video/postfx.lolfx b/neercs/video/postfx.lolfx index 0b81848..5abcef2 100644 --- a/neercs/video/postfx.lolfx +++ b/neercs/video/postfx.lolfx @@ -4,8 +4,8 @@ void main() { - gl_Position = gl_Vertex; - gl_TexCoord[0] = gl_MultiTexCoord0; + gl_Position=gl_Vertex; + gl_TexCoord[0]=gl_MultiTexCoord0; } [frag.glsl] @@ -30,7 +30,7 @@ uniform float beat; vec2 screen(in vec2 p,in float radius) { - float d = deform.x+sync*0.0625+beat*0.0375; + float d=deform.x+sync*0.0625+beat*0.0375; return p*(1.5-(radius*cos(p.x*d)+radius*cos(p.y*d)))-0.5; } @@ -46,30 +46,36 @@ float letterbox(in vec2 p,in float w,in float radius,in float smooth) void main(void) { - vec2 q = gl_FragCoord.xy/screen_size.xy; - vec2 p = -1.0+2.0*gl_FragCoord.xy/screen_size.xy; - p.y += 0.025*sync; - vec2 z = screen(p,deform.y); - vec2 z1 = screen(p,deform.y+ghost1.z*0.01); - vec2 z2 = screen(p,deform.y+ghost2.z*0.01); - float mask = q.x*(6.0-q.x*6.0)*q.y*(6.0-q.y*6.0); + vec2 q=gl_FragCoord.xy/screen_size.xy; + vec2 p=-1.0+2.0*gl_FragCoord.xy/screen_size.xy; + p.y+=0.025*sync; + vec2 z=screen(p,deform.y); + vec2 z1=screen(p,deform.y+ghost1.z*0.01); + vec2 z2=screen(p,deform.y+ghost2.z*0.01); + float mask=q.x*(6.0-q.x*6.0)*q.y*(6.0-q.y*6.0); - vec3 source = get_color(texture,z); - vec3 g1 = get_color(texture,z1-ghost1.xy*0.01); - vec3 g2 = get_color(texture,z2-ghost2.xy*0.01); + vec3 source=get_color(texture,z); + vec3 g1=get_color(texture,z1-ghost1.xy*0.01); + vec3 g2=get_color(texture,z2-ghost2.xy*0.01); - vec3 c = source+g1*ghost1.w+g2*ghost2.w; // mix + vec3 c=source+g1*ghost1.w+g2*ghost2.w; // mix - float v = aberration/float(screen_size.x);//+aberration/float(screen_size.x)*(2.0-mask); - vec3 ca1 = get_color(texture,vec2(z.x-v,z.y)); - vec3 ca2 = get_color(texture,vec2(z.x+v,z.y)); - c += vec3(ca1.x,c.y,ca2.z); // chromatic aberration + float v=aberration/float(screen_size.x);//+aberration/float(screen_size.x)*(2.0-mask); + vec3 ca1=get_color(texture,vec2(z.x-v,z.y)); + vec3 ca2=get_color(texture,vec2(z.x+v,z.y)); + c+=vec3(ca1.x,c.y,ca2.z); // chromatic aberration - c *= moire_h.x+moire_h.y*sin(z.y*float(screen_size.y*moire_h.z))*sin(0.5+z.x*float(screen_size.x*moire_h.w)); // moire h - c *= moire_v.x+moire_v.y*sin(z.x*float(screen_size.x*moire_v.z))*sin(0.5+z.y*float(screen_size.y*moire_v.w)); // moire v - c *= scanline_h.x+scanline_h.y*cos(z.y*float(screen_size.y*scanline_h.z+scanline_h.w)); // scanline h - c *= scanline_v.x+scanline_v.y*cos(z.x*float(screen_size.x*scanline_v.z+scanline_v.w)); // scanline v - c *= mix(1.0,mask,vignetting); // vignetting - c *= letterbox(z,corner.x+2.0,corner.y,corner.z); // corner - gl_FragColor = vec4(c,1.0); + vec3 c1=vec3(0.3,0.2,0.2); + vec3 c2=vec3(1.0,1.0,1.0); + vec3 c3=vec3(0.0,0.4,0.7); + + c+=((p.y<0.0)?mix(c1,c2,1.0+p.y):mix(c2,c3,p.y))*0.25; // reflection + + c*=moire_h.x+moire_h.y*sin(z.y*float(screen_size.y*moire_h.z))*sin(0.5+z.x*float(screen_size.x*moire_h.w)); // moire h + c*=moire_v.x+moire_v.y*sin(z.x*float(screen_size.x*moire_v.z))*sin(0.5+z.y*float(screen_size.y*moire_v.w)); // moire v + c*=scanline_h.x+scanline_h.y*cos(z.y*float(screen_size.y*scanline_h.z+scanline_h.w)); // scanline h + c*=scanline_v.x+scanline_v.y*cos(z.x*float(screen_size.x*scanline_v.z+scanline_v.w)); // scanline v + c*=mix(1.0,mask,vignetting); // vignetting + c*=letterbox(z,corner.x+2.0,corner.y,corner.z); // corner + gl_FragColor=vec4(c,1.0); } \ No newline at end of file diff --git a/neercs/video/radial.lolfx b/neercs/video/radial.lolfx new file mode 100644 index 0000000..c115f8e --- /dev/null +++ b/neercs/video/radial.lolfx @@ -0,0 +1,44 @@ +[vert.glsl] + +#version 120 + +void main() +{ + gl_Position = gl_Vertex; + gl_TexCoord[0] = gl_MultiTexCoord0; +} + +[frag.glsl] + +#version 120 + +uniform sampler2D texture; +uniform vec2 screen_size; +uniform vec4 radial; + +vec3 deform(in vec2 p) + { + float zoom = 0.5; + vec2 uv = p * zoom - 0.5; + return texture2D(texture, uv).xyz; + } + +void main(void) +{ + vec2 p = -1.0+2.0*gl_TexCoord[0].xy; + vec2 s = p; + vec3 source=deform(s); + + vec3 color = vec3(1.0,1.0,1.0); + + vec2 d = -p / float(radial.z * radial.x); + float w = 1.0; + for(int i = 0; i < radial.z; i++) + { + vec3 c = deform(s); + color += c * w; + w *= radial.y; + s += d; + } + gl_FragColor = vec4(source + color * radial.w, 1.0); +} \ No newline at end of file diff --git a/neercs/video/render.cpp b/neercs/video/render.cpp index 98802fa..9cf0154 100644 --- a/neercs/video/render.cpp +++ b/neercs/video/render.cpp @@ -42,6 +42,7 @@ extern char const *lolfx_color; extern char const *lolfx_noise; extern char const *lolfx_postfx; extern char const *lolfx_mirror; +extern char const *lolfx_radial; #define PID M_PI/180.0f // pi ratio @@ -102,11 +103,11 @@ vec2 blur(0.5f,0.0f); // blur radius [center,corner] vec4 copper_copper(0.75f,0.25f,0.42f,4.0f); // copper [base,variable,repeat,color cycle] vec3 copper_mask_color(4.0f,4.0f,4.0f); // color [red,green,blue] vec3 color_filter(0.9f,0.95f,0.85f); // color filter [red,green,blue] -vec4 color_color(1.4f,1.2f,0.1f,0.35f); // color modifier [brightness,contrast,level,grayscale] +vec4 color_color(1.0f,1.25f,0.0f,0.35f); // color modifier [brightness,contrast,level,grayscale] vec2 noise_offset(1.0f,1.0f); // random line [horizontal,vertical] float noise_noise = 0.15f; // noise vec3 noise_retrace(1.0f,1.0f,0.5f); // retrace [strength,length,speed] -vec2 postfx_deform(0.8f,0.52f); // deformation [ratio,zoom] +vec2 postfx_deform(0.8f,0.48f); // deformation [ratio,zoom] float postfx_vignetting = 0.5f; // vignetting strength float postfx_aberration = 4.0f; // chromatic aberration vec4 postfx_ghost1(1.0f,0.0f,0.0f,-0.25f); // ghost picture 1 [position x,position y,position z,strength] @@ -116,21 +117,22 @@ vec4 postfx_moire_v(0.75f,-0.25f,1.0f,1.5f); // horizontal moire [base,variab vec4 postfx_scanline_h(1.0f,0.0f,0.0f,0.0f); // vertical scanline [base,variable,repeat,shift] vec4 postfx_scanline_v(0.75f,-0.25f,2.0f,0.0f); // horizontal scanline [base,variable,repeat,shift] vec3 postfx_corner(0.0f,0.8f,0.96f); // corner [width,radius,blur] -vec4 mirror(0.6f,0.6f,0.4f,4.0f); // mirror [width,height,strength,ratio] +vec4 mirror(0.95f,0.9f,0.4f,3.0f); // mirror [width,height,strength,ratio] +vec4 radial(4.0f,0.94f,32,0.25f); // radial [distance,fade ratio,iteration,strength] /* text variable */ 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 ivec2 canvas_size(0,0); // caca size -ivec2 border(2 * ratio_2d.x * font_size.x,1 * ratio_2d.x * font_size.y); // border width +ivec2 border(2 * ratio_2d.x * font_size.x,1 * ratio_2d.y * font_size.y); // border width /* setup variable */ bool setup_switch = false; // switch [option/item] int setup_n = 0; // item/option number int setup_h = 8; // height int setup_cursor = 0; // cursor position int setup_option_i = 0; // selected option -int setup_option_n = 12; // option number +int setup_option_n = 13; // option number int setup_option_p = 0; // option position int setup_item_i = 0; // selected item int setup_item_n = 8; // item number @@ -247,6 +249,15 @@ char const *setup_text[] = { "ratio", "", "", + "", + "radial", + "enable", + "distance", + "fade ratio", + "iteration", + "strength", + "", + "", "" }; @@ -355,7 +366,16 @@ vec4 setup_var[]={ // setup variable [start,end,step,value] vec4(0.0f, 2.0f, 0.05f, mirror.x), vec4(0.0f, 2.0f, 0.05f, mirror.y), vec4(0.0f, 1.0f, 0.05f, mirror.z), - vec4(1.0f, 4.0f, 0.25f, mirror.w), + vec4(1.0f, 8.0f, 1.00f, mirror.w), + vec4(0), + vec4(0), + vec4(0), + vec4(0), /* radial blur */ + vec4(0, 1, 1, 1), + vec4(2.0f, 8.0f, 0.25f, radial.x), + vec4(0.5f, 1.0f, 0.01f, radial.y), + vec4(2.0f,64.0f, 2.00f, radial.z), + vec4(0.0f, 1.0f, 0.05f, radial.w), vec4(0), vec4(0), vec4(0), @@ -409,6 +429,9 @@ void Render::UpdateVar() k += 1; /* mirror */ m_shader_mirror = (setup_var[k].w == 1) ? true : false; k++; mirror = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4; + k += 4; /* radial blur */ + m_shader_radial = (setup_var[k].w == 1) ? true : false; k++; + radial = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4; UpdateSize(); } @@ -439,7 +462,7 @@ int calc_item_length() Shader *shader_simple; Shader *shader_blur_h, *shader_blur_v, *shader_glow; Shader *shader_remanence, *shader_copper, *shader_color; -Shader *shader_noise, *shader_postfx, *shader_mirror; +Shader *shader_noise, *shader_postfx, *shader_mirror, *shader_radial; // shader variables ShaderUniform shader_simple_texture; ShaderUniform shader_blur_h_texture, @@ -487,6 +510,9 @@ ShaderUniform shader_postfx_texture, ShaderUniform shader_mirror_texture, shader_mirror_screen_size, shader_mirror_mirror; +ShaderUniform shader_radial_texture, + shader_radial_screen_size, + shader_radial_radial; FrameBuffer *fbo_back, *fbo_front, *fbo_screen; FrameBuffer *fbo_blur_h, *fbo_blur_v; @@ -586,6 +612,11 @@ int Render::InitDraw(void) shader_mirror_texture = shader_mirror->GetUniformLocation("texture"); shader_mirror_screen_size = shader_mirror->GetUniformLocation("screen_size"); shader_mirror_mirror = shader_mirror->GetUniformLocation("mirror"); + // shader radial blur + shader_radial = Shader::Create(lolfx_radial); + shader_radial_texture = shader_radial->GetUniformLocation("texture"); + shader_radial_screen_size = shader_radial->GetUniformLocation("screen_size"); + shader_radial_radial = shader_radial->GetUniformLocation("radial"); // initialize setup setup_n = calc_item_length(); return true; @@ -604,7 +635,6 @@ Render::Render(caca_canvas_t *caca) m_fps_debug(0), m_ready(false), m_pause(false), - m_polygon(true), m_shader(true), m_shader_glow(true), m_shader_blur(true), @@ -613,7 +643,8 @@ Render::Render(caca_canvas_t *caca) m_shader_color(true), m_shader_noise(true), m_shader_postfx(true), - m_shader_mirror(true) + m_shader_mirror(true), + m_shader_radial(true) { m_txt_screen = new TextRender(m_cv_screen, font_size); m_txt_setup = new TextRender(m_cv_setup, font_size); @@ -622,18 +653,6 @@ Render::Render(caca_canvas_t *caca) void Render::TickGame(float seconds) { Entity::TickGame(seconds); - - /* draw LOLCUBE */ - /* - caca_set_color_argb(m_cv_screen, 0xfff, 0x000); - caca_put_str(m_cv_screen, canvas_char.x - 8, canvas_char.y - 6, "_______"); - caca_put_str(m_cv_screen, canvas_char.x - 9, canvas_char.y - 5, "/ /|"); - caca_put_str(m_cv_screen, canvas_char.x - 10, canvas_char.y - 4, "/______/ |"); - caca_put_str(m_cv_screen, canvas_char.x - 10, canvas_char.y - 3, "| | |"); - caca_put_str(m_cv_screen, canvas_char.x - 10, canvas_char.y - 2, "| :D | /"); - caca_put_str(m_cv_screen, canvas_char.x - 10, canvas_char.y - 1, "|______|/"); - */ - /* draw setup */ if (g_setup) { @@ -646,10 +665,12 @@ void Render::TickGame(float seconds) caca_draw_line(m_cv_setup, 0, 0, setup_size.x, 0, ' '); caca_put_str(m_cv_setup, setup_size.x / 2 - 3, 0, "SETUP"); /* informations */ + /* int w = caca_get_canvas_width(m_cv_screen); int h = caca_get_canvas_height(m_cv_screen); caca_set_color_argb(m_cv_setup, setup_color.y, setup_color.x); caca_printf(m_cv_setup, 1, 0, "%i*%i", w, h); + */ /* display option */ for (int i = 0; i < setup_h; i++) { @@ -755,9 +776,7 @@ void Render::TickDraw(float seconds) m_shader_noise = !m_shader_noise; m_shader_postfx = !m_shader_postfx; m_shader_mirror = !m_shader_mirror; - //m_polygon = !m_polygon; - //polygon_fillmode = (m_polygon)?GL_FILL:GL_LINE; - //glPolygonMode(GL_FRONT, polygon_fillmode); + m_shader_radial = !m_shader_radial; } if (Input::WasPressed(Key::Tab)) { @@ -1083,6 +1102,7 @@ void Render::Draw2D() glViewport(0, 0, screen_size.x, screen_size.y); /* Clear the back buffer */ + glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_COLOR, GL_DST_ALPHA); @@ -1094,16 +1114,12 @@ void Render::Draw2D() if (g_setup) m_txt_setup->Blit((screen_size - setup_canvas_size) / 2, setup_canvas_size); - //if (m_polygon) glEnable(GL_LINE_SMOOTH); else glDisable(GL_LINE_SMOOTH); - glLineWidth((m_polygon)?2.0f:1.0f); - fx_angle=main_angle-part_angle; - if (m_polygon) - glEnable(GL_TEXTURE_2D); - glMatrixMode(GL_PROJECTION); mat4 m = mat4::ortho(0, screen_size.x, screen_size.y, 0, -1.f, 1.f); glLoadMatrixf(&m[0][0]); glMatrixMode(GL_MODELVIEW); + + fx_angle=main_angle-part_angle; } void Render::Draw3D() @@ -1330,6 +1346,23 @@ void Render::Draw3D() fbo_front->Unbind(); } + if (m_shader_radial) + { + // shader radial blur + fbo_tmp->Bind(); + shader_radial->Bind(); + shader_radial->SetUniform(shader_radial_texture, fbo_front->GetTexture(), 0); + shader_radial->SetUniform(shader_radial_screen_size, (vec2)screen_size); + shader_radial->SetUniform(shader_radial_radial, vec4(radial.x, radial.y, radial.z, radial.w * 0.1f)); + TraceQuad(); + shader_radial->Unbind(); + fbo_tmp->Unbind(); + // shader simple + fbo_front->Bind(); + ShaderSimple(fbo_tmp, 0); + fbo_front->Unbind(); + } + // shader simple ShaderSimple(fbo_front, 0); @@ -1341,5 +1374,4 @@ Render::~Render() { if (m_fps_debug) Ticker::Unref(m_fps_debug); -} - +} \ No newline at end of file diff --git a/neercs/video/render.h b/neercs/video/render.h index 4f5b0e9..a333510 100644 --- a/neercs/video/render.h +++ b/neercs/video/render.h @@ -37,7 +37,6 @@ private: bool m_ready; bool m_pause; - bool m_polygon; bool m_shader; bool m_shader_glow; bool m_shader_blur; @@ -47,7 +46,7 @@ private: bool m_shader_noise; bool m_shader_postfx; bool m_shader_mirror; + bool m_shader_radial; }; -#endif // __VIDEO_RENDER_H__ - +#endif // __VIDEO_RENDER_H__ \ No newline at end of file