gKit2 light
Toggle main menu visibility
Loading...
Searching...
No Matches
gkit2_tutos
deferred_decal.glsl
1
2
#version 330
3
4
#ifdef VERTEX_SHADER
5
layout(location= 0) in
vec3
position;
6
7
uniform mat4 mvpMatrix;
8
9
void
main( )
10
{
11
gl_Position= mvpMatrix *
vec4
(position, 1);
12
}
13
#endif
14
15
#ifdef FRAGMENT_SHADER
16
out
vec4
fragment_color;
17
18
uniform mat4 invMatrix;
19
20
uniform sampler2D decal_texture;
21
uniform sampler2D color_texture;
22
uniform sampler2D depth_texture;
23
24
void
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
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