gKit2 light
Loading...
Searching...
No Matches
alpha_notexture.glsl
1
2#version 430
3
4#ifdef VERTEX_SHADER
5uniform mat4 mvpMatrix;
6uniform mat4 mvMatrix;
7layout(location= 0) in vec3 position;
8layout(location= 1) in vec2 texcoords;
9layout(location= 2) in vec3 normal;
10
11out vec3 vertex_position;
12out vec2 vertex_texcoords;
13
14out vec3 view_position;
15out vec3 view_normal;
16
17void 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
31out vec4 fragment_color;
32
33in vec3 vertex_position;
34in vec2 vertex_texcoords;
35
36in vec3 view_position;
37in vec3 view_normal;
38
39
40float 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)))); }
41float hash3D( in vec3 v ) { return hash2D(vec2(hash2D(v.xy), v.z)); }
42
43const int msaa= 8; // MSAA samples
44
45float 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
53void 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
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
float dot(const Vector &u, const Vector &v)
renvoie le produit scalaire de 2 vecteurs.
Definition vec.cpp:181
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
Definition vec.cpp:167
vecteur generique, utilitaire.
Definition vec.h:152
vecteur generique, utilitaire.
Definition vec.h:169
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition vec.h:192