Changeset 1672 for trunk/tools


Ignore:
Timestamp:
Jul 26, 2012, 6:38:45 PM (8 years ago)
Author:
rez
Message:

postfx optimization

Location:
trunk/tools/neercs/video
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/neercs/video/blurh.lolfx

    r1661 r1672  
    1414
    1515uniform sampler2D texture;
    16 uniform vec2 screen_size;
    17 uniform float blur;
    18 uniform float deform;
    19 
    20 const float PI=3.14159265358979323846;
     16uniform vec2 radius;
    2117
    2218void main(void)
    2319        {
    2420        vec4 total=vec4(0.0);
    25         vec2 p=gl_TexCoord[0].xy/screen_size;
     21        vec2 p=gl_TexCoord[0].xy;
    2622        float mask=2.0-p.x*(6.0-p.x*6.0)*p.y*(6.0-p.y*6.0);
    27         float b=blur+deform*mask;
     23        float b=radius.x+radius.y*mask;
    2824        total+=texture2D(texture,vec2(p.x-b*4.0,p.y))*0.04;
    2925        total+=texture2D(texture,vec2(p.x-b*3.0,p.y))*0.08;
  • trunk/tools/neercs/video/blurv.lolfx

    r1661 r1672  
    1414
    1515uniform sampler2D texture;
    16 uniform vec2 screen_size;
    17 uniform float blur;
    18 uniform float deform;
    19 
    20 const float PI=3.14159265358979323846;
     16uniform vec2 radius;
    2117
    2218void main(void)
    2319        {
    2420        vec4 total=vec4(0.0);
    25         vec2 p=gl_TexCoord[0].xy/screen_size;
     21        vec2 p=gl_TexCoord[0].xy;
    2622        float mask=2.0-p.x*(6.0-p.x*6.0)*p.y*(6.0-p.y*6.0);
    27         float b=blur+deform*mask;
     23        float b=radius.x+radius.y*mask;
    2824        total+=texture2D(texture,vec2(p.x,p.y-b*4.0))*0.04;
    2925        total+=texture2D(texture,vec2(p.x,p.y-b*3.0))*0.08;
  • trunk/tools/neercs/video/glow.lolfx

    r1459 r1672  
    1313#version 120
    1414
    15 uniform sampler2D texture;
    16 uniform sampler2D texture_prv;
    17 uniform vec2 screen_size;
    18 uniform float time;
    19 uniform float step;
    20 uniform float value1;
    21 uniform float value2;
     15uniform sampler2D glow;
     16uniform sampler2D source;
     17uniform vec3 mix;
    2218
    2319void main(void)
    2420        {
    25         vec2 p=gl_TexCoord[0].xy;
    26         vec4 source=texture2D(texture_prv,p);
    27         vec4 glow=texture2D(texture,p);
    28         source=smoothstep(step,1.0,source);
    29         vec4 color=glow*value1+source*value2;
    30         gl_FragColor=color;
     21        gl_FragColor=smoothstep(mix.z,1.0,texture2D(source,gl_TexCoord[0].xy))*mix.x+texture2D(glow,gl_TexCoord[0].xy)*mix.y;
    3122        }
  • trunk/tools/neercs/video/remanency.lolfx

    r1661 r1672  
    1313#version 120
    1414
    15 uniform sampler2D texture;
    16 uniform sampler2D texture_buffer;
    17 uniform vec2 screen_size;
    18 uniform float screen_color;
    19 uniform float value1;
    20 uniform float value2;
     15uniform sampler2D source;
     16uniform sampler2D buffer;
     17uniform vec2 mix;
    2118
    2219void main(void)
    2320        {
    24         vec2 p=gl_TexCoord[0].xy;
    25         vec4 source=texture2D(texture,p);
    26         vec4 buffer=texture2D(texture_buffer,p);
    27         vec4 color=source*value1+buffer*value2;
    28         gl_FragColor=color;
     21        gl_FragColor=texture2D(source,gl_TexCoord[0].xy)*mix.x+texture2D(buffer,gl_TexCoord[0].xy)*mix.y;
    2922        }
  • trunk/tools/neercs/video/render.cpp

    r1666 r1672  
    8585ivec2 border;              // border width
    8686/* text variable */
    87 ivec2 ratio_2d(1,4);       // 2d ratio
     87ivec2 ratio_2d(2,4);       // 2d ratio
    8888ivec2 map_size(256,256);   // texture map size
    8989ivec2 font_size(8,8);      // font size
     
    9393float value, angle, radius, scale, speed;
    9494/* shader variable */
    95 float remanency_source_mix = 0.25f;
    96 float remanency_buffer_mix = 0.75f;
    97 float remanency_new_frame_mix = 0.75f;
    98 float remanency_old_frame_mix = 0.25f;
    99 float blur_radius = 0.25f;      // glow radius
    100 float blur_radius_deform = 0.625f;// glow radius deform
    101 int glow_fbo_size = 2;          // glow fbo size
    102 float glow_smoothstep = 0.1f;   // glow smoothstep value (try 0.025f)
    103 vec3 glow_large(0.75f,2.0f,3.0f);// large glow [mix,ratio normal,ratio deform]
    104 vec3 glow_small(0.50f,1.0f,1.5f);// small glow [mix,ratio normal,ratio deform]
     95vec2 buffer(0.75f,0.25f);       // [new frame mix,old frame mix]
     96vec2 remanency(0.25f,0.75f);    // remanency [source mix,buffer mix]
     97vec2 blur(0.5f,1.0f);           // glow radius [normal,deform]
     98vec3 glow_mix(1.0f,0.0f,0.025f);// glow mix [glow mix,source mix,source smoothstep]
     99vec2 glow_large(4.0f,6.0f);     // large glow radius [normal,deform]
     100vec2 glow_small(2.0f,4.0f);     // small glow radius [normal,deform]
     101//vec3 radial(2.0f,0.8f,0);     // radial [mix,strength,color mode]
    105102//---------------------------------[IDEAS] http://www.youtube.com/watch?v=d1qEP2vMe-I
    106103float postfx_deform = 0.625f;   // deformation ratio
     
    111108float postfx_aberration = 3.0f; // chromatic aberration
    112109bool postfx_moire = true;       // moire
    113 vec4 postfx_moire_h(0.75f,0.25f,0.5f,1.5f);
    114 vec4 postfx_moire_v(0.75f,0.25f,0.5f,1.5f);
     110vec4 postfx_moire_h(0.75f,-0.25f,1.0f,2.0f);
     111vec4 postfx_moire_v(0.875f,-0.125f,0.5f,2.0f);
    115112bool postfx_scanline = true;    // scanline
    116 vec4 postfx_scanline_h(0.75f,0.25f,1.0f,0.0f);// vertical scanline [base,variable,repeat]
    117 vec4 postfx_scanline_v(1.0f,0.0f,0.0f,0.0f);
    118 //float radial_value1 = 2.0f;
    119 //float radial_value2 = 0.8f;
    120 //float radial_color = 0;
     113vec4 postfx_scanline_h(0.75f,-0.5f,2.0f,0.0f);// vertical scanline [base,variable,repeat]
     114vec4 postfx_scanline_v(1.0f,0.0f,0.0f,0.0f);  // horizontal scanline [base,variable,repeat]
    121115
    122116Shader *shader_simple;
     
    126120ShaderUniform shader_simple_texture;
    127121ShaderUniform shader_blur_h_texture,
    128               shader_blur_h_screen_size,
    129               shader_blur_h_blur,
    130               shader_blur_h_deform;
     122              shader_blur_h_radius;
    131123ShaderUniform shader_blur_v_texture,
    132               shader_blur_v_screen_size,
    133               shader_blur_v_blur,
    134               shader_blur_v_deform;
    135 ShaderUniform shader_remanency_texture,
    136               shader_remanency_texture_buffer,
    137               shader_remanency_screen_size,
    138               shader_remanency_screen_color,
    139               shader_remanency_value1,
    140               shader_remanency_value2;
    141 ShaderUniform shader_glow_texture,
    142               shader_glow_texture_prv,
    143               shader_glow_screen_size,
    144               shader_glow_time,
    145               shader_glow_step,
    146               shader_glow_value1,
    147               shader_glow_value2;
     124              shader_blur_v_radius;
     125ShaderUniform shader_remanency_source,
     126              shader_remanency_buffer,
     127              shader_remanency_mix;
     128ShaderUniform shader_glow_glow,
     129              shader_glow_source,
     130              shader_glow_mix;
    148131ShaderUniform shader_radial_texture,
    149132              shader_radial_screen_size,
     
    211194    fbo_front = new FrameBuffer(screen_size);
    212195    fbo_buffer = new FrameBuffer(screen_size);
    213     fbo_blur_h = new FrameBuffer(screen_size / glow_fbo_size);
    214     fbo_blur_v = new FrameBuffer(screen_size / glow_fbo_size);
     196    fbo_blur_h = new FrameBuffer(screen_size / 2);
     197    fbo_blur_v = new FrameBuffer(screen_size / 2);
    215198    fbo_ping = new FrameBuffer(screen_size);
    216199    fbo_pong = new FrameBuffer(screen_size);
     
    221204    shader_blur_h = Shader::Create(lolfx_blurh);
    222205    shader_blur_h_texture = shader_blur_h->GetUniformLocation("texture");
    223     shader_blur_h_screen_size = shader_blur_h->GetUniformLocation("screen_size");
    224     shader_blur_h_blur = shader_blur_h->GetUniformLocation("blur");
    225     shader_blur_h_deform = shader_blur_h->GetUniformLocation("deform");
     206    shader_blur_h_radius = shader_blur_h->GetUniformLocation("radius");
    226207    // shader blur vertical
    227208    shader_blur_v = Shader::Create(lolfx_blurv);
    228209    shader_blur_v_texture = shader_blur_v->GetUniformLocation("texture");
    229     shader_blur_v_screen_size = shader_blur_v->GetUniformLocation("screen_size");
    230     shader_blur_v_blur = shader_blur_v->GetUniformLocation("blur");
    231     shader_blur_v_deform = shader_blur_v->GetUniformLocation("deform");
     210    shader_blur_v_radius = shader_blur_v->GetUniformLocation("radius");
    232211    // shader remanency
    233212    shader_remanency = Shader::Create(lolfx_remanency);
    234     shader_remanency_texture = shader_remanency->GetUniformLocation("texture");
    235     shader_remanency_texture_buffer = shader_remanency->GetUniformLocation("texture_buffer");
    236     shader_remanency_screen_size = shader_remanency->GetUniformLocation("screen_size");
    237     shader_remanency_screen_color = shader_remanency->GetUniformLocation("screen_color");
    238     shader_remanency_value1 = shader_remanency->GetUniformLocation("value1");
    239     shader_remanency_value2 = shader_remanency->GetUniformLocation("value2");
     213    shader_remanency_source = shader_remanency->GetUniformLocation("source");
     214    shader_remanency_buffer = shader_remanency->GetUniformLocation("buffer");
     215    shader_remanency_mix = shader_remanency->GetUniformLocation("mix");
    240216    // shader glow
    241217    shader_glow = Shader::Create(lolfx_glow);
    242     shader_glow_texture = shader_glow->GetUniformLocation("texture");
    243     shader_glow_texture_prv = shader_glow->GetUniformLocation("texture_prv");
    244     shader_glow_screen_size = shader_glow->GetUniformLocation("screen_size");
    245     shader_glow_time = shader_glow->GetUniformLocation("time");
    246     shader_glow_step = shader_glow->GetUniformLocation("step");
    247     shader_glow_value1 = shader_glow->GetUniformLocation("value1");
    248     shader_glow_value2 = shader_glow->GetUniformLocation("value2");
     218    shader_glow_glow = shader_glow->GetUniformLocation("glow");
     219    shader_glow_source = shader_glow->GetUniformLocation("source");
     220    shader_glow_mix = shader_glow->GetUniformLocation("mix");
    249221    // shader radial
    250222    shader_radial = Shader::Create(lolfx_radial);
     
    465437        fbo_ping->Bind();
    466438        shader_remanency->Bind();
    467         shader_remanency->SetTexture(shader_remanency_texture, fbo_back->GetTexture(), 0);
    468         shader_remanency->SetTexture(shader_remanency_texture_buffer, fbo_buffer->GetTexture(), 1);
    469         shader_remanency->SetUniform(shader_remanency_screen_size, vec2(1.0f));
    470         shader_remanency->SetUniform(shader_remanency_screen_color, screen_color);
    471         shader_remanency->SetUniform(shader_remanency_value1, remanency_source_mix);
    472         shader_remanency->SetUniform(shader_remanency_value2, remanency_buffer_mix);
     439        shader_remanency->SetTexture(shader_remanency_source, fbo_back->GetTexture(), 0);
     440        shader_remanency->SetTexture(shader_remanency_buffer, fbo_buffer->GetTexture(), 1);
     441        shader_remanency->SetUniform(shader_remanency_mix, remanency);
    473442        fs_quad();
    474443        shader_remanency->Unbind();
     
    481450        fbo_ping->Bind();
    482451        shader_remanency->Bind();
    483         shader_remanency->SetTexture(shader_remanency_texture, fbo_front->GetTexture(), 0);
    484         shader_remanency->SetTexture(shader_remanency_texture_buffer, fbo_buffer->GetTexture(), 1);
    485         shader_remanency->SetUniform(shader_remanency_screen_size, vec2(1.0f));
    486         shader_remanency->SetUniform(shader_remanency_screen_color, screen_color);
    487         shader_remanency->SetUniform(shader_remanency_value1, remanency_new_frame_mix);
    488         shader_remanency->SetUniform(shader_remanency_value2, remanency_old_frame_mix);
     452        shader_remanency->SetTexture(shader_remanency_source, fbo_front->GetTexture(), 0);
     453        shader_remanency->SetTexture(shader_remanency_buffer, fbo_buffer->GetTexture(), 1);
     454        shader_remanency->SetUniform(shader_remanency_mix, buffer);
    489455        fs_quad();
    490456        shader_remanency->Unbind();
     
    502468        shader_blur_h->Bind();
    503469        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_back->GetTexture(), 0);
    504         shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f));
    505         shader_blur_h->SetUniform(shader_blur_h_blur, blur_radius / screen_size.x);
    506         shader_blur_h->SetUniform(shader_blur_h_deform, blur_radius_deform / screen_size.x);
     470        shader_blur_h->SetUniform(shader_blur_h_radius, blur / screen_size.x);
    507471        fs_quad();
    508472        shader_blur_h->Unbind();
     
    512476        shader_blur_v->Bind();
    513477        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_ping->GetTexture(), 0);
    514         shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f));
    515         shader_blur_v->SetUniform(shader_blur_v_blur, blur_radius / screen_size.y);
    516         shader_blur_v->SetUniform(shader_blur_v_deform, blur_radius_deform / screen_size.y);
     478        shader_blur_v->SetUniform(shader_blur_v_radius, blur / screen_size.y);
    517479        fs_quad();
    518480        shader_blur_v->Unbind();
     
    532494        shader_blur_h->Bind();
    533495        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_ping->GetTexture(), 0);
    534         shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f / glow_fbo_size));
    535         shader_blur_h->SetUniform(shader_blur_h_blur, glow_large.y / screen_size.x);
    536         shader_blur_h->SetUniform(shader_blur_h_deform, glow_large.z / screen_size.x);
     496        shader_blur_h->SetUniform(shader_blur_h_radius, glow_large / screen_size.x);
    537497        fs_quad();
    538498        shader_blur_h->Unbind();
     
    542502        shader_blur_v->Bind();
    543503        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
    544         shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f / glow_fbo_size));
    545         shader_blur_v->SetUniform(shader_blur_v_blur, glow_large.y / screen_size.y);
    546         shader_blur_v->SetUniform(shader_blur_v_deform, glow_large.z / screen_size.y);
     504        shader_blur_v->SetUniform(shader_blur_v_radius, glow_large / screen_size.y);
    547505        fs_quad();
    548506        shader_blur_v->Unbind();
     
    552510        shader_blur_h->Bind();
    553511        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0);
    554         shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f / glow_fbo_size));
    555         shader_blur_h->SetUniform(shader_blur_h_blur, glow_small.y / screen_size.x);
    556         shader_blur_h->SetUniform(shader_blur_h_deform, glow_small.z / screen_size.x);
     512        shader_blur_h->SetUniform(shader_blur_h_radius, glow_small / screen_size.x);
    557513        fs_quad();
    558514        shader_blur_h->Unbind();
     
    562518        shader_blur_v->Bind();
    563519        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
    564         shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f / glow_fbo_size));
    565         shader_blur_v->SetUniform(shader_blur_v_blur, glow_small.y / screen_size.y);
    566         shader_blur_h->SetUniform(shader_blur_v_deform, glow_small.z / screen_size.y);
     520        shader_blur_v->SetUniform(shader_blur_v_radius, glow_small / screen_size.y);
    567521        fs_quad();
    568522        shader_blur_v->Unbind();
     
    571525        fbo_pong->Bind();
    572526        shader_glow->Bind();
    573         shader_glow->SetTexture(shader_glow_texture, fbo_blur_v->GetTexture(), 0);
    574         shader_glow->SetTexture(shader_glow_texture_prv, fbo_front->GetTexture(), 1);
    575         shader_glow->SetUniform(shader_glow_screen_size, vec2(1.0f));
    576         shader_glow->SetUniform(shader_glow_time, fx_angle);
    577         shader_glow->SetUniform(shader_glow_step, glow_smoothstep);
    578         shader_glow->SetUniform(shader_glow_value1, glow_large.x);
    579         shader_glow->SetUniform(shader_glow_value2, glow_small.x);
     527        shader_glow->SetTexture(shader_glow_glow, fbo_blur_v->GetTexture(), 0);
     528        shader_glow->SetTexture(shader_glow_source, fbo_front->GetTexture(), 1);
     529        shader_glow->SetUniform(shader_glow_mix, glow_mix);
    580530        fs_quad();
    581531        shader_glow->Unbind();
Note: See TracChangeset for help on using the changeset viewer.