-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't leave alpha of fog color unused (#10633)
* Don't leave alpha of fog color unused * Apply review comments: Simplify flow, reduce uniforms * Fix naming * Update docs * Fix flow
- Loading branch information
1 parent
ad2ea60
commit 1e7e2e1
Showing
21 changed files
with
284 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,48 @@ | ||
// @flow | ||
|
||
import Context from '../gl/context.js'; | ||
import type {UniformLocations} from './uniform_binding.js'; | ||
|
||
import {Uniform1f, Uniform2f, Uniform3f, UniformMatrix4f} from './uniform_binding.js'; | ||
import type {UniformLocations, UniformValues} from './uniform_binding.js'; | ||
import type {UnwrappedTileID} from '../source/tile_id.js'; | ||
import Painter from './painter.js'; | ||
import Fog from '../style/fog.js'; | ||
import {Uniform1f, Uniform2f, Uniform4f, UniformMatrix4f} from './uniform_binding.js'; | ||
|
||
export type FogUniformsType = {| | ||
'u_fog_matrix': UniformMatrix4f, | ||
'u_fog_range': Uniform2f, | ||
'u_fog_color': Uniform3f, | ||
'u_fog_color': Uniform4f, | ||
'u_fog_horizon_blend': Uniform1f, | ||
'u_fog_temporal_offset': Uniform1f, | ||
'u_fog_opacity': Uniform1f, | ||
|
||
|}; | ||
|
||
export const fogUniforms = (context: Context, locations: UniformLocations): FogUniformsType => ({ | ||
'u_fog_matrix': new UniformMatrix4f(context, locations.u_fog_matrix), | ||
'u_fog_range': new Uniform2f(context, locations.u_fog_range), | ||
'u_fog_color': new Uniform3f(context, locations.u_fog_color), | ||
'u_fog_color': new Uniform4f(context, locations.u_fog_color), | ||
'u_fog_horizon_blend': new Uniform1f(context, locations.u_fog_horizon_blend), | ||
'u_fog_temporal_offset': new Uniform1f(context, locations.u_fog_temporal_offset), | ||
'u_fog_opacity': new Uniform1f(context, locations.u_fog_opacity), | ||
}); | ||
|
||
export const fogUniformValues = ( | ||
painter: Painter, | ||
fog: Fog, | ||
tileID: ?UnwrappedTileID, | ||
fogOpacity: number | ||
): UniformValues<FogUniformsType> => { | ||
const fogColor = fog.properties.get('color'); | ||
const temporalOffset = (painter.frameCounter / 1000.0) % 1; | ||
const fogColorUnpremultiplied = [ | ||
fogColor.r / fogColor.a, | ||
fogColor.g / fogColor.a, | ||
fogColor.b / fogColor.a, | ||
fogOpacity | ||
]; | ||
return { | ||
'u_fog_matrix': tileID ? painter.transform.calculateFogTileMatrix(tileID) : painter.identityMat, | ||
'u_fog_range': fog.properties.get('range'), | ||
'u_fog_color': fogColorUnpremultiplied, | ||
'u_fog_horizon_blend': fog.properties.get('horizon-blend'), | ||
'u_fog_temporal_offset': temporalOffset | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions
29
test/integration/render-tests/fog/color-opacity/style.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"version": 8, | ||
"metadata": { | ||
"test": { | ||
"height": 256, | ||
"allowed": 0.0005 | ||
} | ||
}, | ||
"center": [ | ||
52.499167, | ||
13.418056 | ||
], | ||
"zoom": 16, | ||
"pitch": 70, | ||
"fog": { | ||
"range": [1, 4], | ||
"color": "rgba(255, 30, 35, 0.8)" | ||
}, | ||
"sources": {}, | ||
"layers": [ | ||
{ | ||
"id": "background", | ||
"type": "background", | ||
"paint": { | ||
"background-color": "beige" | ||
} | ||
} | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.