[core] Support fill-extrusion-vertical-gradient

This commit is contained in:
Bruno de Oliveira Abinader
2018-11-28 11:29:50 +02:00
parent 217acb8948
commit e64c28613a
30 changed files with 1830 additions and 1576 deletions

View File

@@ -226,7 +226,8 @@ style::FillExtrusionPaintProperties::PossiblyEvaluated RenderFillExtrusionLayer:
evaluated.get<style::FillExtrusionTranslateAnchor>(),
evaluated.get<style::FillExtrusionPattern>(),
evaluated.get<style::FillExtrusionHeight>(),
evaluated.get<style::FillExtrusionBase>()
evaluated.get<style::FillExtrusionBase>(),
evaluated.get<style::FillExtrusionVerticalGradient>()
};
}

View File

@@ -7,8 +7,8 @@ namespace mbgl {
namespace shaders {
const char* extrusion_texture::name = "extrusion_texture";
const char* extrusion_texture::vertexSource = source() + 35603;
const char* extrusion_texture::fragmentSource = source() + 35819;
const char* extrusion_texture::vertexSource = source() + 36207;
const char* extrusion_texture::fragmentSource = source() + 36423;
// Uncompressed source of extrusion_texture.vertex.glsl:
/*

View File

@@ -8,7 +8,7 @@ namespace shaders {
const char* fill_extrusion::name = "fill_extrusion";
const char* fill_extrusion::vertexSource = source() + 27816;
const char* fill_extrusion::fragmentSource = source() + 30616;
const char* fill_extrusion::fragmentSource = source() + 30918;
// Uncompressed source of fill_extrusion.vertex.glsl:
/*
@@ -16,6 +16,7 @@ uniform mat4 u_matrix;
uniform vec3 u_lightcolor;
uniform lowp vec3 u_lightpos;
uniform lowp float u_lightintensity;
uniform float u_vertical_gradient;
attribute vec2 a_pos;
attribute vec4 a_normal_ed;
@@ -100,7 +101,11 @@ void main() {
// Add gradient along z axis of side surfaces
if (normal.y != 0.0) {
directional *= clamp((t + base) * pow(height / 150.0, 0.5), mix(0.7, 0.98, 1.0 - u_lightintensity), 1.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

View File

@@ -7,8 +7,8 @@ namespace mbgl {
namespace shaders {
const char* fill_extrusion_pattern::name = "fill_extrusion_pattern";
const char* fill_extrusion_pattern::vertexSource = source() + 30748;
const char* fill_extrusion_pattern::fragmentSource = source() + 34026;
const char* fill_extrusion_pattern::vertexSource = source() + 31050;
const char* fill_extrusion_pattern::fragmentSource = source() + 34630;
// Uncompressed source of fill_extrusion_pattern.vertex.glsl:
/*
@@ -17,6 +17,7 @@ uniform vec2 u_pixel_coord_upper;
uniform vec2 u_pixel_coord_lower;
uniform float u_height_factor;
uniform vec4 u_scale;
uniform float u_vertical_gradient;
uniform vec3 u_lightcolor;
uniform lowp vec3 u_lightpos;
@@ -132,7 +133,11 @@ void main() {
directional = mix((1.0 - u_lightintensity), max((0.5 + u_lightintensity), 1.0), directional);
if (normal.y != 0.0) {
directional *= clamp((t + base) * pow(height / 150.0, 0.5), mix(0.7, 0.98, 1.0 - u_lightintensity), 1.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)));
}
v_lighting.rgb += clamp(directional * u_lightcolor, mix(vec3(0.0), vec3(0.3), 1.0 - u_lightcolor), vec3(1.0));

View File

@@ -7,8 +7,8 @@ namespace mbgl {
namespace shaders {
const char* hillshade::name = "hillshade";
const char* hillshade::vertexSource = source() + 38765;
const char* hillshade::fragmentSource = source() + 38964;
const char* hillshade::vertexSource = source() + 39369;
const char* hillshade::fragmentSource = source() + 39568;
// Uncompressed source of hillshade.vertex.glsl:
/*

View File

@@ -7,8 +7,8 @@ namespace mbgl {
namespace shaders {
const char* hillshade_prepare::name = "hillshade_prepare";
const char* hillshade_prepare::vertexSource = source() + 36031;
const char* hillshade_prepare::fragmentSource = source() + 36245;
const char* hillshade_prepare::vertexSource = source() + 36635;
const char* hillshade_prepare::fragmentSource = source() + 36849;
// Uncompressed source of hillshade_prepare.vertex.glsl:
/*

View File

@@ -7,8 +7,8 @@ namespace mbgl {
namespace shaders {
const char* line::name = "line";
const char* line::vertexSource = source() + 41600;
const char* line::fragmentSource = source() + 46063;
const char* line::vertexSource = source() + 42204;
const char* line::fragmentSource = source() + 46667;
// Uncompressed source of line.vertex.glsl:
/*

View File

@@ -7,8 +7,8 @@ namespace mbgl {
namespace shaders {
const char* line_gradient::name = "line_gradient";
const char* line_gradient::vertexSource = source() + 47235;
const char* line_gradient::fragmentSource = source() + 51544;
const char* line_gradient::vertexSource = source() + 47839;
const char* line_gradient::fragmentSource = source() + 52148;
// Uncompressed source of line_gradient.vertex.glsl:
/*

View File

@@ -7,8 +7,8 @@ namespace mbgl {
namespace shaders {
const char* line_pattern::name = "line_pattern";
const char* line_pattern::vertexSource = source() + 52829;
const char* line_pattern::fragmentSource = source() + 57905;
const char* line_pattern::vertexSource = source() + 53433;
const char* line_pattern::fragmentSource = source() + 58509;
// Uncompressed source of line_pattern.vertex.glsl:
/*

View File

@@ -7,8 +7,8 @@ namespace mbgl {
namespace shaders {
const char* line_sdf::name = "line_sdf";
const char* line_sdf::vertexSource = source() + 61204;
const char* line_sdf::fragmentSource = source() + 66571;
const char* line_sdf::vertexSource = source() + 61808;
const char* line_sdf::fragmentSource = source() + 67175;
// Uncompressed source of line_sdf.vertex.glsl:
/*

View File

@@ -7,8 +7,8 @@ namespace mbgl {
namespace shaders {
const char* raster::name = "raster";
const char* raster::vertexSource = source() + 68497;
const char* raster::fragmentSource = source() + 69310;
const char* raster::vertexSource = source() + 69101;
const char* raster::fragmentSource = source() + 69914;
// Uncompressed source of raster.vertex.glsl:
/*

File diff suppressed because it is too large Load Diff

View File

@@ -7,8 +7,8 @@ namespace mbgl {
namespace shaders {
const char* symbol_icon::name = "symbol_icon";
const char* symbol_icon::vertexSource = source() + 70714;
const char* symbol_icon::fragmentSource = source() + 74120;
const char* symbol_icon::vertexSource = source() + 71318;
const char* symbol_icon::fragmentSource = source() + 74724;
// Uncompressed source of symbol_icon.vertex.glsl:
/*

View File

@@ -7,8 +7,8 @@ namespace mbgl {
namespace shaders {
const char* symbol_sdf::name = "symbol_sdf";
const char* symbol_sdf::vertexSource = source() + 74570;
const char* symbol_sdf::fragmentSource = source() + 80495;
const char* symbol_sdf::vertexSource = source() + 75174;
const char* symbol_sdf::fragmentSource = source() + 81099;
// Uncompressed source of symbol_sdf.vertex.glsl:
/*

View File

@@ -252,6 +252,33 @@ TransitionOptions FillExtrusionLayer::getFillExtrusionBaseTransition() const {
return impl().paint.template get<FillExtrusionBase>().options;
}
PropertyValue<bool> FillExtrusionLayer::getDefaultFillExtrusionVerticalGradient() {
return { true };
}
PropertyValue<bool> FillExtrusionLayer::getFillExtrusionVerticalGradient() const {
return impl().paint.template get<FillExtrusionVerticalGradient>().value;
}
void FillExtrusionLayer::setFillExtrusionVerticalGradient(PropertyValue<bool> value) {
if (value == getFillExtrusionVerticalGradient())
return;
auto impl_ = mutableImpl();
impl_->paint.template get<FillExtrusionVerticalGradient>().value = value;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
void FillExtrusionLayer::setFillExtrusionVerticalGradientTransition(const TransitionOptions& options) {
auto impl_ = mutableImpl();
impl_->paint.template get<FillExtrusionVerticalGradient>().options = options;
baseImpl = std::move(impl_);
}
TransitionOptions FillExtrusionLayer::getFillExtrusionVerticalGradientTransition() const {
return impl().paint.template get<FillExtrusionVerticalGradient>().options;
}
using namespace conversion;
optional<Error> FillExtrusionLayer::setPaintProperty(const std::string& name, const Convertible& value) {
@@ -264,6 +291,7 @@ optional<Error> FillExtrusionLayer::setPaintProperty(const std::string& name, co
FillExtrusionPattern,
FillExtrusionHeight,
FillExtrusionBase,
FillExtrusionVerticalGradient,
FillExtrusionOpacityTransition,
FillExtrusionColorTransition,
FillExtrusionTranslateTransition,
@@ -271,6 +299,7 @@ optional<Error> FillExtrusionLayer::setPaintProperty(const std::string& name, co
FillExtrusionPatternTransition,
FillExtrusionHeightTransition,
FillExtrusionBaseTransition,
FillExtrusionVerticalGradientTransition,
};
Property property = Property::Unknown;
@@ -345,6 +374,16 @@ optional<Error> FillExtrusionLayer::setPaintProperty(const std::string& name, co
property = Property::FillExtrusionBaseTransition;
}
break;
case util::hashFNV1a("fill-extrusion-vertical-gradient"):
if (name == "fill-extrusion-vertical-gradient") {
property = Property::FillExtrusionVerticalGradient;
}
break;
case util::hashFNV1a("fill-extrusion-vertical-gradient-transition"):
if (name == "fill-extrusion-vertical-gradient-transition") {
property = Property::FillExtrusionVerticalGradientTransition;
}
break;
}
@@ -432,6 +471,18 @@ optional<Error> FillExtrusionLayer::setPaintProperty(const std::string& name, co
}
if (property == Property::FillExtrusionVerticalGradient) {
Error error;
optional<PropertyValue<bool>> typedValue = convert<PropertyValue<bool>>(value, error, false, false);
if (!typedValue) {
return error;
}
setFillExtrusionVerticalGradient(*typedValue);
return nullopt;
}
Error error;
optional<TransitionOptions> transition = convert<TransitionOptions>(value, error);
@@ -474,6 +525,11 @@ optional<Error> FillExtrusionLayer::setPaintProperty(const std::string& name, co
return nullopt;
}
if (property == Property::FillExtrusionVerticalGradientTransition) {
setFillExtrusionVerticalGradientTransition(*transition);
return nullopt;
}
return Error { "layer doesn't support this property" };
}

View File

@@ -40,6 +40,10 @@ struct FillExtrusionBase : DataDrivenPaintProperty<float, attributes::a_base, un
static float defaultValue() { return 0; }
};
struct FillExtrusionVerticalGradient : PaintProperty<bool> {
static bool defaultValue() { return true; }
};
class FillExtrusionPaintProperties : public Properties<
FillExtrusionOpacity,
FillExtrusionColor,
@@ -47,7 +51,8 @@ class FillExtrusionPaintProperties : public Properties<
FillExtrusionTranslateAnchor,
FillExtrusionPattern,
FillExtrusionHeight,
FillExtrusionBase
FillExtrusionBase,
FillExtrusionVerticalGradient
> {};
} // namespace style