Files
MapLibreParticleLab/include/mbgl/shaders/gl/drawable_fill_extrusion.hpp
Alex Cristici f582327191 UBO consolidation (#3089)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-01-08 17:41:29 +02:00

140 lines
4.3 KiB
C++

// Generated code, do not modify this file!
#pragma once
#include <mbgl/shaders/shader_source.hpp>
namespace mbgl {
namespace shaders {
template <>
struct ShaderSource<BuiltIn::FillExtrusionShader, gfx::Backend::Type::OpenGL> {
static constexpr const char* name = "FillExtrusionShader";
static constexpr const char* vertex = R"(layout (location = 0) in vec2 a_pos;
layout (location = 1) in vec4 a_normal_ed;
out vec4 v_color;
layout (std140) uniform FillExtrusionDrawableUBO {
highp mat4 u_matrix;
highp vec2 u_pixel_coord_upper;
highp vec2 u_pixel_coord_lower;
highp float u_height_factor;
highp float u_tile_ratio;
// Interpolations
highp float u_base_t;
highp float u_height_t;
highp float u_color_t;
highp float u_pattern_from_t;
highp float u_pattern_to_t;
lowp float drawable_pad1;
};
layout (std140) uniform FillExtrusionTilePropsUBO {
highp vec4 u_pattern_from;
highp vec4 u_pattern_to;
highp vec2 u_texsize;
lowp float tileprops_pad1;
lowp float tileprops_pad2;
};
layout (std140) uniform FillExtrusionPropsUBO {
highp vec4 u_color;
highp vec3 u_lightcolor;
lowp float props_pad1;
highp vec3 u_lightpos;
highp float u_base;
highp float u_height;
highp float u_lightintensity;
highp float u_vertical_gradient;
highp float u_opacity;
highp float u_fade;
highp float u_from_scale;
highp float u_to_scale;
lowp float props_pad2;
};
#ifndef HAS_UNIFORM_u_base
layout (location = 2) in highp vec2 a_base;
#endif
#ifndef HAS_UNIFORM_u_height
layout (location = 3) in highp vec2 a_height;
#endif
#ifndef HAS_UNIFORM_u_color
layout (location = 4) in highp vec4 a_color;
#endif
void main() {
#ifndef HAS_UNIFORM_u_base
highp float base = unpack_mix_vec2(a_base, u_base_t);
#else
highp float base = u_base;
#endif
#ifndef HAS_UNIFORM_u_height
highp float height = unpack_mix_vec2(a_height, u_height_t);
#else
highp float height = u_height;
#endif
#ifndef HAS_UNIFORM_u_color
highp vec4 color = unpack_mix_color(a_color, u_color_t);
#else
highp vec4 color = u_color;
#endif
vec3 normal = a_normal_ed.xyz;
base = max(0.0, base);
height = max(0.0, height);
float t = mod(normal.x, 2.0);
gl_Position = u_matrix * vec4(a_pos, t > 0.0 ? height : base, 1);
// Relative luminance (how dark/bright is the surface color?)
float colorvalue = color.r * 0.2126 + color.g * 0.7152 + color.b * 0.0722;
v_color = vec4(0.0, 0.0, 0.0, 1.0);
// Add slight ambient lighting so no extrusions are totally black
vec4 ambientlight = vec4(0.03, 0.03, 0.03, 1.0);
color += ambientlight;
// Calculate cos(theta), where theta is the angle between surface normal and diffuse light ray
float directional = clamp(dot(normal / 16384.0, u_lightpos), 0.0, 1.0);
// Adjust directional so that
// the range of values for highlight/shading is narrower
// with lower light intensity
// and with lighter/brighter surface colors
directional = mix((1.0 - u_lightintensity), max((1.0 - colorvalue + u_lightintensity), 1.0), directional);
// Add gradient along z axis of side surfaces
if (normal.y != 0.0) {
// This avoids another branching statement, but multiplies by a constant of 0.84 if no vertical gradient,
// and otherwise calculates the gradient based on base + height
directional *= (
(1.0 - u_vertical_gradient) +
(u_vertical_gradient * clamp((t + base) * pow(height / 150.0, 0.5), mix(0.7, 0.98, 1.0 - u_lightintensity), 1.0)));
}
// Assign final color based on surface + ambient light color, diffuse light directional, and light color
// with lower bounds adjusted to hue of light
// so that shading is tinted with the complementary (opposite) color to the light color
v_color.r += clamp(color.r * directional * u_lightcolor.r, mix(0.0, 0.3, 1.0 - u_lightcolor.r), 1.0);
v_color.g += clamp(color.g * directional * u_lightcolor.g, mix(0.0, 0.3, 1.0 - u_lightcolor.g), 1.0);
v_color.b += clamp(color.b * directional * u_lightcolor.b, mix(0.0, 0.3, 1.0 - u_lightcolor.b), 1.0);
v_color *= u_opacity;
}
)";
static constexpr const char* fragment = R"(in vec4 v_color;
void main() {
fragColor = v_color;
#ifdef OVERDRAW_INSPECTOR
fragColor = vec4(1.0);
#endif
}
)";
};
} // namespace shaders
} // namespace mbgl