-
Notifications
You must be signed in to change notification settings - Fork 0
/
Relief.glsl
65 lines (53 loc) · 2.22 KB
/
Relief.glsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#version 450
// Author: Andreas Leeb
// Version: 1.0
precision highp float;
//@implements: sampler2D
struct Relief {
sampler2D sampler;
//@ label: "Mix[%]", editor: range, min: 0, max: 1, range_min: 0, range_max: 1, range_default: 0
float mix;
//@ label: "Direction", editor: range, min: 0, max: 3, range_min: 0, range_max: 3, range_default: 0
float direction;
//@ label: "Width[px]", editor: range, min: 0, max: 10000, range_min: 0, range_max: 10000, range_default: 1920
float width;
//@ label: "Height[px]", editor: range, min: 0, max: 10000, range_min: 0, range_max: 10000, range_default: 1200
float height;
};
vec4 rl_texel(Relief s, vec2 dim, vec2 abs_coords) {
vec2 tex_coords = abs_coords / dim;
return texture(s.sampler, tex_coords);
}
const mat3 weight1 = mat3(-2., -1., 0.,
-1., 1., 1.,
0., 1., 2.);
const mat3 weight2 = mat3( 0., 1., 2.,
-1., 1., 1.,
-2., -1., 0.);
const mat3 weight3 = mat3( 2., 1., 0.,
1., 1., -1.,
0., -1., -2.);
const mat3 weight4 = mat3( 0., -1., -2.,
1., 1., -1.,
2., 1., 0.);
const mat3 weights[] = mat3[](weight1, weight2, weight3, weight4);
const float weightSum = 8.;
const vec2 offset[] = vec2[](vec2(-1., 1.), vec2(0., 1.), vec2(1., 1.),
vec2(-1., 0.), vec2(0., 0.), vec2(1., 0.),
vec2(-1., -1.), vec2(0., -1.), vec2(1., -1.));
vec4 texture(Relief s, vec2 tex_coords) {
//vec2 dim = textureSize(s.sampler, 0); // for GPUpad
vec2 dim = vec2(s.width, s.height); // for Wings
vec4 color = vec4(0.);
int direction = int(s.direction);
vec2 abs_coords = tex_coords * dim;
for(int i = 0; i < offset.length(); i++) {
vec2 coords = abs_coords + offset[i];
if(any(lessThan(coords, vec2(0.))) || any(greaterThan(coords, dim)))
coords = abs_coords;
vec4 texel = rl_texel(s, dim, coords);
color.rgb += texel.rgb * weights[direction][i/3][i%3];
color.a = texel.a;
}
return mix(texture(s.sampler, tex_coords), color, s.mix);
}