forked from Qfusion/glsl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
defaultQ3AShader.frag.glsl
114 lines (95 loc) · 3.43 KB
/
defaultQ3AShader.frag.glsl
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
107
108
109
110
111
112
113
114
#include "include/common.glsl"
#include "include/lightmap.glsl"
#include "include/uniforms.glsl"
#include_if(NUM_DLIGHTS) "include/dlights.glsl"
#include_if(APPLY_FOG) "include/fog.glsl"
#include_if(APPLY_GREYSCALE) "include/greyscale.glsl"
#include "include/varying_q3a.glsl"
#if defined(APPLY_CUBEMAP) || defined(APPLY_CUBEMAP_VERTEX) || defined(APPLY_SURROUNDMAP)
uniform samplerCube u_BaseTexture;
#else
uniform sampler2D u_BaseTexture;
#endif
#ifdef APPLY_DRAWFLAT
uniform myhalf3 u_WallColor;
uniform myhalf3 u_FloorColor;
#endif
#ifdef NUM_LIGHTMAPS
uniform LightmapSampler u_LightmapTexture0;
#if NUM_LIGHTMAPS >= 2
uniform LightmapSampler u_LightmapTexture1;
#if NUM_LIGHTMAPS >= 3
uniform LightmapSampler u_LightmapTexture2;
#if NUM_LIGHTMAPS >= 4
uniform LightmapSampler u_LightmapTexture3;
#endif // NUM_LIGHTMAPS >= 4
#endif // NUM_LIGHTMAPS >= 3
#endif // NUM_LIGHTMAPS >= 2
#endif // NUM_LIGHTMAPS
#if defined(APPLY_SOFT_PARTICLE)
#include "include/softparticle.glsl"
uniform sampler2D u_DepthTexture;
#endif
void main(void)
{
myhalf4 color;
#ifdef NUM_LIGHTMAPS
color = myhalf4(0.0, 0.0, 0.0, qf_FrontColor.a);
color.rgb += myhalf3(Lightmap(u_LightmapTexture0, v_LightmapTexCoord01.st, v_LightmapLayer0123.x)) * LinearColor(u_LightstyleColor[0]);
#if NUM_LIGHTMAPS >= 2
color.rgb += myhalf3(Lightmap(u_LightmapTexture1, v_LightmapTexCoord01.pq, v_LightmapLayer0123.y)) * LinearColor(u_LightstyleColor[1]);
#if NUM_LIGHTMAPS >= 3
color.rgb += myhalf3(Lightmap(u_LightmapTexture2, v_LightmapTexCoord23.st, v_LightmapLayer0123.z)) * LinearColor(u_LightstyleColor[2]);
#if NUM_LIGHTMAPS >= 4
color.rgb += myhalf3(Lightmap(u_LightmapTexture3, v_LightmapTexCoord23.pq, v_LightmapLayer0123.w)) * LinearColor(u_LightstyleColor[3]);
#endif // NUM_LIGHTMAPS >= 4
#endif // NUM_LIGHTMAPS >= 3
#endif // NUM_LIGHTMAPS >= 2
color.rgb *= u_LightingIntensity;
#else
color = myhalf4(qf_FrontColor);
#endif // NUM_LIGHTMAPS
#if defined(APPLY_FOG) && !defined(APPLY_FOG_COLOR)
myhalf fogDensity = FogDensity(v_FogCoord);
#endif
#if defined(NUM_DLIGHTS)
color.rgb += DynamicLightsColor(v_Position);
#endif
myhalf4 diffuse;
#if defined(APPLY_CUBEMAP)
diffuse = myhalf4(qf_textureCube(u_BaseTexture, reflect(v_Position - u_EntityDist, normalize(v_Normal))));
#elif defined(APPLY_CUBEMAP_VERTEX)
diffuse = myhalf4(qf_textureCube(u_BaseTexture, v_TexCoord));
#elif defined(APPLY_SURROUNDMAP)
diffuse = myhalf4(qf_textureCube(u_BaseTexture, v_Position - u_EntityDist));
#else
diffuse = myhalf4(qf_texture(u_BaseTexture, v_TexCoord));
#endif
#ifdef APPLY_DRAWFLAT
myhalf n = myhalf(step(DRAWFLAT_NORMAL_STEP, abs(v_Normal.z)));
diffuse.rgb = myhalf3(mix(LinearColor(u_WallColor), LinearColor(u_FloorColor), n));
#endif
#ifdef APPLY_ALPHA_MASK
color.a *= diffuse.a;
#else
color *= diffuse;
#endif
#ifdef NUM_LIGHTMAPS
// so that team-colored shaders work
color *= myhalf4(qf_FrontColor);
#endif
#ifdef APPLY_GREYSCALE
color.rgb = Greyscale(color.rgb);
#endif
#if defined(APPLY_FOG) && !defined(APPLY_FOG_COLOR)
color.rgb = mix(color.rgb, LinearColor(u_FogColor), fogDensity);
#endif
#if defined(APPLY_SOFT_PARTICLE)
myhalf softness = FragmentSoftness(v_Depth, u_DepthTexture, gl_FragCoord.xy, u_ZRange);
color *= mix(myhalf4(1.0), myhalf4(softness), u_BlendMix.xxxy);
#endif
#ifdef QF_ALPHATEST
QF_ALPHATEST(color.a);
#endif
qf_FragColor = vec4(sRGBColor(color));
}