Bladeren bron

moved noise/offset/retrace into a new shader

master
rez Sam Hocevar <sam@hocevar.net> 12 jaren geleden
bovenliggende
commit
fcad48e2ce
8 gewijzigde bestanden met toevoegingen van 149 en 90 verwijderingen
  1. +2
    -2
      neercs/Makefile.am
  2. +4
    -3
      neercs/neercs.vcxproj
  3. +8
    -5
      neercs/neercs.vcxproj.filters
  4. +38
    -0
      neercs/video/noise.lolfx
  5. +4
    -19
      neercs/video/postfx.lolfx
  6. +84
    -53
      neercs/video/render.cpp
  7. +2
    -0
      neercs/video/render.h
  8. +7
    -8
      neercs/video/simple.lolfx

+ 2
- 2
neercs/Makefile.am Bestand weergeven

@@ -11,8 +11,8 @@ neercs_SOURCES = \
video/render.cpp video/render.h \
video/text-render.cpp video/text-render.h \
video/simple.lolfx \
video/blurh.lolfx video/blurv.lolfx \
video/remanency.lolfx video/glow.lolfx video/postfx.lolfx video/radial.lolfx \
video/blurh.lolfx video/blurv.lolfx video/glow.lolfx video/radial.lolfx \
video/remanency.lolfx video/noise.lolfx video/postfx.lolfx\
video/text.lolfx
neercs_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ @CACA_CFLAGS@ -Iold
neercs_LDADD =


+ 4
- 3
neercs/neercs.vcxproj Bestand weergeven

@@ -78,14 +78,15 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<LolFxCompile Include="video\simple.lolfx" />
<LolFxCompile Include="video\text.lolfx" />
<LolFxCompile Include="video\blurh.lolfx" />
<LolFxCompile Include="video\blurv.lolfx" />
<LolFxCompile Include="video\glow.lolfx" />
<LolFxCompile Include="video\postfx.lolfx" />
<LolFxCompile Include="video\radial.lolfx" />
<LolFxCompile Include="video\remanency.lolfx" />
<LolFxCompile Include="video\simple.lolfx" />
<LolFxCompile Include="video\text.lolfx" />
<LolFxCompile Include="video\noise.lolfx" />
<LolFxCompile Include="video\postfx.lolfx" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{587FCCE9-1D8D-4398-B8B6-E8F4E9A92233}</ProjectGuid>


+ 8
- 5
neercs/neercs.vcxproj.filters Bestand weergeven

@@ -114,6 +114,12 @@
</Filter>
</ItemGroup>
<ItemGroup>
<LolFxCompile Include="video\simple.lolfx">
<Filter>video</Filter>
</LolFxCompile>
<LolFxCompile Include="video\text.lolfx">
<Filter>video</Filter>
</LolFxCompile>
<LolFxCompile Include="video\blurh.lolfx">
<Filter>video</Filter>
</LolFxCompile>
@@ -123,19 +129,16 @@
<LolFxCompile Include="video\glow.lolfx">
<Filter>video</Filter>
</LolFxCompile>
<LolFxCompile Include="video\postfx.lolfx">
<Filter>video</Filter>
</LolFxCompile>
<LolFxCompile Include="video\radial.lolfx">
<Filter>video</Filter>
</LolFxCompile>
<LolFxCompile Include="video\remanency.lolfx">
<Filter>video</Filter>
</LolFxCompile>
<LolFxCompile Include="video\simple.lolfx">
<LolFxCompile Include="video\noise.lolfx">
<Filter>video</Filter>
</LolFxCompile>
<LolFxCompile Include="video\text.lolfx">
<LolFxCompile Include="video\postfx.lolfx">
<Filter>video</Filter>
</LolFxCompile>
</ItemGroup>


+ 38
- 0
neercs/video/noise.lolfx Bestand weergeven

@@ -0,0 +1,38 @@
-- GLSL.Vert --

#version 120

void main()
{
gl_Position=gl_Vertex;
gl_TexCoord[0]=gl_MultiTexCoord0;
}

-- GLSL.Frag --

#version 120

uniform sampler2D texture;
uniform vec2 screen_size;
uniform float time;
uniform vec2 offset;
uniform float noise;
uniform vec3 retrace;

float rand(in vec2 p)
{
return fract(sin(dot(p,vec2(12.9898,78.233)))*43758.5453);
}

void main(void)
{
vec2 p=gl_FragCoord.xy/screen_size.xy;

float rnd=rand(p+time);
vec2 o=(offset-offset*2.0*rnd)/screen_size;

vec3 c=texture2D(texture,p+o).xyz; // offset
c-=rnd*noise; // noise
c-=retrace.x*mod(p.y*retrace.y+time*retrace.z,1.0); // retrace
gl_FragColor=vec4(c,1.0);
}

+ 4
- 19
neercs/video/postfx.lolfx Bestand weergeven

@@ -20,9 +20,6 @@ uniform vec4 ghost1;
uniform vec4 ghost2;
uniform vec3 filter;
uniform vec3 color;
uniform vec3 retrace;
uniform vec2 offset;
uniform float noise;
uniform float aberration;
uniform vec4 moire_h;
uniform vec4 moire_v;
@@ -33,8 +30,6 @@ uniform float vignetting;
uniform float flash;
uniform float sync;

const float PI=3.14159265358979323846;

vec2 screen(in vec2 p,in float radius)
{
float d=deform.x+sync*0.0625;
@@ -46,11 +41,6 @@ vec3 get_color(in sampler2D tex,in vec2 p)
return texture2D(tex,clamp(p,-1.0,0.0)).xyz;
}

float rand(in vec2 p)
{
return fract(sin(dot(p,vec2(12.9898,78.233)))*43758.5453);
}

float letterbox(in vec2 p,in float radius,in float smooth)
{
return 1.0-smoothstep(smooth,1.0,length(max(abs(p*2.0+1.0)-vec2(radius),0.0))+radius);
@@ -66,19 +56,16 @@ void main(void)
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 rnd=vec2(rand(vec2(p.x+time,p.y-time)),rand(vec2(p.x-time,p.y+time)));

vec2 o=(offset-offset*2.0*rnd.x)/screen_size; // offset
vec3 source=get_color(texture,z+o); // offset added to source
vec3 source=get_color(texture,z);
vec3 g1=get_color(texture,z1-ghost1.xy);
vec3 g2=get_color(texture,z2-ghost2.xy);

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

vec3 ca;
ca.x=get_color(texture,vec2(z.x+o.x-v,z.y+o.y)).x;
ca.y=get_color(texture,vec2(z.x+o.x ,z.y+o.y)).y;
ca.z=get_color(texture,vec2(z.x+o.x+v,z.y+o.y)).z;
ca.x=get_color(texture,vec2(z.x-v,z.y)).x;
ca.y=get_color(texture,vec2(z.x ,z.y)).y;
ca.z=get_color(texture,vec2(z.x+v,z.y)).z;

vec3 c=source+g1*g1*ghost1.w+g2*g2*ghost2.w; // mix

@@ -91,8 +78,6 @@ void main(void)

c+=flash; // flash
c+=ca; // chromatic aberration
c-=retrace.x*mod(z.y*retrace.y+time*retrace.z,1.0); // retrace
c-=(vec3(rnd.x-rnd.y))*noise; // noise
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


+ 84
- 53
neercs/video/render.cpp Bestand weergeven

@@ -31,13 +31,14 @@ using namespace lol;
#include "render.h"
#include "text-render.h"

extern char const *lolfx_simple;
extern char const *lolfx_remanency;
extern char const *lolfx_blurh;
extern char const *lolfx_blurv;
extern char const *lolfx_remanency;
extern char const *lolfx_glow;
extern char const *lolfx_postfx;
extern char const *lolfx_radial;
extern char const *lolfx_simple;
extern char const *lolfx_noise;
extern char const *lolfx_postfx;

#define PID M_PI/180.0f // pi ratio
#define CR 1.0f/256.0f // color ratio
@@ -91,17 +92,17 @@ vec2 glow_mix(0.6f,0.4f); // glow mix [source mix,glow mix]
vec2 glow_large(2.0f,2.0f); // large glow radius [center,corner]
vec2 glow_small(1.0f,1.0f); // small glow radius [center,corner]
vec2 blur(0.25f,0.5f); // glow radius [center,corner]
vec2 postfx_deform(0.7f,0.54f); // deformation [ratio,zoom]
vec2 noise_offset(3.0f,3.0f); // random line [horizontal,vertical]
float noise_noise = 0.15f; // noise
vec3 noise_retrace(0.05f,2.0f,4.0f); // retrace [strength,length,speed]
vec2 postfx_deform(0.7f,0.54f); // deformation [ratio,zoom]
vec3 postfx_filter(0.8f,0.9f,0.4f); // color filter [red,green,blue]
vec3 postfx_color(1.8f,1.5f,0.5f); // color modifier [brightness,contrast,grayscale]
vec2 postfx_corner(0.75f,0.95f); // corner [radius,blur]
float postfx_vignetting = -0.5f; // vignetting strength
vec3 postfx_retrace(0.05f,2.0f,4.0f); // retrace [strength,length,speed]
vec2 postfx_offset(3.0f,3.0f); // random line [horizontal,vertical]
float postfx_noise = 0.15f; // noise
float postfx_aberration = 4.0f; // chromatic aberration
vec4 postfx_ghost1(0.01f,0.0f,0.1f,-0.4f); // ghost picture 1 [position x,position y,position z,strength]
vec4 postfx_ghost2(0.02f,0.0f,0.1f,0.4f); // ghost picture 2 [position x,position y,position z,strength]
float postfx_aberration = 4.0f; // chromatic aberration
vec4 postfx_moire_h(0.75f,-0.25f,0.0f,1.0f); // vertical moire [base,variable,repeat x,repeat y]
vec4 postfx_moire_v(0.75f,-0.25f,1.0f,1.5f); // horizontal moire [base,variable,repeat x,repeat y]
vec4 postfx_scanline_h(0.75f, 0.25f,0.0f,2.0f); // vertical scanline [base,variable,repeat x,repeat y]
@@ -179,17 +180,17 @@ char const *setup_text[] = {
"brightness",
"contrast",
"grayscale",
"",
"aberration",
"",
"noise",
"offset h",
"offset v",
"noise",
"aberration",
"retrace strength",
"retrace length",
"retrace speed",
"",
"",
"ghost",
"back x",
"back y",
@@ -271,16 +272,16 @@ vec4 setup_var[]={ // setup variable [start,end,step,value]
vec4(0.0f, 4.0f, 0.1f, postfx_color.x),
vec4(0.0f, 4.0f, 0.1f, postfx_color.y),
vec4(0.0f, 1.5f, 0.1f, postfx_color.z),
vec4(0),
vec4(0.0f, 8.0f, 0.5f, postfx_aberration),
vec4(0),
vec4(0), /* noise */
vec4(0.0f, 4.0f, 0.50f, postfx_offset.x),
vec4(0.0f, 4.0f, 0.50f, postfx_offset.y),
vec4(0.0f, 1.0f, 0.05f, postfx_noise),
vec4(0.0f, 8.0f, 0.50f, postfx_aberration),
vec4(0.0f, 0.2f, 0.01f, postfx_retrace.x),
vec4(0.0f, 8.0f, 0.50f, postfx_retrace.y),
vec4(0.0f, 4.0f, 0.25f, postfx_retrace.z),
vec4(0.0f, 4.0f, 0.50f, noise_offset.x),
vec4(0.0f, 4.0f, 0.50f, noise_offset.y),
vec4(0.0f, 1.0f, 0.05f, noise_noise),
vec4(0.0f, 0.2f, 0.01f, noise_retrace.x),
vec4(0.0f, 8.0f, 0.50f, noise_retrace.y),
vec4(0.0f, 4.0f, 0.25f, noise_retrace.z),
vec4(0),
vec4(0),
vec4(0), /* ghost */
vec4(-0.5f, 0.5f, 0.01f, postfx_ghost1.x),
@@ -335,12 +336,12 @@ void Render::UpdateVar()
k += 3; /* color */
postfx_filter = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
postfx_color = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
k += 3; /* noise */
postfx_offset = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
postfx_noise = setup_var[k].w; k++;
postfx_aberration = setup_var[k].w; k++;
postfx_retrace = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
k += 2; /* ghost */
k += 2; /* noise */
noise_offset = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
noise_noise = setup_var[k].w; k++;
noise_retrace = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
k += 3; /* ghost */
postfx_ghost1 = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
postfx_ghost2 = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
k += 1; /* moire */
@@ -364,26 +365,33 @@ int calc_item_length()
}

Shader *shader_simple;
Shader *shader_blur_h, *shader_blur_v;
Shader *shader_remanency, *shader_glow, *shader_radial, *shader_postfx;
Shader *shader_remanency;
Shader *shader_blur_h, *shader_blur_v, *shader_glow, *shader_radial;
Shader *shader_noise, *shader_postfx;
// shader variables
ShaderUniform shader_simple_texture;
ShaderUniform shader_remanency_source,
shader_remanency_buffer,
shader_remanency_mix;
ShaderUniform shader_glow_glow,
shader_glow_source,
shader_glow_mix;
ShaderUniform shader_blur_h_texture,
shader_blur_h_radius,
shader_blur_v_texture,
shader_blur_v_radius;
ShaderUniform shader_glow_glow,
shader_glow_source,
shader_glow_mix;
ShaderUniform shader_radial_texture,
shader_radial_screen_size,
shader_radial_time,
shader_radial_value1,
shader_radial_value2,
shader_radial_color;
ShaderUniform shader_noise_texture,
shader_noise_screen_size,
shader_noise_time,
shader_noise_offset,
shader_noise_noise,
shader_noise_retrace;
ShaderUniform shader_postfx_texture,
shader_postfx_texture_2d,
shader_postfx_screen_size,
@@ -395,9 +403,6 @@ ShaderUniform shader_postfx_texture,
shader_postfx_color,
shader_postfx_corner,
shader_postfx_vignetting,
shader_postfx_retrace,
shader_postfx_offset,
shader_postfx_noise,
shader_postfx_aberration,
shader_postfx_moire_h,
shader_postfx_moire_v,
@@ -479,6 +484,14 @@ int Render::InitDraw(void)
shader_radial_value1 = shader_radial->GetUniformLocation("value1");
shader_radial_value2 = shader_radial->GetUniformLocation("value2");
shader_radial_color = shader_radial->GetUniformLocation("color");
// shader noise
shader_noise = Shader::Create(lolfx_noise);
shader_noise_texture = shader_noise->GetUniformLocation("texture");
shader_noise_screen_size = shader_noise->GetUniformLocation("screen_size");
shader_noise_time = shader_noise->GetUniformLocation("time");
shader_noise_offset = shader_noise->GetUniformLocation("offset");
shader_noise_noise = shader_noise->GetUniformLocation("noise");
shader_noise_retrace = shader_noise->GetUniformLocation("retrace");
// shader postfx
shader_postfx = Shader::Create(lolfx_postfx);
shader_postfx_texture = shader_postfx->GetUniformLocation("texture");
@@ -492,10 +505,7 @@ int Render::InitDraw(void)
shader_postfx_color = shader_postfx->GetUniformLocation("color");
shader_postfx_corner = shader_postfx->GetUniformLocation("corner");
shader_postfx_vignetting = shader_postfx->GetUniformLocation("vignetting");
shader_postfx_retrace = shader_postfx->GetUniformLocation("retrace");
shader_postfx_offset = shader_postfx->GetUniformLocation("offset");
shader_postfx_noise = shader_postfx->GetUniformLocation("noise");
shader_postfx_aberration = shader_postfx->GetUniformLocation("aberration");
shader_postfx_aberration = shader_noise->GetUniformLocation("aberration");
shader_postfx_moire_h = shader_postfx->GetUniformLocation("moire_h");
shader_postfx_moire_v = shader_postfx->GetUniformLocation("moire_v");
shader_postfx_scanline_h = shader_postfx->GetUniformLocation("scanline_h");
@@ -537,6 +547,7 @@ Render::Render(caca_canvas_t *caca)
m_shader_remanency(true),
m_shader_glow(true),
m_shader_blur(true),
m_shader_noise(true),
m_shader_postfx(true)
{
text_render = new TextRender(m_caca, font_size);
@@ -571,19 +582,6 @@ void Render::TickDraw(float seconds)
polygon_fillmode = (m_polygon)?GL_FILL:GL_LINE;
glPolygonMode(GL_FRONT, polygon_fillmode);
}
if (Input::WasPressed(Key::F3))
{
m_shader_glow = !m_shader_glow;
m_shader_blur = !m_shader_blur;
}
if (Input::WasPressed(Key::F4))
{
m_shader_postfx = !m_shader_postfx;
}
if (Input::WasPressed(Key::F5))
{
Pause();
}
if (Input::WasPressed(Key::Tab))
{
if (m_setup)
@@ -673,10 +671,26 @@ void Render::TickDraw(float seconds)
Render::UpdateVar();
}
}
if (Input::WasPressed(Key::Home))
{
if (m_setup && setup_switch)
{
setup_var[setup_item_key].w = setup_var[setup_item_key].x;
Render::UpdateVar();
}
}
if (Input::WasPressed(Key::End))
{
if (m_setup && setup_switch)
{
setup_var[setup_item_key].w = setup_var[setup_item_key].y;
Render::UpdateVar();
}
}
if (Input::WasPressed(Key::Return))
{
sync_flag = true;
sync_angle = main_angle;
fade_flag = true;
fade_angle = main_angle;
}

Entity::TickDraw(seconds);
@@ -957,6 +971,26 @@ void Render::Draw3D()
fbo_front->Unbind();
}

if (m_shader_noise)
{
// shader noise
fbo_ping->Bind();
shader_noise->Bind();
shader_noise->SetUniform(shader_noise_texture, fbo_front->GetTexture(), 0);
shader_noise->SetUniform(shader_noise_screen_size, (vec2)screen_size);
shader_noise->SetUniform(shader_noise_time, fx_angle);
shader_noise->SetUniform(shader_noise_offset, noise_offset);
shader_noise->SetUniform(shader_noise_noise, noise_noise);
shader_noise->SetUniform(shader_noise_retrace, noise_retrace);
fs_quad();
shader_noise->Unbind();
fbo_ping->Unbind();
// shader simple
fbo_front->Bind();
draw_shader_simple(fbo_ping, 0);
fbo_front->Unbind();
}

if (m_shader_postfx)
{
// shader postfx
@@ -971,9 +1005,6 @@ void Render::Draw3D()
shader_postfx->SetUniform(shader_postfx_color, postfx_color);
shader_postfx->SetUniform(shader_postfx_corner, postfx_corner);
shader_postfx->SetUniform(shader_postfx_vignetting, postfx_vignetting);
shader_postfx->SetUniform(shader_postfx_retrace, postfx_retrace);
shader_postfx->SetUniform(shader_postfx_offset, postfx_offset);
shader_postfx->SetUniform(shader_postfx_noise, postfx_noise);
shader_postfx->SetUniform(shader_postfx_aberration, postfx_aberration);
shader_postfx->SetUniform(shader_postfx_moire_h, postfx_moire_h);
shader_postfx->SetUniform(shader_postfx_moire_v, postfx_moire_v);


+ 2
- 0
neercs/video/render.h Bestand weergeven

@@ -36,6 +36,8 @@ private:
bool m_shader_remanency;
bool m_shader_blur;
bool m_shader_glow;
bool m_shader_radial;
bool m_shader_noise;
bool m_shader_postfx;
};



+ 7
- 8
neercs/video/simple.lolfx Bestand weergeven

@@ -3,10 +3,10 @@
#version 120

void main()
{
gl_Position = gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
{
gl_Position = gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
}

-- GLSL.Frag --

@@ -15,7 +15,6 @@ void main()
uniform sampler2D texture;

void main(void)
{
gl_FragColor = texture2D(texture, gl_TexCoord[0].xy);
}

{
gl_FragColor = texture2D(texture, gl_TexCoord[0].xy);
}

Laden…
Annuleren
Opslaan