Skip to content

Commit

Permalink
fix: [NGRM] - Strange artefacts in 2D maps equinor#2134 (equinor#2135)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilscb authored Jul 8, 2024
1 parent a2390e2 commit 0446493
Show file tree
Hide file tree
Showing 23 changed files with 69 additions and 10 deletions.
Binary file added example-data/ArtefactsMap/points.bin
Binary file not shown.
Binary file added example-data/ArtefactsMap/properties.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,33 @@ precision highp float;
in vec3 cameraPosition;
in vec4 position_commonspace;
in float property;
flat in float property;
in float property_interpolated;
flat in vec3 normal;
flat in int vertexIndex;
uniform sampler2D colormap;
uniform float valueRangeMin;
uniform float valueRangeMax;
uniform float colorMapRangeMin;
uniform float colorMapRangeMax;
uniform bool isColoringDiscrete;
uniform float colorMapSize;
uniform highp int coloringMode;
uniform vec3 colorMapClampColor;
uniform bool isClampColor;
uniform bool isColorMapClampColorTransparent;
// Calculate color from propertyValue using continuous colormap.
vec4 getContinuousPropertyColor (float propertyValue) {
vec4 color = vec4(1.0, 1.0, 1.0, 1.0);
float x = (propertyValue - colorMapRangeMin) / (colorMapRangeMax - colorMapRangeMin);
if (x < 0.0 - 1e-4 || x > 1.0 + 1e-4) {
if (x < 0.0 || x > 1.0) {
// Out of range. Use clampcolor.
if (isClampColor) {
color = vec4(colorMapClampColor.rgb, 1.0);
Expand All @@ -53,7 +57,7 @@ vec4 getDiscretePropertyColor (float propertyValue) {
vec4 color = vec4(1.0, 1.0, 1.0, 1.0);
float tolerance = (1.0 / colorMapSize) * 0.5;
if (propertyValue < colorMapRangeMin - tolerance || propertyValue > colorMapRangeMax + tolerance) {
// Out of range. Use clampcolor.
if (isClampColor) {
Expand Down Expand Up @@ -90,8 +94,12 @@ void main(void) {
gl_FragColor = encodeVertexIndexToRGB(vertexIndex);
return;
}
vec4 color = getPropertyColor(property);
// Property values other than X,Y or Z are passed as "flat" i.e. constant over faces.
float propertyValue = coloringMode == 0 ? property : property_interpolated;
propertyValue = clamp(propertyValue, valueRangeMin, valueRangeMax);
vec4 color = getPropertyColor(propertyValue);
// Use two sided phong lighting. This has no effect if "material" property is not set.
vec3 lightColor = getPhongLightColor(color.rgb, cameraPosition, position_commonspace.xyz, normal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ const defaultProps = {

interface IPropertyUniforms {
colormap: Texture2D;
valueRangeMin: number;
valueRangeMax: number;
colorMapRangeMin: number;
colorMapRangeMax: number;
colorMapClampColor: Color | undefined | boolean | number[];
Expand Down Expand Up @@ -362,6 +364,8 @@ export default class PrivateLayer extends Layer<PrivateLayerProps> {

return {
colormap,
valueRangeMin,
valueRangeMax,
colorMapRangeMin,
colorMapRangeMax,
colorMapClampColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ uniform int coloringMode;
// Outputs to fragment shader
out vec3 cameraPosition;
out vec4 position_commonspace;
out float property;
flat out float property;
out float property_interpolated;
flat out vec3 normal;
flat out int vertexIndex;
Expand All @@ -37,9 +38,9 @@ void main(void) {
switch(coloringMode) {
case 0: property = properties; break;
case 1: property = position.x; break;
case 2: property = position.y; break;
case 3: property = position.z; break;
case 1: property_interpolated = position.x; break;
case 2: property_interpolated = position.y; break;
case 3: property_interpolated = position.z; break;
default: property = properties; break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ void main(void) {
vec4 color = vec4(1.0, 1.0, 1.0, 1.0);;
float propertyValue = property;
// This may happen due to GPU interpolation precision causing color artifacts.
propertyValue = clamp(propertyValue, valueRangeMin, valueRangeMax);
float x = (propertyValue - colorMapRangeMin) / (colorMapRangeMax - colorMapRangeMin);
if (x < 0.0 || x > 1.0) {
// Out of range. Use clampcolor.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ const smallLayer = {
colorMapClampColor: [255, 0, 0],
};

const artefactsMapLayer = {
"@@type": "MapLayer",
id: "artefacts-map-layer",
meshData: "ArtefactsMap/points.bin",
frame: {
origin: [1134, 9317.966796875],
count: [81, 92],
increment: [101.04595712679287, -100.58940471369598],

rotDeg: 0.10652954894901544,
},
propertiesData: "ArtefactsMap/properties.bin",
gridLines: false,
material: false,
// black to white colors.
colorMapFunction: [0, 0, 0],
colorMapRange: [-0.01, 33], // actual range is [0, 34.764503479003906]
colorMapClampColor: [0, 255, 0],
};

// This layer has as many property values as depth values hence each cell will be interpolated in color.
const nodeCenteredPropertiesLayer = {
"@@type": "MapLayer",
Expand Down Expand Up @@ -322,6 +342,12 @@ const axes_small = {
bounds: [459790, 5929776, 0, 460590, 5930626, 30],
};

const axes_artefact_map = {
"@@type": "AxesLayer",
id: "axes_artefact_map",
bounds: [0, 0, 0, 10000, 10000, 30],
};

export const SmallMap: StoryObj<typeof SubsurfaceViewer> = {
args: {
id: "map",
Expand All @@ -339,6 +365,23 @@ export const SmallMap: StoryObj<typeof SubsurfaceViewer> = {
},
};

export const MapWithArtefacts: StoryObj<typeof SubsurfaceViewer> = {
args: {
id: "artefacts-map",
layers: [axes_artefact_map, artefactsMapLayer],
bounds: [0, 0, 10000, 10000] as BoundingBox2D,
views: default3DViews,
},
parameters: {
docs: {
...defaultStoryParameters.docs,
description: {
story: "Map with color artefacts.",
},
},
},
};

const axes_lite = {
"@@type": "AxesLayer",
id: "axes_small",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0446493

Please sign in to comment.