Skip to content

Commit c0bd005

Browse files
committed
shaders
1 parent 4d9a39e commit c0bd005

File tree

5 files changed

+148
-0
lines changed

5 files changed

+148
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifdef GL_ES
2+
precision mediump float;
3+
precision mediump int;
4+
#endif
5+
6+
#define PROCESSING_TEXTURE_SHADER
7+
8+
uniform sampler2D texture;
9+
uniform vec2 texOffset;
10+
11+
varying vec4 vertColor;
12+
varying vec4 vertTexCoord;
13+
14+
void main(void) {
15+
// Grouping texcoord variables in order to make it work in the GMA 950. See post #13
16+
// in this thread:
17+
// http://www.idevgames.com/forums/thread-3467.html
18+
vec2 tc0 = vertTexCoord.st + vec2(-texOffset.s, -texOffset.t);
19+
vec2 tc1 = vertTexCoord.st + vec2( 0.0, -texOffset.t);
20+
vec2 tc2 = vertTexCoord.st + vec2(+texOffset.s, -texOffset.t);
21+
vec2 tc3 = vertTexCoord.st + vec2(-texOffset.s, 0.0);
22+
vec2 tc4 = vertTexCoord.st + vec2( 0.0, 0.0);
23+
vec2 tc5 = vertTexCoord.st + vec2(+texOffset.s, 0.0);
24+
vec2 tc6 = vertTexCoord.st + vec2(-texOffset.s, +texOffset.t);
25+
vec2 tc7 = vertTexCoord.st + vec2( 0.0, +texOffset.t);
26+
vec2 tc8 = vertTexCoord.st + vec2(+texOffset.s, +texOffset.t);
27+
28+
vec4 col0 = texture2D(texture, tc0);
29+
vec4 col1 = texture2D(texture, tc1);
30+
vec4 col2 = texture2D(texture, tc2);
31+
vec4 col3 = texture2D(texture, tc3);
32+
vec4 col4 = texture2D(texture, tc4);
33+
vec4 col5 = texture2D(texture, tc5);
34+
vec4 col6 = texture2D(texture, tc6);
35+
vec4 col7 = texture2D(texture, tc7);
36+
vec4 col8 = texture2D(texture, tc8);
37+
38+
vec4 sum = 8.0 * col4 - (col0 + col1 + col2 + col3 + col5 + col6 + col7 + col8);
39+
gl_FragColor = vec4(sum.rgb, 1.0) * vertColor;
40+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifdef GL_ES
2+
precision mediump float;
3+
precision mediump int;
4+
#endif
5+
6+
uniform sampler2D texture;
7+
uniform vec2 texOffset;
8+
9+
varying vec4 vertColor;
10+
varying vec4 vertTexCoord;
11+
12+
const vec4 lumcoeff = vec4(0.299, 0.587, 0.114, 0);
13+
14+
void main() {
15+
vec2 tc0 = vertTexCoord.st + vec2(-texOffset.s, -texOffset.t);
16+
vec2 tc1 = vertTexCoord.st + vec2( 0.0, -texOffset.t);
17+
vec2 tc2 = vertTexCoord.st + vec2(+texOffset.s, -texOffset.t);
18+
vec2 tc3 = vertTexCoord.st + vec2(-texOffset.s, 0.0);
19+
vec2 tc4 = vertTexCoord.st + vec2( 0.0, 0.0);
20+
vec2 tc5 = vertTexCoord.st + vec2(+texOffset.s, 0.0);
21+
vec2 tc6 = vertTexCoord.st + vec2(-texOffset.s, +texOffset.t);
22+
vec2 tc7 = vertTexCoord.st + vec2( 0.0, +texOffset.t);
23+
vec2 tc8 = vertTexCoord.st + vec2(+texOffset.s, +texOffset.t);
24+
25+
vec4 col0 = texture2D(texture, tc0);
26+
vec4 col1 = texture2D(texture, tc1);
27+
vec4 col2 = texture2D(texture, tc2);
28+
vec4 col3 = texture2D(texture, tc3);
29+
vec4 col4 = texture2D(texture, tc4);
30+
vec4 col5 = texture2D(texture, tc5);
31+
vec4 col6 = texture2D(texture, tc6);
32+
vec4 col7 = texture2D(texture, tc7);
33+
vec4 col8 = texture2D(texture, tc8);
34+
35+
vec4 sum = 8.0 * col4 - (col0 + col1 + col2 + col3 + col5 + col6 + col7 + col8);
36+
gl_FragColor = vec4(sum.rgb, 1.0) * vertColor;
37+
}
42.2 KB
Loading
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env jruby -v -W2
2+
# frozen_string_literal: true
3+
require 'propane'
4+
5+
class EdgeDetect < Propane::App
6+
attr_reader :edges, :img , :enabled
7+
8+
def setup
9+
sketch_title 'Edge detect'
10+
@enabled = true
11+
@img = load_image(data_path('leaves.jpg'))
12+
@edges = load_shader(data_path('edges.glsl'))
13+
end
14+
15+
def draw
16+
shader(edges) if enabled
17+
image(img, 0, 0)
18+
end
19+
20+
def mouse_pressed
21+
@enabled = !enabled
22+
reset_shader if !enabled
23+
end
24+
25+
def settings
26+
size(640, 360, P2D)
27+
end
28+
end
29+
30+
EdgeDetect.new
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env jruby -v -W2
2+
# frozen_string_literal: true
3+
require 'propane'
4+
5+
class EdgeFilter < Propane::App
6+
attr_reader :edges, :apply_filter
7+
8+
def setup
9+
sketch_title 'Edge Filter'
10+
@apply_filter = true
11+
@edges = load_shader(data_path('edges.glsl'))
12+
no_stroke
13+
end
14+
15+
def draw
16+
background(0)
17+
lights
18+
translate(width / 2, height / 2)
19+
push_matrix
20+
rotate_x(frame_count * 0.01)
21+
rotate_y(frame_count * 0.01)
22+
box(120)
23+
pop_matrix
24+
filter(edges) if apply_filter
25+
# The sphere doesn't have the edge detection applied
26+
# on it because it is drawn after filter is called.
27+
rotate_y(frame_count * 0.02)
28+
translate(150, 0)
29+
sphere(40)
30+
end
31+
32+
def mouse_pressed
33+
@apply_filter = !apply_filter
34+
end
35+
36+
def settings
37+
size(640, 360, P3D)
38+
end
39+
end
40+
41+
EdgeFilter.new

0 commit comments

Comments
 (0)