UFO: Alien Invasion
Loading...
Searching...
No Matches
warp_fs.glsl
Go to the documentation of this file.
1/**
2 * @file
3 * @brief Warp fragment shader.
4 */
5
6#if r_postprocess
7 /*
8 * Indicates that gl_FragData is written to, not gl_FragColor.
9 * #extension needs to be placed before all non preprocessor code.
10 */
11 #extension GL_ARB_draw_buffers : enable
12#endif
13
14#include "fog_fs.glsl"
15
16#ifndef glsl110
17 #if r_postprocess
18 /** After glsl1110 this need to be explicitly declared; used by fixed functionality at the end of the OpenGL pipeline.*/
19 out vec4 gl_FragData[2];
20 #else
21 /** After glsl1110 this need to be explicitly declared; used by fixed functionality at the end of the OpenGL pipeline.*/
22 out vec4 gl_FragColor;
23 #endif
24#endif
25
26uniform vec4 OFFSET;
27uniform float GLOWSCALE;
28
29uniform sampler2D SAMPLER_DIFFUSE;
30uniform sampler2D SAMPLER_WARP;
31uniform sampler2D SAMPLER_GLOWMAP;
32
33/**
34 * @brief Main.
35 */
36void main(void) {
37 vec4 finalColor = vec4(0.0);
38
39 /* Sample glowmap and calculate final glow color. */
40 vec4 glow_tex = texture2D(SAMPLER_GLOWMAP, gl_TexCoord[0].st);
41 vec3 glowcolor = glow_tex.rgb * glow_tex.a * GLOWSCALE;
42
43 /* Sample the warp texture at a time-varied offset, */
44 vec4 warp = texture2D(SAMPLER_WARP, gl_TexCoord[0].xy + OFFSET.xy);
45
46 /* and derive a diffuse texcoord based on the warp data, */
47 vec2 coord = vec2(gl_TexCoord[0].x + warp.z, gl_TexCoord[0].y + warp.w);
48
49 /* sample the diffuse texture, factoring in primary color as well. */
50 finalColor = gl_Color * texture2D(SAMPLER_DIFFUSE, coord);
51
52#if r_fog
53 /* Add fog.*/
54 finalColor = FogFragment(finalColor);
55#endif
56
57#if r_postprocess
58 gl_FragData[0] = finalColor;
59 if (GLOWSCALE > 0.01) {
60 gl_FragData[1].rgb = glowcolor;
61 gl_FragData[1].a = 1.0;
62 } else {
63 gl_FragData[1] = vec4(0,0,0,1);
64 }
65#else
66 gl_FragColor.rgb = finalColor.rgb + glowcolor;
67 gl_FragColor.a = finalColor.a;
68#endif
69}