source: trunk/tools/neercs/video/render.cpp @ 1663

Last change on this file since 1663 was 1663, checked in by rez, 8 years ago

fixed noise / added tons of control vars to postfx

File size: 23.3 KB
Line 
1//
2// Neercs
3//
4
5#if defined HAVE_CONFIG_H
6#   include "config.h"
7#endif
8
9#if defined _XBOX
10#   define _USE_MATH_DEFINES /* for M_PI */
11#   include <xtl.h>
12#elif defined _WIN32
13#   define _USE_MATH_DEFINES /* for M_PI */
14#   define WIN32_LEAN_AND_MEAN
15#   include <windows.h>
16#endif
17
18#include <cmath>
19#include <cstdio>
20#include <cstdlib>
21#include <ctime>
22#include <string>
23
24#include "core.h"
25#include "lolgl.h"
26
27using namespace std;
28using namespace lol;
29
30#include "../neercs.h"
31#include "render.h"
32#include "text-render.h"
33
34extern char const *lolfx_blurh;
35extern char const *lolfx_blurv;
36extern char const *lolfx_remanency;
37extern char const *lolfx_glow;
38extern char const *lolfx_postfx;
39extern char const *lolfx_radial;
40extern char const *lolfx_simple;
41
42#define PID M_PI/180.0f    // pi ratio
43#define CR 1.0f/256.0f     // color ratio
44
45/*
46 * Various variables
47 */
48
49int active = true;         // window active flag
50float nearplane = 0.1f;    // nearplane
51float farplane = 1000.0f;  // farplane
52int polygon_fillmode = GL_FILL; // fill mode
53bool key_state = 0;        // key state
54/* window variable */
55ivec2 screen_size;         // screen size
56vec3 screen_color = CR * vec3(32, 32, 32); // screen color
57/* object variable */
58float main_angle = 0.0f;   // main angle
59float part_angle = 0.0f;   // part angle
60float fx_angle;            // current angle
61/* fs_quad variable */
62float fs_quad_vtx[] = {-1.0f, 1.0f, 0, 1.0f, -1.0f, -1.0f, 0, 1.0f, 1.0f, -1.0f, 0, 1.0f, 1.0f, 1.0f, 0, 1.0f};
63float fs_quad_tex[] = {0, 1.0f, 0, 0, 1.0f, 0, 1.0f, 1.0f};
64/* flash variable */
65bool flash_flag = false;   // flag
66float flash_angle = 0;     // angle
67float flash_value = 0;     // value
68float flash_speed = 1.5f;  // speed
69/* fade variable */
70bool fade_flag = false;    // flag
71float fade_angle = 0;      // angle
72float fade_value = 0;      // value
73float fade_speed = 0.2f;   // speed
74/* sync variable */
75bool sync_flag = false;    // flag
76float sync_angle = 0;      // angle
77float sync_value = 1.0f;   // value
78float sync_speed = 1.0f;   // speed
79/* beat variable */
80bool beat_flag = false;    // flag
81float beat_angle = 0;      // angle
82float beat_value = 0;      // value
83float beat_speed = 2.0f;   // speed
84/* window variable */
85ivec2 border;              // border width
86/* text variable */
87ivec2 ratio_2d(1,4);       // 2d ratio
88ivec2 map_size(256,256);   // texture map size
89ivec2 font_size(8,8);      // font size
90ivec2 canvas_char(0,0);    // canvas char number
91ivec2 canvas_size(0,0);    // caca size
92/* common variable */
93float value, angle, radius, scale, speed;
94/* shader variable */
95float remanency_source_mix = 0.25f;
96float remanency_buffer_mix = 0.75f;
97float remanency_new_frame_mix = 0.75f;
98float remanency_old_frame_mix = 0.25f;
99float blur_radius = 0.25f;      // glow radius
100float blur_radius_deform = 0.625f;// glow radius deform
101int glow_fbo_size = 2;          // glow fbo size
102float glow_smoothstep = 0.0f;   // glow smoothstep value (try 0.025f)
103float glow_mix_ratio1 = 0.375f; // glow mixing ratio
104float glow_mix_ratio2 = 0.625f; // source mixing ratio
105float glow_radius1 = 2.0f;      // large glow radius
106float glow_radius2 = 1.0f;      // small glow radius
107float glow_radius_deform1 = 3.0f;// large glow radius deform
108float glow_radius_deform2 = 1.5f;// small glow radius deform
109float postfx_deform = 0.625f;   // deformation ratio
110float postfx_noise = 0.125f;    // global noise
111float postfx_noise_h = 3.0f;    // horizontal noise
112float postfx_noise_v = 3.0f;    // vertical noise
113float postfx_aberration = 3.0f; // chromatic aberration
114bool postfx_scanline = true;    // scanline
115float postfx_scanline_h_base = 0.75f;
116float postfx_scanline_h_var = 0.25f;
117float postfx_scanline_h_repeat_x = 1.0f;
118float postfx_scanline_h_repeat_y = 1.0f;
119float postfx_scanline_v_base = 0.75f;
120float postfx_scanline_v_var = 0.5f;
121float postfx_scanline_v_repeat_x = 0.0f;
122float postfx_scanline_v_repeat_y = 1.0f;
123//float radial_value1 = 2.0f;
124//float radial_value2 = 0.8f;
125//float radial_color = 0;
126
127Shader *shader_simple;
128Shader *shader_blur_h, *shader_blur_v;
129Shader *shader_remanency, *shader_glow, *shader_radial, *shader_postfx;
130// shader variables
131ShaderUniform shader_simple_texture;
132ShaderUniform shader_blur_h_texture,
133              shader_blur_h_screen_size,
134              shader_blur_h_blur,
135              shader_blur_h_deform;
136ShaderUniform shader_blur_v_texture,
137              shader_blur_v_screen_size,
138              shader_blur_v_blur,
139              shader_blur_v_deform;
140ShaderUniform shader_remanency_texture,
141              shader_remanency_texture_buffer,
142              shader_remanency_screen_size,
143              shader_remanency_screen_color,
144              shader_remanency_value1,
145              shader_remanency_value2;
146ShaderUniform shader_glow_texture,
147              shader_glow_texture_prv,
148              shader_glow_screen_size,
149              shader_glow_time,
150              shader_glow_step,
151              shader_glow_value1,
152              shader_glow_value2;
153ShaderUniform shader_radial_texture,
154              shader_radial_screen_size,
155              shader_radial_time,
156              shader_radial_value1,
157              shader_radial_value2,
158              shader_radial_color;
159ShaderUniform shader_postfx_texture,
160              shader_postfx_texture_2d,
161              shader_postfx_screen_size,
162              shader_postfx_time,
163              shader_postfx_deform,
164              shader_postfx_noise,
165              shader_postfx_noise_h,
166              shader_postfx_noise_v,
167              shader_postfx_aberration,
168              shader_postfx_scanline,
169              shader_postfx_scanline_h_base,
170              shader_postfx_scanline_h_var,
171              shader_postfx_scanline_h_repeat_x,
172              shader_postfx_scanline_h_repeat_y,
173              shader_postfx_scanline_v_base,
174              shader_postfx_scanline_v_var,
175              shader_postfx_scanline_v_repeat_x,
176              shader_postfx_scanline_v_repeat_y,
177              shader_postfx_flash,
178              shader_postfx_sync;
179
180FrameBuffer *fbo_back, *fbo_front, *fbo_buffer;
181FrameBuffer *fbo_blur_h, *fbo_blur_v, *fbo_ping, *fbo_pong;
182
183TextRender *text_render;
184
185void fs_quad()
186{
187    glLoadIdentity();
188    glDrawArrays(GL_QUADS, 0, 4);
189}
190
191void draw_shader_simple(FrameBuffer *fbo_output, int n)
192{
193    shader_simple->Bind();
194    shader_simple->SetTexture(shader_simple_texture, fbo_output->GetTexture(), n);
195    fs_quad();
196    shader_simple->Unbind();
197}
198
199void rectangle(int x, int y, int w, int h)
200{
201    glLoadIdentity();
202    glBegin(GL_QUADS);
203        glVertex2i(x+w, y  );
204        glVertex2i(x  , y  );
205        glVertex2i(x  , y+h);
206        glVertex2i(x+w, y+h);
207    glEnd();
208}
209
210int Render::InitDraw(void)
211{
212    glDepthMask(GL_TRUE);     // do not write z-buffer
213    glEnable(GL_CULL_FACE);   // disable cull face
214    glCullFace(GL_BACK);      // don't draw front face
215
216    /* Initialise framebuffer objects */
217    fbo_back = new FrameBuffer(screen_size);
218    fbo_front = new FrameBuffer(screen_size);
219    fbo_buffer = new FrameBuffer(screen_size);
220    fbo_blur_h = new FrameBuffer(screen_size / glow_fbo_size);
221    fbo_blur_v = new FrameBuffer(screen_size / glow_fbo_size);
222    fbo_ping = new FrameBuffer(screen_size);
223    fbo_pong = new FrameBuffer(screen_size);
224    // shader simple
225    shader_simple = Shader::Create(lolfx_simple);
226    shader_simple_texture = shader_simple->GetUniformLocation("texture");
227    // shader blur horizontal
228    shader_blur_h = Shader::Create(lolfx_blurh);
229    shader_blur_h_texture = shader_blur_h->GetUniformLocation("texture");
230    shader_blur_h_screen_size = shader_blur_h->GetUniformLocation("screen_size");
231    shader_blur_h_blur = shader_blur_h->GetUniformLocation("blur");
232    shader_blur_h_deform = shader_blur_h->GetUniformLocation("deform");
233    // shader blur vertical
234    shader_blur_v = Shader::Create(lolfx_blurv);
235    shader_blur_v_texture = shader_blur_v->GetUniformLocation("texture");
236    shader_blur_v_screen_size = shader_blur_v->GetUniformLocation("screen_size");
237    shader_blur_v_blur = shader_blur_v->GetUniformLocation("blur");
238    shader_blur_v_deform = shader_blur_v->GetUniformLocation("deform");
239    // shader remanency
240    shader_remanency = Shader::Create(lolfx_remanency);
241    shader_remanency_texture = shader_remanency->GetUniformLocation("texture");
242    shader_remanency_texture_buffer = shader_remanency->GetUniformLocation("texture_buffer");
243    shader_remanency_screen_size = shader_remanency->GetUniformLocation("screen_size");
244    shader_remanency_screen_color = shader_remanency->GetUniformLocation("screen_color");
245    shader_remanency_value1 = shader_remanency->GetUniformLocation("value1");
246    shader_remanency_value2 = shader_remanency->GetUniformLocation("value2");
247    // shader glow
248    shader_glow = Shader::Create(lolfx_glow);
249    shader_glow_texture = shader_glow->GetUniformLocation("texture");
250    shader_glow_texture_prv = shader_glow->GetUniformLocation("texture_prv");
251    shader_glow_screen_size = shader_glow->GetUniformLocation("screen_size");
252    shader_glow_time = shader_glow->GetUniformLocation("time");
253    shader_glow_step = shader_glow->GetUniformLocation("step");
254    shader_glow_value1 = shader_glow->GetUniformLocation("value1");
255    shader_glow_value2 = shader_glow->GetUniformLocation("value2");
256    // shader radial
257    shader_radial = Shader::Create(lolfx_radial);
258    shader_radial_texture = shader_radial->GetUniformLocation("texture");
259    shader_radial_screen_size = shader_radial->GetUniformLocation("screen_size");
260    shader_radial_time = shader_radial->GetUniformLocation("time");
261    shader_radial_value1 = shader_radial->GetUniformLocation("value1");
262    shader_radial_value2 = shader_radial->GetUniformLocation("value2");
263    shader_radial_color = shader_radial->GetUniformLocation("color");
264    // shader postfx
265    shader_postfx = Shader::Create(lolfx_postfx);
266    shader_postfx_texture = shader_postfx->GetUniformLocation("texture");
267    shader_postfx_texture_2d = shader_postfx->GetUniformLocation("texture_2d");
268    shader_postfx_screen_size = shader_postfx->GetUniformLocation("screen_size");
269    shader_postfx_time = shader_postfx->GetUniformLocation("time");
270    shader_postfx_deform = shader_postfx->GetUniformLocation("deform");
271    shader_postfx_noise = shader_postfx->GetUniformLocation("noise");
272    shader_postfx_noise_h = shader_postfx->GetUniformLocation("noise_h");
273    shader_postfx_noise_v = shader_postfx->GetUniformLocation("noise_v");
274    shader_postfx_aberration = shader_postfx->GetUniformLocation("aberration");
275    shader_postfx_scanline = shader_postfx->GetUniformLocation("scanline");
276    shader_postfx_scanline_h_base = shader_postfx->GetUniformLocation("scanline_h_base");
277    shader_postfx_scanline_h_var = shader_postfx->GetUniformLocation("scanline_h_var");
278    shader_postfx_scanline_h_repeat_x = shader_postfx->GetUniformLocation("scanline_h_repeat_x");
279    shader_postfx_scanline_h_repeat_y = shader_postfx->GetUniformLocation("scanline_h_repeat_y");
280    shader_postfx_scanline_v_base = shader_postfx->GetUniformLocation("scanline_v_base");
281    shader_postfx_scanline_v_var = shader_postfx->GetUniformLocation("scanline_v_var");
282    shader_postfx_scanline_v_repeat_x = shader_postfx->GetUniformLocation("scanline_v_repeat_x");
283    shader_postfx_scanline_v_repeat_y = shader_postfx->GetUniformLocation("scanline_v_repeat_y");
284    shader_postfx_flash = shader_postfx->GetUniformLocation("flash");
285    shader_postfx_sync = shader_postfx->GetUniformLocation("sync");
286
287    return true;
288}
289
290int Render::CreateGLWindow()
291{
292    screen_size = Video::GetSize();
293    border = 18 * ratio_2d;
294    border.y = border.x; // enabled to get same border everywhere
295    canvas_char = (screen_size - border * 2) / (font_size * ratio_2d);
296    canvas_size = canvas_char * font_size * ratio_2d;
297
298    border = (screen_size - canvas_size) / 2;
299
300    caca_set_canvas_size(m_caca, canvas_char.x, canvas_char.y);
301
302    InitDraw();
303    return true;
304}
305
306Render::Render(caca_canvas_t *caca)
307  : m_caca(caca),
308    m_ready(false),
309    m_pause(false),
310    m_polygon(true),
311    m_shader(true),
312    m_shader_remanency(true),
313    m_shader_blur(true),
314    m_shader_glow(true),
315    m_shader_fx(true),
316    m_shader_postfx(true),
317    m_border(false)
318{
319    text_render = new TextRender(m_caca, font_size);
320}
321
322void Render::TickGame(float seconds)
323{
324    Entity::TickGame(seconds);
325}
326
327void Render::Pause()
328{
329    m_pause=!m_pause;
330}
331
332void Render::TickDraw(float seconds)
333{
334    /* keyboard manager */
335    if (Input::GetButtonState(27/*SDLK_ESCAPE*/))
336        Ticker::Shutdown();
337    //if (Input::GetButtonState(282/*SDLK_F1*/))
338    //    LEAULE();
339    if (Input::GetButtonState(283/*SDLK_F2*/))
340        {
341        m_polygon=!m_polygon;
342        polygon_fillmode=(m_polygon)?GL_FILL:GL_LINE;
343        glPolygonMode(GL_FRONT,polygon_fillmode);
344        }
345    if (Input::GetButtonState(284/*SDLK_F3*/)&&key_state!=284)
346        {
347        m_shader=!m_shader;
348        key_state=284;
349        }
350    if (Input::GetButtonState(285/*SDLK_F4*/))
351        m_shader_postfx=!m_shader_postfx;
352    if (Input::GetButtonState(286/*SDLK_F5*/))
353        Pause();
354
355    Entity::TickDraw(seconds);
356
357    if (!m_ready)
358    {
359        CreateGLWindow();
360        text_render->Init();
361        m_ready = true;
362    }
363
364    // timer
365    if (!m_pause)
366        main_angle += seconds * 100.0f * PID;
367    if (sync_flag)
368    {
369        angle=(main_angle-sync_angle)*sync_speed;
370        sync_value=1.0f-sinf(angle);
371        if (angle>90.0f*PID)
372        {
373            sync_value=0;
374            sync_flag=false;
375        }
376    }
377    if (beat_flag)
378    {
379        angle=(main_angle-beat_angle)*beat_speed;
380        beat_value=1.0f-sinf(angle);
381        if (angle>90.0f*PID)
382        {
383            beat_value=0;
384            beat_flag=false;
385        }
386    }
387    if (flash_flag)
388    {
389        angle=(main_angle-flash_angle)*flash_speed;
390        flash_value=1.0f-sinf(angle);
391        if (angle>90.0f*PID)
392        {
393            flash_value=0;
394            flash_flag=false;
395        }
396    }
397    if (fade_flag)
398    {
399        angle=(main_angle-fade_angle)*fade_speed;
400        fade_value=1.0f-sinf(angle);
401        if (angle>90.0f*PID)
402        {
403            fade_value=0;
404            fade_flag=false;
405        }
406    }
407
408    Draw2D();
409    Draw3D();
410}
411
412void Render::Draw2D()
413{
414    /* Draw text in an offline buffer */
415    text_render->Render();
416
417    if (m_shader)
418    {
419        fbo_back->Bind();
420    }
421
422    glViewport(0, 0, screen_size.x, screen_size.y);
423
424    /* Clear the back buffer */
425    glEnable(GL_BLEND);
426    glBlendFunc(GL_SRC_COLOR,GL_DST_ALPHA);
427    glClearColor(screen_color.r, screen_color.g, screen_color.b, 1.0f);
428    glClearDepth(1.0f); // set depth buffer
429    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
430
431    text_render->Blit(border, canvas_size);
432
433    //if (m_polygon) glEnable(GL_LINE_SMOOTH); else glDisable(GL_LINE_SMOOTH);
434    glLineWidth((m_polygon)?2.0f:1.0f);
435    fx_angle=main_angle-part_angle;
436    if (m_polygon)
437        glEnable(GL_TEXTURE_2D);
438
439    glMatrixMode(GL_PROJECTION);
440    mat4 m = mat4::ortho(0, screen_size.x, screen_size.y, 0, -1.f, 1.f);
441    glLoadMatrixf(&m[0][0]);
442    glMatrixMode(GL_MODELVIEW);
443    // draw border
444    if (m_border)
445    {
446        glDisable(GL_TEXTURE_2D);
447        glDisable(GL_BLEND);
448        glColor3f(1.0f, 1.0f, 1.0f);
449        rectangle(border.x - ratio_2d.x, border.y - ratio_2d.y, canvas_size.x + ratio_2d.x * 2, ratio_2d.y);
450        rectangle(border.x - ratio_2d.x, border.y, ratio_2d.x, canvas_size.y);
451        rectangle(border.x + canvas_size.x, border.y, ratio_2d.x, canvas_size.y);
452        rectangle(border.x - ratio_2d.x, border.y + canvas_size.y, canvas_size.x + ratio_2d.x * 2, ratio_2d.y);
453        glEnable(GL_BLEND);
454    }
455}
456
457void Render::Draw3D()
458{
459    if (!m_shader)
460        return;
461
462    glDisable(GL_DEPTH_TEST);
463    glDisable(GL_BLEND);
464
465    glEnableClientState(GL_VERTEX_ARRAY);
466    glVertexPointer(4, GL_FLOAT, 0, fs_quad_vtx);
467
468    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
469    glTexCoordPointer(2, GL_FLOAT, 0, fs_quad_tex);
470
471    if (m_shader_remanency)
472    {
473        // shader remanency
474        fbo_ping->Bind();
475        shader_remanency->Bind();
476        shader_remanency->SetTexture(shader_remanency_texture, fbo_back->GetTexture(), 0);
477        shader_remanency->SetTexture(shader_remanency_texture_buffer, fbo_buffer->GetTexture(), 1);
478        shader_remanency->SetUniform(shader_remanency_screen_size, vec2(1.0f));
479        shader_remanency->SetUniform(shader_remanency_screen_color, screen_color);
480        shader_remanency->SetUniform(shader_remanency_value1, remanency_source_mix);
481        shader_remanency->SetUniform(shader_remanency_value2, remanency_buffer_mix);
482        fs_quad();
483        shader_remanency->Unbind();
484        fbo_ping->Unbind();
485        // shader simple
486        fbo_back->Bind();
487        draw_shader_simple(fbo_ping, 0);
488        fbo_back->Unbind();
489        // save previous fbo
490        fbo_ping->Bind();
491        shader_remanency->Bind();
492        shader_remanency->SetTexture(shader_remanency_texture, fbo_front->GetTexture(), 0);
493        shader_remanency->SetTexture(shader_remanency_texture_buffer, fbo_buffer->GetTexture(), 1);
494        shader_remanency->SetUniform(shader_remanency_screen_size, vec2(1.0f));
495        shader_remanency->SetUniform(shader_remanency_screen_color, screen_color);
496        shader_remanency->SetUniform(shader_remanency_value1, remanency_new_frame_mix);
497        shader_remanency->SetUniform(shader_remanency_value2, remanency_old_frame_mix);
498        fs_quad();
499        shader_remanency->Unbind();
500        fbo_ping->Unbind();
501        // shader simple
502        fbo_buffer->Bind();
503        draw_shader_simple(fbo_ping, 0);
504        fbo_buffer->Unbind();
505    }
506
507    if (m_shader_fx && m_shader_blur)
508    {
509        // shader blur horizontal
510        fbo_ping->Bind();
511        shader_blur_h->Bind();
512        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_back->GetTexture(), 0);
513        shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f));
514        shader_blur_h->SetUniform(shader_blur_h_blur, blur_radius / screen_size.x);
515        shader_blur_h->SetUniform(shader_blur_h_deform, blur_radius_deform / screen_size.x);
516        fs_quad();
517        shader_blur_h->Unbind();
518        fbo_ping->Unbind();
519        // shader blur vertical
520        fbo_front->Bind();
521        shader_blur_v->Bind();
522        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_ping->GetTexture(), 0);
523        shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f));
524        shader_blur_v->SetUniform(shader_blur_v_blur, blur_radius / screen_size.y);
525        shader_blur_v->SetUniform(shader_blur_v_deform, blur_radius_deform / screen_size.y);
526        fs_quad();
527        shader_blur_v->Unbind();
528    }
529    else
530    {
531        // shader simple
532        fbo_front->Bind();
533        draw_shader_simple(fbo_back, 0);
534    }
535    fbo_front->Unbind();
536    // shader glow
537    if (m_shader_fx && m_shader_glow)
538    {
539        // shader blur horizontal
540        fbo_blur_h->Bind();
541        shader_blur_h->Bind();
542        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_ping->GetTexture(), 0);
543        shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f / glow_fbo_size));
544        shader_blur_h->SetUniform(shader_blur_h_blur, glow_radius1 / screen_size.x);
545        shader_blur_h->SetUniform(shader_blur_h_deform, glow_radius_deform1 / screen_size.x);
546        fs_quad();
547        shader_blur_h->Unbind();
548        fbo_blur_h->Unbind();
549        // shader blur vertical
550        fbo_blur_v->Bind();
551        shader_blur_v->Bind();
552        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
553        shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f / glow_fbo_size));
554        shader_blur_v->SetUniform(shader_blur_v_blur, glow_radius1 / screen_size.y);
555        shader_blur_v->SetUniform(shader_blur_v_deform, glow_radius_deform1 / screen_size.y);
556        fs_quad();
557        shader_blur_v->Unbind();
558        fbo_blur_v->Unbind();
559        // shader blur horizontal
560        fbo_blur_h->Bind();
561        shader_blur_h->Bind();
562        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0);
563        shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f / glow_fbo_size));
564        shader_blur_h->SetUniform(shader_blur_h_blur, glow_radius2 / screen_size.x);
565        shader_blur_h->SetUniform(shader_blur_h_deform, glow_radius_deform2 / screen_size.x);
566        fs_quad();
567        shader_blur_h->Unbind();
568        fbo_blur_h->Unbind();
569        // shader blur vertical
570        fbo_blur_v->Bind();
571        shader_blur_v->Bind();
572        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
573        shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f / glow_fbo_size));
574        shader_blur_v->SetUniform(shader_blur_v_blur, glow_radius2 / screen_size.y);
575        shader_blur_h->SetUniform(shader_blur_v_deform, glow_radius_deform2 / screen_size.y);
576        fs_quad();
577        shader_blur_v->Unbind();
578        fbo_blur_v->Unbind();
579        // shader glow
580        fbo_pong->Bind();
581        shader_glow->Bind();
582        shader_glow->SetTexture(shader_glow_texture, fbo_blur_v->GetTexture(), 0);
583        shader_glow->SetTexture(shader_glow_texture_prv, fbo_front->GetTexture(), 1);
584        shader_glow->SetUniform(shader_glow_screen_size, vec2(1.0f));
585        shader_glow->SetUniform(shader_glow_time, fx_angle);
586        shader_glow->SetUniform(shader_glow_step, glow_smoothstep);
587        shader_glow->SetUniform(shader_glow_value1, glow_mix_ratio1);
588        shader_glow->SetUniform(shader_glow_value2, glow_mix_ratio2);
589        fs_quad();
590        shader_glow->Unbind();
591    }
592    if (!m_shader_fx)
593    {
594        // shader simple
595        fbo_pong->Bind();
596        draw_shader_simple(fbo_front, 0);
597    }
598    fbo_pong->Unbind();
599    if (m_shader_postfx)
600    {
601        // shader postfx
602        shader_postfx->Bind();
603        shader_postfx->SetTexture(shader_postfx_texture, fbo_pong->GetTexture(), 0);
604        shader_postfx->SetUniform(shader_postfx_screen_size, (vec2)screen_size);
605        shader_postfx->SetUniform(shader_postfx_time, fx_angle);
606        shader_postfx->SetUniform(shader_postfx_deform, postfx_deform);
607        shader_postfx->SetUniform(shader_postfx_noise, postfx_noise);
608        shader_postfx->SetUniform(shader_postfx_noise_h, postfx_noise_h);
609        shader_postfx->SetUniform(shader_postfx_noise_v, postfx_noise_v);
610        shader_postfx->SetUniform(shader_postfx_aberration, postfx_aberration);
611        shader_postfx->SetUniform(shader_postfx_scanline, postfx_scanline);
612        shader_postfx->SetUniform(shader_postfx_scanline_h_base, postfx_scanline_h_base);
613        shader_postfx->SetUniform(shader_postfx_scanline_h_var, postfx_scanline_h_var);
614        shader_postfx->SetUniform(shader_postfx_scanline_h_repeat_x, postfx_scanline_h_repeat_x);
615        shader_postfx->SetUniform(shader_postfx_scanline_h_repeat_y, postfx_scanline_h_repeat_y);
616        shader_postfx->SetUniform(shader_postfx_scanline_v_base, postfx_scanline_v_base);
617        shader_postfx->SetUniform(shader_postfx_scanline_v_var, postfx_scanline_v_var);
618        shader_postfx->SetUniform(shader_postfx_scanline_v_repeat_x, postfx_scanline_v_repeat_x);
619        shader_postfx->SetUniform(shader_postfx_scanline_v_repeat_y, postfx_scanline_v_repeat_y);
620        shader_postfx->SetUniform(shader_postfx_flash, flash_value);
621        shader_postfx->SetUniform(shader_postfx_sync, (float)fabs(beat_value*cosf((main_angle-beat_angle)*8.0f)));
622        fs_quad();
623        shader_postfx->Unbind();
624    }
625    else
626    {
627        // shader simple
628        draw_shader_simple(fbo_pong, 0);
629    }
630
631    glDisableClientState(GL_VERTEX_ARRAY);
632    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
633}
634
635Render::~Render()
636{
637}
Note: See TracBrowser for help on using the repository browser.