gKit2 light
Toggle main menu visibility
Loading...
Searching...
No Matches
gkit2_tutos
alpha_notexture.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
layout(location= 2) in
vec3
normal;
10
11
out
vec3
vertex_position;
12
out
vec2
vertex_texcoords;
13
14
out
vec3
view_position;
15
out
vec3
view_normal;
16
17
void
main( )
18
{
19
gl_Position= mvpMatrix *
vec4
(position, 1);
20
21
vertex_position= position;
22
vertex_texcoords= texcoords;
23
24
view_position=
vec3
(mvMatrix *
vec4
(position, 1));
25
view_normal= mat3(mvMatrix) * normal;
26
}
27
#endif
28
29
30
#ifdef FRAGMENT_SHADER
31
out
vec4
fragment_color;
32
33
in
vec3
vertex_position;
34
in
vec2
vertex_texcoords;
35
36
in
vec3
view_position;
37
in
vec3
view_normal;
38
39
40
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)))); }
41
float
hash3D( in
vec3
v ) {
return
hash2D(
vec2
(hash2D(v.xy), v.z)); }
42
43
const
int
msaa= 8;
// MSAA samples
44
45
float
fresnel(
const
in
float
F0,
const
in
vec3
n,
const
in
vec3
l )
46
{
47
float
ndotl= abs(
dot
(n, l));
48
return
F0 + (1 - F0) * pow(1 - ndotl, 5);
49
}
50
51
//~ layout(early_fragment_tests) in;
52
53
void
main()
54
{
55
// enable GL_MULTISAMPLE
56
// enable GL_SAMPLE_ALPHA_TO_COVERAGE
57
58
vec4
color=
vec4
(1);
59
60
vec3
n=
normalize
(view_normal);
61
vec3
o=
normalize
(- view_position);
62
float
f= fresnel(0.028, n, o);
63
64
// threshold
65
float
i= floor(f * msaa);
66
//~ // jitter threshold
67
//~ float rng= min(msaa, (i + hash3D(view_position))) / float(msaa);
68
//~ // no jitter
69
//~ float rng= i / float(msaa);
70
71
float
rng=
min
(msaa, (f * msaa + hash3D(
vec3
(vertex_position.xy, view_position.z)) - 0.5)) / float(msaa);
72
73
fragment_color=
vec4
(color.rgb, rng);
74
//~ fragment_color= vec4(color.rgb, f);
75
//~ fragment_color= vec4(vec3(f), 1);
76
}
77
78
#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
dot
float dot(const Vector &u, const Vector &v)
renvoie le produit scalaire de 2 vecteurs.
Definition
vec.cpp:181
normalize
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
Definition
vec.cpp:167
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