Skip to content
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

fix: [NGRM] - Strange artefacts in 2D maps #2134 #2135

Merged
merged 20 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
w1nklr marked this conversation as resolved.
Show resolved Hide resolved

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;
w1nklr marked this conversation as resolved.
Show resolved Hide resolved

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.
w1nklr marked this conversation as resolved.
Show resolved Hide resolved
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.
Loading