forked from QW-Group/ezquake-source
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdraw_world.vertex.glsl
104 lines (90 loc) · 3.08 KB
/
draw_world.vertex.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
#version 430
#ezquake-definitions
layout(location = 0) in vec3 position;
layout(location = 1) in vec3 tex;
layout(location = 2) in vec3 lightmapCoord;
layout(location = 3) in vec2 detailCoord;
layout(location = 4) in int _instanceId;
layout(location = 5) in int vboFlags;
layout(location = 6) in vec3 flatColor;
layout(location = 7) in int surfaceNumber;
out vec3 TexCoordLightmap;
out vec3 TextureCoord;
#ifdef DRAW_TEXTURELESS
out vec3 TextureLessCoord;
#endif
#if defined(DRAW_LUMA_TEXTURES) || defined(DRAW_LUMA_TEXTURES_FB)
out vec3 LumaCoord;
#endif
#ifdef DRAW_DETAIL_TEXTURES
out vec2 DetailCoord;
#endif
out vec3 FlatColor;
out flat int Flags;
out vec3 Direction;
#ifdef DRAW_GEOMETRY
out vec3 Normal;
out vec4 UnClipped;
layout(std140, binding = EZQ_GL_BINDINGPOINT_WORLDMODEL_SURFACES) buffer surface_data {
model_surface surfaces[];
};
#endif
out float mix_floor;
out float mix_wall;
out float alpha;
layout(std140, binding=EZQ_GL_BINDINGPOINT_BRUSHMODEL_DRAWDATA) buffer WorldCvars {
WorldDrawInfo drawInfo[];
};
layout(std140, binding=EZQ_GL_BINDINGPOINT_BRUSHMODEL_SAMPLERS) buffer SamplerMappingsBuffer {
SamplerMapping samplerMapping[];
};
void main()
{
int materialNumber = int(tex.z);
float materialArrayIndex = samplerMapping[drawInfo[_instanceId].samplerBase + materialNumber].layer;
int drawCallFlags = drawInfo[_instanceId].drawFlags;
int textureFlags = samplerMapping[drawInfo[_instanceId].samplerBase + materialNumber].flags;
alpha = drawInfo[_instanceId].alpha;
gl_Position = projectionMatrix * drawInfo[_instanceId].mvMatrix * vec4(position, 1.0);
#ifdef DRAW_GEOMETRY
Normal = surfaces[surfaceNumber].normal.xyz;
UnClipped = drawInfo[_instanceId].mvMatrix * vec4(position, 1.0);
#endif
FlatColor = flatColor;
Flags = vboFlags | drawCallFlags | textureFlags;
if (lightmapCoord.z < 0) {
TextureCoord = vec3(tex.xy, materialArrayIndex);
TexCoordLightmap = vec3(0, 0, 0);
Direction = (position - cameraPosition);
#if defined(DRAW_SKYBOX)
Direction = vec3(-Direction.y, Direction.z, Direction.x);
#endif
#ifdef DRAW_DETAIL_TEXTURES
DetailCoord = vec2(0, 0);
#endif
#if defined(DRAW_LUMA_TEXTURES) || defined(DRAW_LUMA_TEXTURES_FB)
LumaCoord = TextureCoord;
#endif
mix_floor = 0;
mix_wall = 0;
}
else {
#if defined(DRAW_TEXTURELESS) && !defined(DRAW_ALPHATEST_ENABLED)
TextureCoord = vec3(mix(tex.xy, vec2(0, 0), min(Flags & EZQ_SURFACE_WORLD, 1)), materialArrayIndex);
#elif defined(DRAW_TEXTURELESS)
TextureLessCoord = vec3(mix(tex.xy, vec2(0, 0), min(Flags & EZQ_SURFACE_WORLD, 1)), materialArrayIndex);
TextureCoord = vec3(tex.xy, materialArrayIndex);
#else
TextureCoord = vec3(tex.xy, materialArrayIndex);
#endif
#if defined(DRAW_LUMA_TEXTURES) || defined(DRAW_LUMA_TEXTURES_FB)
LumaCoord = (Flags & (EZQ_SURFACE_HAS_LUMA | EZQ_SURFACE_HAS_FB)) != 0 ? vec3(TextureCoord.st, TextureCoord.z + 1) : TextureCoord;
#endif
TexCoordLightmap = lightmapCoord;
#ifdef DRAW_DETAIL_TEXTURES
DetailCoord = detailCoord;
#endif
mix_floor = min(1, (Flags & EZQ_SURFACE_WORLD) * (Flags & EZQ_SURFACE_IS_FLOOR));
mix_wall = min(1, (Flags & EZQ_SURFACE_WORLD) * (1 - mix_floor));
}
}