gKit2 light
Toggle main menu visibility
Loading...
Searching...
No Matches
gkit2_tutos
mesh_viewer.glsl
Go to the documentation of this file.
1
2
3
#version 330
4
5
#ifdef VERTEX_SHADER
6
layout(location= 0) in
vec3
position;
7
layout(location= 1) in
vec2
texcoord;
8
layout(location= 2) in
vec3
normal;
9
10
uniform mat4 mvpMatrix;
11
uniform mat4 mvMatrix;
12
13
out
vec3
vertex_position;
14
out
vec2
vertex_texcoord;
15
out
vec3
vertex_normal;
16
out
vec3
vertex_uv;
17
18
void
main( )
19
{
20
gl_Position= mvpMatrix *
vec4
(position, 1);
21
22
// coordonnees barycentriques des sommets abc d'un triangle
23
const
vec3
uv[3]=
vec3
[3](
vec3
(1, 0, 0),
vec3
(0, 1, 0),
vec3
(0, 0, 1));
24
vertex_uv= uv[gl_VertexID%3];
25
26
vertex_position=
vec3
(mvMatrix *
vec4
(position, 1));
27
vertex_texcoord= texcoord;
28
vertex_normal= mat3(mvMatrix) * normal;
29
}
30
31
#endif
32
33
34
#ifdef FRAGMENT_SHADER
35
36
uniform
float
flat_shading;
37
uniform
vec4
diffuse_color;
38
uniform sampler2D diffuse_texture;
39
40
in
vec3
vertex_position;
41
in
vec2
vertex_texcoord;
42
in
vec3
vertex_normal;
43
in
vec3
vertex_uv;
44
45
out
vec4
fragment_color;
46
47
void
main( )
48
{
49
float
cos_theta=
abs
(
dot
(
normalize
(- vertex_position),
normalize
(vertex_normal)));
50
if
(flat_shading != 0)
51
cos_theta= 1;
52
53
#if 0
54
// utilise uniquement l'uniform color
55
vec3
color= diffuse_color.rgb * cos_theta;
56
//~ vec3 color= diffuse_color.rgb;
57
#else
58
// ou : utilise la texture
59
vec4
color_texture= texture(diffuse_texture, vertex_texcoord);
60
if
(color_texture.a < 0.3)
61
discard;
62
63
// module la couleur de la matiere par la couleur de la texture
64
vec3
color= diffuse_color.rgb * color_texture.rgb * cos_theta;
65
#endif
66
67
// applique une correction gamma au resultat
68
//~ fragment_color= vec4(pow(color, vec3(1.0 / 2, 1.0 / 2, 1.0 / 2)), 1);
69
70
fragment_color=
vec4
(color, 1);
71
//~ fragment_color= vec4(abs(vertex_texcoord), 0, 1);
72
}
73
74
#endif
abs
Color abs(const Color &color)
renvoie la valeur absolue de chaque canal.
Definition
color.cpp:71
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