gKit2 light
Loading...
Searching...
No Matches
deferred_decal.glsl
1
2#version 330
3
4#ifdef VERTEX_SHADER
5layout(location= 0) in vec3 position;
6
7uniform mat4 mvpMatrix;
8
9void main( )
10{
11 gl_Position= mvpMatrix * vec4(position, 1);
12}
13#endif
14
15#ifdef FRAGMENT_SHADER
16out vec4 fragment_color;
17
18uniform mat4 invMatrix;
19
20uniform sampler2D decal_texture;
21uniform sampler2D color_texture;
22uniform sampler2D depth_texture;
23
24void main( )
25{
26 // couleur de l'objet deja dessine, pour la modifier en fonction du decal
27 vec3 color= texelFetch(color_texture, ivec2(gl_FragCoord.xy), 0).rgb;
28
29 // retrouve la position du fragment deja dessine dans le monde
30 float z= texelFetch(depth_texture, ivec2(gl_FragCoord.xy), 0).r;
31 vec4 position= vec4(gl_FragCoord.xy, z, 1);
32
33 // passage dans le repere du decal
34 vec4 decal_position= invMatrix * position;
35
36 vec4 decal= textureProj(decal_texture, decal_position);
37 if(decal.a < 0.3)
38 discard;
39 vec3 decal_color= decal.rgb;
40
41 // test d'inclusion
42 vec3 texcoord= decal_position.xyz / decal_position.w;
43 if(texcoord.x < 0 || texcoord.x > 1)
44 discard;
45 if(texcoord.y < 0 || texcoord.y > 1)
46 discard;
47 if(texcoord.z < 0 || texcoord.z > 1)
48 discard;
49
50 color= color * decal_color;
51 fragment_color= vec4(color, 1);
52}
53#endif
vecteur generique, utilitaire.
Definition vec.h:169
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition vec.h:192