wx_BGI_Graphics
Classic BGI-compatible graphics API with modern OpenGL extension API
Loading...
Searching...
No Matches
src
bgi_gl_shaders.h
Go to the documentation of this file.
1
#pragma once
18
// =============================================================================
19
// 1. Page-texture program — fullscreen quad with RGBA texture
20
// =============================================================================
21
22
static
const
char
*kPageTexVertSrc = R
"GLSL(
23
#version 330 core
24
layout(location = 0) in vec2 aPos;
25
layout(location = 1) in vec2 aUV;
26
out vec2 vUV;
27
void main() {
28
vUV = aUV;
29
gl_Position = vec4(aPos, 0.0, 1.0);
30
}
31
)GLSL";
32
33
static
const
char
*kPageTexFragSrc = R
"GLSL(
34
#version 330 core
35
in vec2 vUV;
36
out vec4 fragColor;
37
uniform sampler2D uTex;
38
void main() {
39
fragColor = texture(uTex, vUV);
40
}
41
)GLSL";
42
43
// =============================================================================
44
// 2. Flat Phong solid program
45
// Vertex shader passes colour and face normal flat to fragment shader.
46
// Fragment shader applies full Phong lighting once per fragment (constant
47
// per face because the normal is flat-interpolated).
48
// =============================================================================
49
50
static
const
char
*kFlatVertSrc = R
"GLSL(
51
#version 330 core
52
layout(location = 0) in vec3 aPos;
53
layout(location = 1) in vec3 aNormal;
54
layout(location = 2) in vec3 aColor;
55
56
flat out vec3 vNormal;
57
flat out vec3 vColor;
58
out vec3 vFragPos;
59
60
uniform mat4 uMVP;
61
uniform mat4 uModel; // model = identity (world coords submitted directly)
62
uniform mat3 uNormMat; // transpose(inverse(model)) for normal transform
63
64
void main() {
65
vFragPos = vec3(uModel * vec4(aPos, 1.0));
66
vNormal = normalize(uNormMat * aNormal);
67
vColor = aColor;
68
gl_Position = uMVP * vec4(aPos, 1.0);
69
}
70
)GLSL";
71
72
static
const
char
*kFlatFragSrc = R
"GLSL(
73
#version 330 core
74
flat in vec3 vNormal;
75
flat in vec3 vColor;
76
in vec3 vFragPos;
77
out vec4 fragColor;
78
79
// Primary light
80
uniform vec3 uLightDir; // normalised, in world-space (may be view-rotated outside)
81
uniform float uAmbient;
82
uniform float uDiffuse;
83
uniform float uSpecular;
84
uniform float uShininess;
85
uniform vec3 uCamPos; // world-space camera position (for specular)
86
87
// Fill light
88
uniform vec3 uFillLightDir;
89
uniform float uFillStrength;
90
91
void main() {
92
vec3 N = normalize(vNormal);
93
vec3 L = normalize(-uLightDir);
94
vec3 V = normalize(uCamPos - vFragPos);
95
vec3 R = reflect(uLightDir, N);
96
97
float diff = max(dot(N, L), 0.0);
98
float spec = pow(max(dot(R, V), 0.0), uShininess);
99
float fillDif = max(dot(N, normalize(-uFillLightDir)), 0.0) * uFillStrength;
100
101
vec3 lit = vColor * (uAmbient + uDiffuse * diff + uFillStrength * fillDif)
102
+ vec3(1.0) * uSpecular * spec;
103
104
fragColor = vec4(clamp(lit, 0.0, 1.0), 1.0);
105
}
106
)GLSL";
107
108
// =============================================================================
109
// 3. Smooth Phong solid program (Gouraud-style: normals interpolated per vertex)
110
// =============================================================================
111
112
static
const
char
*kSmoothVertSrc = R
"GLSL(
113
#version 330 core
114
layout(location = 0) in vec3 aPos;
115
layout(location = 1) in vec3 aNormal;
116
layout(location = 2) in vec3 aColor;
117
118
out vec3 vNormal;
119
out vec3 vColor;
120
out vec3 vFragPos;
121
122
uniform mat4 uMVP;
123
uniform mat4 uModel;
124
uniform mat3 uNormMat;
125
126
void main() {
127
vFragPos = vec3(uModel * vec4(aPos, 1.0));
128
vNormal = normalize(uNormMat * aNormal);
129
vColor = aColor;
130
gl_Position = uMVP * vec4(aPos, 1.0);
131
}
132
)GLSL";
133
134
static
const
char
*kSmoothFragSrc = R
"GLSL(
135
#version 330 core
136
in vec3 vNormal;
137
in vec3 vColor;
138
in vec3 vFragPos;
139
out vec4 fragColor;
140
141
uniform vec3 uLightDir;
142
uniform float uAmbient;
143
uniform float uDiffuse;
144
uniform float uSpecular;
145
uniform float uShininess;
146
uniform vec3 uCamPos;
147
148
uniform vec3 uFillLightDir;
149
uniform float uFillStrength;
150
151
void main() {
152
vec3 N = normalize(vNormal);
153
vec3 L = normalize(-uLightDir);
154
vec3 V = normalize(uCamPos - vFragPos);
155
vec3 R = reflect(uLightDir, N);
156
157
float diff = max(dot(N, L), 0.0);
158
float spec = pow(max(dot(R, V), 0.0), uShininess);
159
float fillDif = max(dot(N, normalize(-uFillLightDir)), 0.0) * uFillStrength;
160
161
vec3 lit = vColor * (uAmbient + uDiffuse * diff + uFillStrength * fillDif)
162
+ vec3(1.0) * uSpecular * spec;
163
164
fragColor = vec4(clamp(lit, 0.0, 1.0), 1.0);
165
}
166
)GLSL";
167
168
// =============================================================================
169
// 4. Depth-tested line program — colour passthrough, no lighting
170
// =============================================================================
171
172
static
const
char
*kLineVertSrc = R
"GLSL(
173
#version 330 core
174
layout(location = 0) in vec3 aPos;
175
layout(location = 1) in vec3 aColor;
176
out vec3 vColor;
177
uniform mat4 uMVP;
178
void main() {
179
vColor = aColor;
180
gl_Position = uMVP * vec4(aPos, 1.0);
181
}
182
)GLSL";
183
184
static
const
char
*kLineFragSrc = R
"GLSL(
185
#version 330 core
186
in vec3 vColor;
187
out vec4 fragColor;
188
void main() {
189
fragColor = vec4(vColor, 1.0);
190
}
191
)GLSL";
Generated by
1.9.8