gKit2 light
Toggle main menu visibility
Loading...
Searching...
No Matches
gkit2_tutos
alpha.glsl
1
2
#version 430
3
4
#ifdef VERTEX_SHADER
5
uniform mat4 mvpMatrix;
6
uniform mat4 mvMatrix;
7
layout(location= 0) in
vec3
position;
8
layout(location= 1) in
vec2
texcoords;
9
10
out
vec3
vertex_position;
11
out
vec2
vertex_texcoords;
12
out
vec3
view_position;
13
14
void
main( )
15
{
16
gl_Position= mvpMatrix *
vec4
(position, 1);
17
vertex_position= position;
18
vertex_texcoords= texcoords;
19
view_position=
vec3
(mvMatrix *
vec4
(position, 1));
20
21
}
22
#endif
23
24
25
#ifdef FRAGMENT_SHADER
26
out
vec4
fragment_color;
27
in
vec3
vertex_position;
28
in
vec2
vertex_texcoords;
29
in
vec3
view_position;
30
31
uniform sampler2D alpha;
32
33
float
hash2D( in
vec2
v ) {
return
fract(1.0e4*sin(17.0*v.x + 0.1*v.y) * (0.1 + abs(sin(13.0*v.y + v.x)))); }
34
float
hash3D( in
vec3
v ) {
return
hash2D(
vec2
(hash2D(v.xy), v.z)); }
35
36
const
int
msaa= 8;
// MSAA samples
37
38
void
main()
39
{
40
// enable GL_MULTISAMPLE
41
// enable GL_SAMPLE_ALPHA_TO_COVERAGE
42
43
//~ // alpha test base
44
//~ if(0.5 < rng)
45
//~ discard;
46
47
// hashed alpha test
48
//~ float rng= hash3D(vertex_position);
49
//~ fragment_color= vec4(0.9, 0.4, 0, rng);
50
51
vec4
color= texture(alpha, vertex_texcoords);
52
// threshold
53
float
i= floor(color.a * msaa);
54
55
//~ // jitter threshold
56
//~ float rng= (i+ hash3D(vertex_position)) / float(n);
57
// jitter
58
float
rng=
min
(msaa, (color.a * msaa + hash3D(
vec3
(vertex_position.xy, view_position.z)) - 0.5)) / float(msaa);
59
//~ // no jitter
60
//~ float rng= i / float(n);
61
62
fragment_color=
vec4
(color.rgb, rng);
63
}
64
65
#endif
min
Point min(const Point &a, const Point &b)
renvoie la plus petite composante de chaque point { min(a.x, b.x), min(a.y, b.y), min(a....
Definition
vec.cpp:30
vec2
vecteur generique, utilitaire.
Definition
vec.h:152
vec3
vecteur generique, utilitaire.
Definition
vec.h:169
vec4
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition
vec.h:192
Generated on
for gKit2 light by
1.17.0