Skip to content

Commit fcd75df

Browse files
committed
Separate out paint layer
1 parent ce1587c commit fcd75df

File tree

4 files changed

+103
-102
lines changed

4 files changed

+103
-102
lines changed

src/layers/NumericDataLayer/index.tsx

Lines changed: 2 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,15 @@
11
import {
22
CompositeLayer,
3-
BitmapLayer,
43
Layer,
54
LayersList,
65
LayerContext,
76
GetPickingInfoParams,
87
} from "deck.gl";
98
import type { BitmapLayerPickingInfo } from "@deck.gl/layers";
10-
119
import type { Texture } from "@luma.gl/core";
12-
import type { ShaderModule } from "@luma.gl/shadertools";
13-
14-
import type {
15-
NumericDataPaintLayerProps,
16-
NumericDataLayerProps,
17-
NumericDataPickingInfo,
18-
} from "./types";
19-
20-
const uniformBlock = `\
21-
uniform wozUniforms {
22-
float min;
23-
float max;
24-
} woz;
25-
`;
26-
27-
export type WOZProps = {
28-
min: number;
29-
max: number;
30-
colormap_texture: Texture;
31-
};
32-
33-
const numericDataUniforms = {
34-
name: "woz",
35-
vs: uniformBlock,
36-
fs: uniformBlock,
37-
// @?: not float data?
38-
uniformTypes: {
39-
min: "f32",
40-
max: "f32",
41-
},
42-
} as const satisfies ShaderModule<WOZProps>;
43-
44-
const defaultProps = {
45-
...BitmapLayer.defaultProps,
46-
min: 0,
47-
max: 0,
48-
tileSize: 256,
49-
imageData: [],
50-
colormap_image: {
51-
type: "image",
52-
value: null,
53-
async: true,
54-
},
55-
};
56-
57-
export class NumericDataPaintLayer extends BitmapLayer<NumericDataPaintLayerProps> {
58-
static layerName = "numeric-paint-layer";
59-
static defaultProps = defaultProps;
6010

61-
initializeState() {
62-
super.initializeState();
63-
}
64-
65-
getShaders() {
66-
return {
67-
...super.getShaders(),
68-
inject: {
69-
"fs:#decl": `
70-
uniform sampler2D colormap_texture; // texture is not included in ubo
71-
`,
72-
"fs:DECKGL_FILTER_COLOR": `
73-
float value = color.r;
74-
vec3 pickingval = vec3(value, 0., 0.);
75-
if (isnan(value)) {
76-
discard;
77-
} else {
78-
float normalized = (value - woz.min)/(woz.max - woz.min);
79-
vec4 color_val = texture(colormap_texture, vec2(normalized, 0.));
80-
color = color_val;
81-
}
82-
`,
83-
},
84-
modules: [...super.getShaders().modules, numericDataUniforms],
85-
};
86-
}
87-
88-
// @ts-expect-error no opts type available
89-
draw(opts) {
90-
const { colormap_image, min, max } = this.props;
91-
const sModels = super.getModels();
92-
if (colormap_image)
93-
for (const m of sModels) {
94-
m.shaderInputs.setProps({
95-
woz: {
96-
colormap_texture: colormap_image,
97-
min,
98-
max,
99-
},
100-
});
101-
}
102-
super.draw({ ...opts });
103-
}
104-
}
11+
import { NumericDataPaintLayer } from "../NumericDataPaintLayer";
12+
import type { NumericDataLayerProps, NumericDataPickingInfo } from "./types";
10513

10614
export default class NumericDataLayer extends CompositeLayer<NumericDataLayerProps> {
10715
static layerName: string = "numeric-data-layer";

src/layers/NumericDataLayer/types.d.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
import type { BitmapLayerProps } from "deck.gl";
1+
import type { NumericDataPaintLayerProps } from "../NumericDataPaintLayer/types";
22
import type { BitmapLayerPickingInfo } from "@deck.gl/layers";
33
import type { TypedArray, NumberDataType } from "zarrita";
44

5-
export interface NumericDataPaintLayerProps extends BitmapLayerProps {
6-
colormap_image: string | Texture;
7-
min: number;
8-
max: number;
9-
tileSize: number;
10-
}
11-
125
export interface NumericDataLayerProps extends NumericDataPaintLayerProps {
136
imageData: TypedArray<NumberDataType>;
147
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { BitmapLayer } from "deck.gl";
2+
3+
import type { Texture } from "@luma.gl/core";
4+
import type { ShaderModule } from "@luma.gl/shadertools";
5+
6+
import type { NumericDataPaintLayerProps } from "./types";
7+
8+
const uniformBlock = `\
9+
uniform ndUniforms {
10+
float min;
11+
float max;
12+
} nd;
13+
`;
14+
15+
export type NDProps = {
16+
min: number;
17+
max: number;
18+
colormap_texture: Texture;
19+
};
20+
21+
const numericDataUniforms = {
22+
name: "nd",
23+
vs: uniformBlock,
24+
fs: uniformBlock,
25+
// @?: not float data?
26+
uniformTypes: {
27+
min: "f32",
28+
max: "f32",
29+
},
30+
} as const satisfies ShaderModule<NDProps>;
31+
32+
const defaultProps = {
33+
...BitmapLayer.defaultProps,
34+
min: 0,
35+
max: 0,
36+
tileSize: 256,
37+
imageData: [],
38+
colormap_image: {
39+
type: "image",
40+
value: null,
41+
async: true,
42+
},
43+
};
44+
45+
export class NumericDataPaintLayer extends BitmapLayer<NumericDataPaintLayerProps> {
46+
static layerName = "numeric-paint-layer";
47+
static defaultProps = defaultProps;
48+
49+
initializeState() {
50+
super.initializeState();
51+
}
52+
53+
getShaders() {
54+
return {
55+
...super.getShaders(),
56+
inject: {
57+
"fs:#decl": `
58+
uniform sampler2D colormap_texture; // texture is not included in ubo
59+
`,
60+
"fs:DECKGL_FILTER_COLOR": `
61+
float value = color.r;
62+
vec3 pickingval = vec3(value, 0., 0.);
63+
if (isnan(value)) {
64+
discard;
65+
} else {
66+
float normalized = (value - nd.min)/(nd.max - nd.min);
67+
vec4 color_val = texture(colormap_texture, vec2(normalized, 0.));
68+
color = color_val;
69+
}
70+
`,
71+
},
72+
modules: [...super.getShaders().modules, numericDataUniforms],
73+
};
74+
}
75+
76+
// @ts-expect-error no opts type available
77+
draw(opts) {
78+
const { colormap_image, min, max } = this.props;
79+
const sModels = super.getModels();
80+
if (colormap_image)
81+
for (const m of sModels) {
82+
m.shaderInputs.setProps({
83+
nd: {
84+
colormap_texture: colormap_image,
85+
min,
86+
max,
87+
},
88+
});
89+
}
90+
super.draw({ ...opts });
91+
}
92+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { BitmapLayerProps } from "deck.gl";
2+
3+
export interface NumericDataPaintLayerProps extends BitmapLayerProps {
4+
colormap_image: string | Texture;
5+
min: number;
6+
max: number;
7+
tileSize: number;
8+
}

0 commit comments

Comments
 (0)