diff --git a/assets/shaders/basic_vs.vert b/assets/shaders/basic_vs.vert index d834ce2..c4cfdc3 100644 --- a/assets/shaders/basic_vs.vert +++ b/assets/shaders/basic_vs.vert @@ -1,14 +1,20 @@ -// Basic Vertex Shader -#version 140 - +// Basic Vertex Shader Template with Model, View, Project matrixes +#version 140 + in vec3 in_Position; in vec3 in_Color; +in vec2 in_UV; + +uniform mat4 in_Model; +uniform mat4 in_View; +uniform mat4 in_Proj; + out vec3 ex_Color; - -void main(void) { - gl_Position.xyz = in_Position.xyz; - gl_Position.w = 1.0; +out vec2 ex_UV; - ex_Color = vec3(1.0, 0.0, 0.0); +void main(void) { + gl_Position = in_Proj * (in_View * (in_Model * vec4(in_Position, 1.0))); + ex_Color = vec3(in_Color); + ex_UV = in_UV; } diff --git a/assets/shaders/retro_texture.frag b/assets/shaders/retro_texture.frag index 44ea4a2..7d58eb8 100644 --- a/assets/shaders/retro_texture.frag +++ b/assets/shaders/retro_texture.frag @@ -18,13 +18,13 @@ out vec4 out_Color; // width of a pixel in texture units, // should be set to 1 / width, 1 / height. uniform vec2 pixelSize = vec2(1.0/(320.0), 1.0/(240.0) ); - + // how sharp the bilinear filter is, 0 - 1 const float sharpness = 0.75; // How many are misalign the color beams const float misalign = 0.4; - + // how much a scanline should darken its line, 0-1 const float scanIntensity = 0.1; @@ -36,7 +36,7 @@ const float distortion = 0.08; // Flicker intesity //const float flicker = 0.025; - + // Time depedent FX uniform float time = 0.0; @@ -51,13 +51,13 @@ uniform float brightness = 0.0; vec2 barrelDistortion(vec2 coord) { vec2 cc = coord - 0.5; float dist = dot(cc, cc) * distortion; - return coord + cc * (1.0 - dist) * dist; + return coord + cc * (1.0 - dist) * dist; } void main(void) { // Apply curvature fx vec2 uv = barrelDistortion(ex_UV); - if ( (uv.x <0 || uv.x > 1.0) || (uv.y <0 || uv.y > 1.0)) { + if ( (uv.x <0.0 || uv.x > 1.0) || (uv.y <0.0 || uv.y > 1.0)) { // Ignore fragments that are outside of the screen discard; return; @@ -65,7 +65,7 @@ void main(void) { // Precalculate misalign in function of horizontal pos float mis = misalign * pixelSize.x * (misalign + (1.0 - misalign)*2 * abs(uv.x - 0.5)); - + // Precalculate bilinear filter things float xInc = pixelSize.x * (1.0 - sharpness) / 2.0; float yInc = pixelSize.y * (1.0 - sharpness) / 2.0; @@ -75,17 +75,17 @@ void main(void) { uvs[1] = uv + vec2(xInc, -yInc); uvs[2] = uv + vec2(-xInc, yInc); uvs[3] = uv + vec2(xInc, yInc); - + for (int i=0; i < 4; i++) { middle[i] = texture(texture0, uvs[i] ).rgb; - + // Generate color border (misaligment) vec3 col; col.r = texture(texture0,vec2(uvs[i].x + mis ,uvs[i].y)).x; col.g = texture(texture0,vec2(uvs[i].x ,uvs[i].y)).y; col.b = texture(texture0,vec2(uvs[i].x - mis ,uvs[i].y)).z; middle[i] = middle[i]*0.2 + col*0.8; - + // scanlines if (scanIntensity > 0.0 && mod(uvs[i].y, pixelSize.y ) > (pixelSize.y/2)) { middle[i].r = max(middle[i].r - scanIntensity, 0); @@ -100,14 +100,14 @@ void main(void) { // noise result = result + noise * fract(sin(dot(uv.xy , vec2(12.9898 + time, 78.233 + tan(time)))) * 43758.5453); - + // contrast curve //result.xyz = clamp(0.5*result.xyz + 0.5*result.xyz * 1.2*result.xyz, 0.0 , 1.0); - + //flickering (semi-randomized) // result *= 1.0 - flicker * fract(sin(dot(vec2(1.0) , vec2(12.9898 + time, 78.233 + tan(time)))) * 43758.5453); - + out_Color.xyz = result * (1.0 + brightness); out_Color.w = 1.0; - + } diff --git a/tools/include/gl_engine.hpp b/tools/include/gl_engine.hpp index cf0e658..da61d18 100644 --- a/tools/include/gl_engine.hpp +++ b/tools/include/gl_engine.hpp @@ -32,7 +32,7 @@ class GlEngine { frame_count = 0; t_acu = 0; - vertShaderFile = "mvp_template.vert"; + vertShaderFile = "basic_vs.vert"; fragShaderFile = "retro_texture.frag"; this->pbo = 0; } diff --git a/tools/src/gl_engine.cpp b/tools/src/gl_engine.cpp index 042a64b..9e4fddb 100644 --- a/tools/src/gl_engine.cpp +++ b/tools/src/gl_engine.cpp @@ -23,7 +23,7 @@ // Constants const unsigned int GlEngine::sh_in_Position = 0; const unsigned int GlEngine::sh_in_Color = 1; -const unsigned int GlEngine::sh_in_UV = 3; +const unsigned int GlEngine::sh_in_UV = 2; const GLsizei GlEngine::N_VERTICES = 4; @@ -118,7 +118,7 @@ int GlEngine::initGL(OS::OS& os) { check_gl_error(); // Upload UV - glBindBuffer(GL_ARRAY_BUFFER, vbo[sh_in_UV-1]); + glBindBuffer(GL_ARRAY_BUFFER, vbo[sh_in_UV]); glBufferData(GL_ARRAY_BUFFER, sizeof(uv_data), uv_data, GL_STATIC_DRAW); // Vertex data to attribute index 0 (shadderAttribute) and is 3 floats glVertexAttribPointer(sh_in_UV, 2, GL_FLOAT, GL_FALSE, 0, 0);