forked from DaemonEngine/Daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneric_fp.glsl
More file actions
106 lines (80 loc) · 3.07 KB
/
Copy pathgeneric_fp.glsl
File metadata and controls
106 lines (80 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
===========================================================================
Copyright (C) 2006-2011 Robert Beckebans <trebor_7@users.sourceforge.net>
This file is part of XreaL source code.
XreaL source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
XreaL source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with XreaL source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
/* generic_fp.glsl */
#define GENERIC_GLSL
uniform sampler2D u_ColorMap;
uniform float u_AlphaThreshold;
#if defined(USE_MATERIAL_SYSTEM)
uniform bool u_ShowTris;
uniform vec3 u_MaterialColour;
#endif
IN(smooth) vec2 var_TexCoords;
IN(smooth) vec4 var_Color;
#if defined(USE_DEPTH_FADE)
#define DEPTHMAP_GLSL
IN(smooth) float var_FadeDepth;
uniform sampler2D u_DepthMap;
#endif
#if defined(USE_ALPHAGEN_PORTAL)
uniform float u_InversePortalRange;
uniform mat4 u_UnprojectMatrix;
#endif
#insert shaderProfiler_fp
DECLARE_OUTPUT(vec4)
void main()
{
#insert material_fp
#if defined(USE_MATERIAL_SYSTEM)
if( u_ShowTris ) {
outputColor = vec4( 0.0, 0.0, 1.0, 1.0 );
return;
}
#endif
vec4 color = texture2D(u_ColorMap, var_TexCoords);
color *= var_Color;
if( abs(color.a + u_AlphaThreshold) <= 1.0 )
{
discard;
return;
}
// Normally alpha modulation is supposed to be done before the alpha test, but this looks
// better for the ancient-remains foliage combining alphagen portal with an alpha-tested
// plant image: fades out to 0 smoothly instead of cutting off at 0.5.
#if defined(USE_ALPHAGEN_PORTAL)
vec4 position = u_UnprojectMatrix * vec4(gl_FragCoord.xyz, 1.0);
float portalAlpha = length(position.xyz / position.w) * u_InversePortalRange;
portalAlpha = length(position.xyz / position.w) * (1.0/256.0);
color.a *= clamp(portalAlpha, 0.0, 1.0);
#endif
#if defined(USE_DEPTH_FADE)
float depth = texture2D(u_DepthMap, gl_FragCoord.xy / r_FBufSize).x;
// convert z from normalized device coordinates [-1, 1]
// to window coordinates [0, 1]
float fadeDepth = 0.5 * var_FadeDepth + 0.5;
// HACK: the (distance from triangle to object behind it) / (shader's depthFade distance) ratio
// is calculated by using (nonlinear) depth values instead of the correct world units, so the
// fade curve will be different depending on the distance to the viewer and znear/zfar
color.a *= smoothstep(gl_FragCoord.z, fadeDepth, depth);
#endif
SHADER_PROFILER_SET( color )
outputColor = color;
// Debugging.
#if defined(USE_MATERIAL_SYSTEM) && defined(r_showGlobalMaterials)
outputColor.rgb = u_MaterialColour;
#endif
}