-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fill-extrusion-vertical-gradient property #6841
Changes from all commits
d13dada
47e3dfa
2e93481
084fe11
28082d4
1e66d47
587cf44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,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; | ||
|
@@ -47,7 +48,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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we have any idea where the magic -0.84 comes from? maybe nicki would know There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why would Nicki know? i have no idea where it comes from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nicki worked on the extrusion shaders w lbud There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nickidlugash do you remember where this magic number came from? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ryanhamley @mollymerp I didn't work with lbud on this PR at all, but having worked on the initial implementation of this shader, my guess is that 0.84 is the lower clamp in the gradient logic when 0.7 and 0.98 are magic numbers that I came up with to keep the vertical gradient consistently subtle, regardless of how intense the light is. I actually wonder though if it would be better not to multiply by a constant here if there is no vertical gradient (i.e. something like |
||
// 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
{ | ||
"version": 8, | ||
"metadata": { | ||
"test": { | ||
"height": 256 | ||
} | ||
}, | ||
"light": { | ||
"intensity": 1 | ||
}, | ||
"sources": { | ||
"geojson": { | ||
"type": "geojson", | ||
"data": { | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"properties": { | ||
"property": 0 | ||
}, | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[ | ||
-0.0003, | ||
-0.0003 | ||
], | ||
[ | ||
-0.0003, | ||
0.0003 | ||
], | ||
[ | ||
0.0003, | ||
0.0003 | ||
], | ||
[ | ||
0.0003, | ||
-0.0003 | ||
], | ||
[ | ||
-0.0003, | ||
-0.0003 | ||
] | ||
] | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"properties": { | ||
"property": 20 | ||
}, | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[ | ||
-0.0003, | ||
-0.0003 | ||
], | ||
[ | ||
-0.0003, | ||
0.0003 | ||
], | ||
[ | ||
0.0003, | ||
0.0003 | ||
], | ||
[ | ||
0.0003, | ||
-0.0003 | ||
], | ||
[ | ||
-0.0003, | ||
-0.0003 | ||
] | ||
] | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"pitch": 60, | ||
"zoom": 18, | ||
"layers": [ | ||
{ | ||
"id": "extrusion", | ||
"type": "fill-extrusion", | ||
"source": "geojson", | ||
"paint": { | ||
"fill-extrusion-height": ["+", ["get", "property"], 18], | ||
"fill-extrusion-base": ["get", "property"], | ||
"fill-extrusion-color": "#999" | ||
} | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
{ | ||
"version": 8, | ||
"metadata": { | ||
"test": { | ||
"height": 256 | ||
} | ||
}, | ||
"light": { | ||
"intensity": 1 | ||
}, | ||
"sources": { | ||
"geojson": { | ||
"type": "geojson", | ||
"data": { | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"properties": { | ||
"property": 0 | ||
}, | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[ | ||
-0.0003, | ||
-0.0003 | ||
], | ||
[ | ||
-0.0003, | ||
0.0003 | ||
], | ||
[ | ||
0.0003, | ||
0.0003 | ||
], | ||
[ | ||
0.0003, | ||
-0.0003 | ||
], | ||
[ | ||
-0.0003, | ||
-0.0003 | ||
] | ||
] | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"properties": { | ||
"property": 20 | ||
}, | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[ | ||
-0.0003, | ||
-0.0003 | ||
], | ||
[ | ||
-0.0003, | ||
0.0003 | ||
], | ||
[ | ||
0.0003, | ||
0.0003 | ||
], | ||
[ | ||
0.0003, | ||
-0.0003 | ||
], | ||
[ | ||
-0.0003, | ||
-0.0003 | ||
] | ||
] | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"pitch": 60, | ||
"zoom": 18, | ||
"layers": [ | ||
{ | ||
"id": "extrusion", | ||
"type": "fill-extrusion", | ||
"source": "geojson", | ||
"paint": { | ||
"fill-extrusion-height": ["+", ["get", "property"], 18], | ||
"fill-extrusion-base": ["get", "property"], | ||
"fill-extrusion-color": "#999", | ||
"fill-extrusion-vertical-gradient": false | ||
} | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just 1 or 0 right? in that case we can use an integer uniform
Uniform1i
to follow the convention of other uniforms used as booleans such asu_is_zoom_constant
for symbol icons/sdfsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually needs to be a float because the calculation in the shader has float constants.