gKit2 light
Loading...
Searching...
No Matches
mesh_viewer.glsl
Go to the documentation of this file.
1
2
3#version 330
4
5#ifdef VERTEX_SHADER
6layout(location= 0) in vec3 position;
7layout(location= 1) in vec2 texcoord;
8layout(location= 2) in vec3 normal;
9
10uniform mat4 mvpMatrix;
11uniform mat4 mvMatrix;
12
13out vec3 vertex_position;
14out vec2 vertex_texcoord;
15out vec3 vertex_normal;
16out vec3 vertex_uv;
17
18void 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
36uniform float flat_shading;
37uniform vec4 diffuse_color;
38uniform sampler2D diffuse_texture;
39
40in vec3 vertex_position;
41in vec2 vertex_texcoord;
42in vec3 vertex_normal;
43in vec3 vertex_uv;
44
45out vec4 fragment_color;
46
47void 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
Color abs(const Color &color)
renvoie la valeur absolue de chaque canal.
Definition color.cpp:71
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