graphics

experiments with opengl3.2/ogles3.3 on linux and win7
git clone http://frotz.net/git/graphics.git
Log | Files | Refs

rectangle.glsl (1742B)


      1 #version 140
      2 #extension GL_ARB_explicit_attrib_location : enable
      3 
      4 -- vertex
      5 
      6 layout (location = 0) in vec4 aPosition;
      7 layout (location = 1) in vec2 aTexCoord;
      8 
      9 out vec2 vTexCoord;
     10 
     11 void main() {
     12 	vTexCoord = aTexCoord;
     13 	gl_Position = aPosition;
     14 }
     15 
     16 -- fragment
     17 
     18 uniform sampler2DRect sampler0;
     19 
     20 uniform float offset[3] =
     21 	float[]( 0.0, 1.3846153846, 3.2307692308 );
     22 uniform float weight[3] =
     23 	float[]( 0.2270270270, 0.3162162162, 0.0702702703 );
     24 
     25 in vec2 vTexCoord;
     26 
     27 layout (location = 0) out vec4 fColor;
     28 
     29 void main() {
     30 #ifdef SKIPLINES
     31 	if ((int(gl_FragCoord.y) & 1) == 1) {
     32 		discard;
     33 		return;
     34 	}
     35 #endif
     36 #ifdef SKIP2LINES
     37 	if ((int(gl_FragCoord.y) & 3) < 2) {
     38 		discard;
     39 		return;
     40 	}
     41 #endif
     42 #ifdef PIXELATE
     43 	fColor = texture(sampler0, floor(gl_FragCoord.xy / 8.0) * 8.0);
     44 #endif
     45 #ifdef GRAY
     46 	float gray = dot(texture(sampler0, gl_FragCoord.xy).rgb, vec3(0.299, 0.587, 0.114));
     47 	fColor = vec4(gray, gray, gray, 1.0);
     48 #endif
     49 #ifdef GREEN
     50 	float gray = dot(texture(sampler0, gl_FragCoord.xy).rgb, vec3(0.299, 0.587, 0.114));
     51 	fColor = vec4(vec3(0.0, 1.0, 0.0) * gray, 1.0);
     52 #endif
     53 #ifdef HBLUR
     54 	vec2 xy = gl_FragCoord.xy;
     55 	vec4 c = texture(sampler0, xy / 1.0) * weight[0];
     56 	for (int i = 1; i < 3; i++) {
     57 		vec2 delta = vec2(offset[i], 0);
     58 		c += texture(sampler0, (xy + delta) / 1.0) * weight[i];
     59 		c += texture(sampler0, (xy - delta) / 1.0) * weight[i];
     60 	}
     61 	fColor = c;
     62 #endif
     63 #ifdef VBLUR
     64 	vec2 xy = gl_FragCoord.xy;
     65 	vec4 c = texture(sampler0, xy / 1.0) * weight[0];
     66 	for (int i = 1; i < 3; i++) {
     67 		vec2 delta = vec2(0, offset[i]);
     68 		c += texture(sampler0, (xy + delta) / 1.0) * weight[i];
     69 		c += texture(sampler0, (xy - delta) / 1.0) * weight[i];
     70 	}
     71 	fColor = c;
     72 #endif
     73 #ifdef COPY
     74 	fColor = texture(sampler0, gl_FragCoord.xy);
     75 #endif
     76 }