Skip to content

Commit

Permalink
fix(ColorLayer): fix shader when transparent is true
Browse files Browse the repository at this point in the history
  • Loading branch information
mgermerie authored and gchoqueux committed Nov 16, 2021
1 parent a0cd2a3 commit 1a4f44d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/Renderer/LayeredMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const defaultStructLayer = {
crs: 0,
effect_parameter: 0,
effect_type: colorLayerEffects.noEffect,
transparent: false,
};

function updateLayersUniforms(uniforms, olayers, max) {
Expand Down
3 changes: 3 additions & 0 deletions src/Renderer/RasterTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ export class RasterColorTile extends RasterTile {
get effect_parameter() {
return this.layer.effect_parameter;
}
get transparent() {
return this.layer.transparent;
}
}

export class RasterElevationTile extends RasterTile {
Expand Down
19 changes: 12 additions & 7 deletions src/Renderer/Shader/Chunk/color_layers_pars_fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ struct Layer {
int effect_type;
float effect_parameter;
float opacity;
bool transparent;
};

#include <itowns/custom_header_colorLayer>
Expand Down Expand Up @@ -61,14 +62,18 @@ vec4 getLayerColor(int textureOffset, sampler2D tex, vec4 offsetScale, Layer lay
float borderDistance = getBorderDistance(uv.xy);
if (textureOffset != layer.textureOffset + int(uv.z) || borderDistance < minBorderDistance ) return vec4(0);
vec4 color = texture2D(tex, pitUV(uv.xy, offsetScale));
if (layer.effect_type == 1) {
color.rgb /= color.a;
color = applyLightColorToInvisibleEffect(color, layer.effect_parameter);
} else if (layer.effect_type == 2) {
color.rgb /= color.a;
color = applyWhiteToInvisibleEffect(color, layer.effect_parameter);
} else if (layer.effect_type == 3) {
if (layer.effect_type == 3) {
#include <itowns/custom_body_colorLayer>
} else {
if (layer.transparent && color.a != 0.0) {
color.rgb /= color.a;
}

if (layer.effect_type == 1) {
color = applyLightColorToInvisibleEffect(color, layer.effect_parameter);
} else if (layer.effect_type == 2) {
color = applyWhiteToInvisibleEffect(color, layer.effect_parameter);
}
}
color.a *= layer.opacity;
return color;
Expand Down

0 comments on commit 1a4f44d

Please sign in to comment.