11 static constexpr
const char* vertex = R
"(uniform mat4 u_matrix;
12 uniform vec3 u_lightcolor;
13 uniform lowp vec3 u_lightpos;
14 uniform lowp float u_lightintensity;
15 uniform float u_vertical_gradient;
16 uniform lowp float u_opacity;
18 layout (location = 0) in vec2 a_pos;
19 layout (location = 1) in vec4 a_normal_ed;
22 #ifndef HAS_UNIFORM_u_base
23 uniform lowp float u_base_t;
24 layout (location = 2) in highp vec2 a_base;
26 uniform highp float u_base;
28 #ifndef HAS_UNIFORM_u_height
29 uniform lowp float u_height_t;
30 layout (location = 3) in highp vec2 a_height;
32 uniform highp float u_height;
35 #ifndef HAS_UNIFORM_u_color
36 uniform lowp float u_color_t;
37 layout (location = 4) in highp vec4 a_color;
39 uniform highp vec4 u_color;
43 #ifndef HAS_UNIFORM_u_base
44 highp float base = unpack_mix_vec2(a_base, u_base_t);
46 highp float base = u_base;
48 #ifndef HAS_UNIFORM_u_height
49 highp float height = unpack_mix_vec2(a_height, u_height_t);
51 highp float height = u_height;
53 #ifndef HAS_UNIFORM_u_color
54 highp vec4 color = unpack_mix_color(a_color, u_color_t);
56 highp vec4 color = u_color;
59 vec3 normal = a_normal_ed.xyz;
61 base = max(0.0, base);
62 height = max(0.0, height);
64 float t = mod(normal.x, 2.0);
66 gl_Position = u_matrix * vec4(a_pos, t > 0.0 ? height : base, 1);
68 // Relative luminance (how dark/bright is the surface color?)
69 float colorvalue = color.r * 0.2126 + color.g * 0.7152 + color.b * 0.0722;
71 v_color = vec4(0.0, 0.0, 0.0, 1.0);
73 // Add slight ambient lighting so no extrusions are totally black
74 vec4 ambientlight = vec4(0.03, 0.03, 0.03, 1.0);
75 color += ambientlight;
77 // Calculate cos(theta), where theta is the angle between surface normal and diffuse light ray
78 float directional = clamp(dot(normal / 16384.0, u_lightpos), 0.0, 1.0);
80 // Adjust directional so that
81 // the range of values for highlight/shading is narrower
82 // with lower light intensity
83 // and with lighter/brighter surface colors
84 directional = mix((1.0 - u_lightintensity), max((1.0 - colorvalue + u_lightintensity), 1.0), directional);
86 // Add gradient along z axis of side surfaces
87 if (normal.y != 0.0) {
88 // This avoids another branching statement, but multiplies by a constant of 0.84 if no vertical gradient,
89 // and otherwise calculates the gradient based on base + height
91 (1.0 - u_vertical_gradient) +
92 (u_vertical_gradient * clamp((t + base) * pow(height / 150.0, 0.5), mix(0.7, 0.98, 1.0 - u_lightintensity), 1.0)));
95 // Assign final color based on surface + ambient light color, diffuse light directional, and light color
96 // with lower bounds adjusted to hue of light
97 // so that shading is tinted with the complementary (opposite) color to the light color
98 v_color.r += clamp(color.r * directional * u_lightcolor.r, mix(0.0, 0.3, 1.0 - u_lightcolor.r), 1.0);
99 v_color.g += clamp(color.g * directional * u_lightcolor.g, mix(0.0, 0.3, 1.0 - u_lightcolor.g), 1.0);
100 v_color.b += clamp(color.b * directional * u_lightcolor.b, mix(0.0, 0.3, 1.0 - u_lightcolor.b), 1.0);
101 v_color *= u_opacity;
104 static constexpr
const char* fragment = R
"(in vec4 v_color;
109 #ifdef OVERDRAW_INSPECTOR
110 fragColor = vec4(1.0);
@ OpenGL
The OpenGL API backend.
BuiltIn
This enum is used with the ShaderSource template to select source code for the desired program and gr...
Select shader source based on a program type and a desired graphics API.