Skip to content

Commit

Permalink
Uses now basic_vs vertex shader
Browse files Browse the repository at this point in the history
- No normals or light direction
  • Loading branch information
Zardoz89 committed Feb 16, 2015
1 parent 100d7b7 commit 4aeda06
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
22 changes: 14 additions & 8 deletions assets/shaders/basic_vs.vert
Original file line number Diff line number Diff line change
@@ -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;
}

26 changes: 13 additions & 13 deletions assets/shaders/retro_texture.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -36,7 +36,7 @@ const float distortion = 0.08;

// Flicker intesity
//const float flicker = 0.025;

// Time depedent FX
uniform float time = 0.0;

Expand All @@ -51,21 +51,21 @@ 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;
}

// 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;
Expand All @@ -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);
Expand All @@ -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;

}
2 changes: 1 addition & 1 deletion tools/include/gl_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions tools/src/gl_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4aeda06

Please sign in to comment.