@playcanvas/inspector 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +110 -0
  3. package/package.json +62 -0
  4. package/src/asset-usage.js +108 -0
  5. package/src/asset-view.js +370 -0
  6. package/src/camera-view.js +128 -0
  7. package/src/debug.js +31 -0
  8. package/src/describe.js +302 -0
  9. package/src/entity-inspector-script.js +130 -0
  10. package/src/frame-graph-view.js +767 -0
  11. package/src/hierarchy-view.js +475 -0
  12. package/src/index.js +4 -0
  13. package/src/input/fly-controller.js +116 -0
  14. package/src/input/input.js +299 -0
  15. package/src/input/math.js +8 -0
  16. package/src/input/orbit-controller.js +158 -0
  17. package/src/input/pose.js +207 -0
  18. package/src/inspector.js +3293 -0
  19. package/src/instance-survey.js +50 -0
  20. package/src/list-view.js +410 -0
  21. package/src/material-view.js +197 -0
  22. package/src/memory-view.js +344 -0
  23. package/src/mesh-view.js +235 -0
  24. package/src/model.js +170 -0
  25. package/src/node-model.js +404 -0
  26. package/src/physics-debug.js +527 -0
  27. package/src/physics-view.js +314 -0
  28. package/src/picker/picker.js +545 -0
  29. package/src/picker/render-pass-picker.js +206 -0
  30. package/src/property-view.js +628 -0
  31. package/src/render-target-view.js +288 -0
  32. package/src/renderers/texture-renderer-shaders.js +139 -0
  33. package/src/renderers/texture-renderer.js +430 -0
  34. package/src/renderers/wire-renderer.js +954 -0
  35. package/src/script-view.js +288 -0
  36. package/src/shader-view.js +287 -0
  37. package/src/styles.js +918 -0
  38. package/src/texture-view.js +186 -0
  39. package/src/tooltip.js +72 -0
  40. package/src/viewport-tools.js +695 -0
  41. package/types/asset-usage.d.ts +23 -0
  42. package/types/asset-view.d.ts +94 -0
  43. package/types/camera-view.d.ts +45 -0
  44. package/types/debug.d.ts +14 -0
  45. package/types/describe.d.ts +43 -0
  46. package/types/entity-inspector-script.d.ts +87 -0
  47. package/types/frame-graph-view.d.ts +155 -0
  48. package/types/hierarchy-view.d.ts +172 -0
  49. package/types/index.d.ts +3 -0
  50. package/types/input/fly-controller.d.ts +42 -0
  51. package/types/input/input.d.ts +192 -0
  52. package/types/input/math.d.ts +1 -0
  53. package/types/input/orbit-controller.d.ts +63 -0
  54. package/types/input/pose.d.ts +126 -0
  55. package/types/inspector.d.ts +1304 -0
  56. package/types/instance-survey.d.ts +35 -0
  57. package/types/list-view.d.ts +151 -0
  58. package/types/material-view.d.ts +63 -0
  59. package/types/memory-view.d.ts +95 -0
  60. package/types/mesh-view.d.ts +89 -0
  61. package/types/model.d.ts +104 -0
  62. package/types/node-model.d.ts +54 -0
  63. package/types/physics-debug.d.ts +254 -0
  64. package/types/physics-view.d.ts +81 -0
  65. package/types/picker/picker.d.ts +255 -0
  66. package/types/picker/render-pass-picker.d.ts +47 -0
  67. package/types/property-view.d.ts +189 -0
  68. package/types/render-target-view.d.ts +98 -0
  69. package/types/renderers/texture-renderer-shaders.d.ts +9 -0
  70. package/types/renderers/texture-renderer.d.ts +231 -0
  71. package/types/renderers/wire-renderer.d.ts +347 -0
  72. package/types/script-view.d.ts +56 -0
  73. package/types/shader-view.d.ts +46 -0
  74. package/types/styles.d.ts +22 -0
  75. package/types/texture-view.d.ts +30 -0
  76. package/types/tooltip.d.ts +17 -0
  77. package/types/viewport-tools.d.ts +237 -0
@@ -0,0 +1,288 @@
1
+ import {
2
+ FILTER_NEAREST, FILTER_NEAREST_MIPMAP_LINEAR, FILTER_NEAREST_MIPMAP_NEAREST, isIntegerPixelFormat, PIXELFORMAT_DEPTH, PIXELFORMAT_DEPTH16, PIXELFORMAT_DEPTHSTENCIL, PIXELFORMAT_R32F, PIXELFORMAT_RG32F, PIXELFORMAT_RGB32F, PIXELFORMAT_RGBA32F, pixelFormatInfo, RENDERTARGET_ORIGIN_BOTTOM, RENDERTARGET_ORIGIN_NATIVE
3
+ } from 'playcanvas';
4
+
5
+ import { describeValue } from './describe.js';
6
+ import { attachmentsText, formatName, makeSection, passDisplayName, push, read, reflectRows } from './model.js';
7
+
8
+ /** @import { GraphicsDevice } from 'playcanvas' */
9
+ /** @import { RenderTarget } from 'playcanvas' */
10
+ /** @import { Texture } from 'playcanvas' */
11
+ /** @import { FrameSnapshot } from './frame-graph-view.js' */
12
+ /** @import { ListRow } from './list-view.js' */
13
+ /** @import { PropertySection } from './model.js' */
14
+
15
+ // render target properties the model shows explicitly, or that are plumbing
16
+ const SKIP_TARGET = [
17
+ 'name', 'width', 'height', 'samples', 'depth', 'stencil', 'flipY', 'mipLevel', 'face', 'initialized',
18
+ 'colorBuffer', 'colorBufferCount', 'resolveBuffer', 'depthBuffer', 'depthResolveBuffer', 'device', 'impl'
19
+ ];
20
+
21
+ /** @type {WeakMap<RenderTarget, number>} */
22
+ const ids = new WeakMap();
23
+ let nextId = 1;
24
+
25
+ /**
26
+ * @param {RenderTarget} rt - A render target.
27
+ * @returns {string} A row key that stays the same for the lifetime of the object.
28
+ */
29
+ function keyOf(rt) {
30
+ let id = ids.get(rt);
31
+ if (id === undefined) {
32
+ id = nextId++;
33
+ ids.set(rt, id);
34
+ }
35
+ return `rt${id}`;
36
+ }
37
+
38
+ /**
39
+ * @param {RenderTarget} rt - A render target.
40
+ * @param {GraphicsDevice} device - The device.
41
+ * @returns {string} The display name.
42
+ */
43
+ function targetName(rt, device) {
44
+ return rt === device.backBuffer ? 'Backbuffer' : (rt.name || '(unnamed)');
45
+ }
46
+
47
+ /**
48
+ * Every render target alive on the device, backbuffer first. The device keeps a registry of the
49
+ * targets created on it, so this covers targets no pass used this frame too.
50
+ *
51
+ * @param {GraphicsDevice} device - The device.
52
+ * @returns {RenderTarget[]} The targets.
53
+ */
54
+ function collectRenderTargets(device) {
55
+ const list = [];
56
+ if (device.backBuffer) list.push(device.backBuffer);
57
+ for (const rt of device.targets ?? []) {
58
+ if (rt !== device.backBuffer) list.push(rt);
59
+ }
60
+ return list;
61
+ }
62
+
63
+ /**
64
+ * @param {string} label - The attachment label.
65
+ * @param {Texture} texture - The attached texture.
66
+ * @returns {string} One line describing the attachment.
67
+ */
68
+ function textureLine(label, texture) {
69
+ return `${label}: "${texture.name}" ${formatName(texture.format)} ${texture.width}×${texture.height}`;
70
+ }
71
+
72
+ /**
73
+ * @param {RenderTarget} rt - A render target.
74
+ * @param {GraphicsDevice} device - The device.
75
+ * @returns {string} A multi-line tooltip listing the attachments with their formats.
76
+ */
77
+ function targetTitle(rt, device) {
78
+ const lines = [`${targetName(rt, device)} ${rt.width}×${rt.height}${rt.samples > 1 ? ` ×${rt.samples} samples` : ''}`];
79
+
80
+ if (rt === device.backBuffer) {
81
+ lines.push(`color: swapchain ${formatName(device.backBufferFormat)}`);
82
+ }
83
+ const count = rt.colorBufferCount ?? 0;
84
+ for (let i = 0; i < count; i++) {
85
+ const texture = rt.getColorBuffer(i);
86
+ if (texture) lines.push(textureLine(`color[${i}]`, texture));
87
+ }
88
+ if (rt.depthBuffer) {
89
+ lines.push(textureLine('depth', rt.depthBuffer));
90
+ } else if (rt.depth) {
91
+ lines.push(`depth: internal${rt.stencil ? ' + stencil' : ''}`);
92
+ }
93
+ if (rt.mipLevel > 0) lines.push(`mip level ${rt.mipLevel}`);
94
+
95
+ return lines.join('\n');
96
+ }
97
+
98
+ /**
99
+ * One row per render target on the device, dimmed when no pass of the captured frame used it.
100
+ *
101
+ * @param {GraphicsDevice} device - The device.
102
+ * @param {FrameSnapshot|null} frame - The captured frame, for usage counts.
103
+ * @returns {ListRow[]} The rows.
104
+ */
105
+ function renderTargetRows(device, frame) {
106
+ return collectRenderTargets(device).map((rt) => {
107
+ const name = targetName(rt, device);
108
+ const uses = frame?.usage.get(rt)?.length ?? 0;
109
+
110
+ const cells = [{ text: name, cls: 'pci-cell-name' }];
111
+ if (rt === device.backBuffer) cells.push({ text: 'backbuffer', cls: 'pci-cell-tag pci-cell-tag-info' });
112
+ cells.push({ text: `${rt.width}×${rt.height} ${attachmentsText(rt, device)}${rt.samples > 1 ? ` ×${rt.samples}` : ''}`, cls: 'pci-cell-info' });
113
+ cells.push({ text: uses ? `${uses} pass${uses === 1 ? '' : 'es'}` : 'unused this frame', cls: 'pci-cell-info pci-cell-right' });
114
+
115
+ return { key: keyOf(rt), item: rt, name, dim: uses === 0, title: targetTitle(rt, device), cells };
116
+ });
117
+ }
118
+
119
+ /**
120
+ * Everything the property view shows for a render target: its setup, the passes that rendered
121
+ * into it this frame (linked), its attachments, and every other public property.
122
+ *
123
+ * @param {RenderTarget} rt - The render target.
124
+ * @param {{ device: GraphicsDevice, frame: FrameSnapshot|null }} ctx - The device and the captured frame.
125
+ * @returns {PropertySection[]} The sections.
126
+ */
127
+ function buildRenderTargetModel(rt, ctx) {
128
+ const { device, frame } = ctx;
129
+ const back = rt === device.backBuffer;
130
+ const sections = [];
131
+
132
+ const general = makeSection('target', back ? 'Backbuffer' : 'Render target');
133
+ push(general, 'name', describeValue(rt.name));
134
+ push(general, 'size', { text: `${rt.width} × ${rt.height}`, cls: 'num' });
135
+ push(general, 'samples', read(rt, 'samples'));
136
+ push(general, 'depth', read(rt, 'depth'));
137
+ push(general, 'stencil', read(rt, 'stencil'));
138
+ push(general, 'flip y', read(rt, 'flipY'));
139
+ push(general, 'mip level', read(rt, 'mipLevel'));
140
+ push(general, 'face', read(rt, 'face'));
141
+ push(general, 'initialized', read(rt, 'initialized'));
142
+
143
+ const uses = frame?.usage.get(rt) ?? [];
144
+ push(general, 'used by', {
145
+ text: uses.length ? `${uses.length} pass${uses.length === 1 ? '' : 'es'} this frame` : 'no pass this frame',
146
+ cls: uses.length ? 'obj' : 'null',
147
+ items: uses.map(entry => ({ label: `#${entry.index}`, text: passDisplayName(entry.pass), cls: 'ref', target: entry.pass }))
148
+ });
149
+ sections.push(general);
150
+
151
+ const attachments = makeSection('attachments', 'Attachments');
152
+ if (back) push(attachments, 'color', { text: `swapchain ${formatName(device.backBufferFormat)}`, cls: 'obj' });
153
+ const count = rt.colorBufferCount ?? 0;
154
+ for (let i = 0; i < count; i++) {
155
+ push(attachments, `color ${i}`, describeValue(rt.getColorBuffer(i)));
156
+ }
157
+ if (rt.resolveBuffer) push(attachments, 'resolve buffer', describeValue(rt.resolveBuffer));
158
+ if (rt.depthBuffer) {
159
+ push(attachments, 'depth buffer', describeValue(rt.depthBuffer));
160
+ } else if (rt.depth) {
161
+ push(attachments, 'depth buffer', { text: `internal depth${rt.stencil ? ' + stencil' : ''}`, cls: 'obj' });
162
+ }
163
+ if (rt.depthResolveBuffer) push(attachments, 'depth resolve buffer', describeValue(rt.depthResolveBuffer));
164
+ if (attachments.rows.length) sections.push(attachments);
165
+
166
+ const rest = makeSection('props', 'Properties');
167
+ reflectRows(rest, rt, [], SKIP_TARGET);
168
+ if (rest.rows.length) sections.push(rest);
169
+
170
+ return sections;
171
+ }
172
+
173
+ /**
174
+ * A texture of a render target that the preview can sample.
175
+ *
176
+ * @typedef {object} PreviewAttachment
177
+ * @property {string} key - 'color0', 'color1' and so on, or 'depth'.
178
+ * @property {string} label - The label shown in the attachment selector.
179
+ * @property {Texture} texture - The texture to sample.
180
+ * @ignore
181
+ */
182
+
183
+ /**
184
+ * The textures of a render target a preview can sample: each color attachment, using the resolve
185
+ * texture of the first when the target keeps explicit multisampled color buffers, and the depth
186
+ * buffer when it is a texture. The backbuffer has none: it is the screen itself.
187
+ *
188
+ * @param {RenderTarget} rt - The render target.
189
+ * @param {GraphicsDevice} device - The device.
190
+ * @returns {PreviewAttachment[]} The attachments, in selector order.
191
+ */
192
+ function previewAttachments(rt, device) {
193
+ /** @type {PreviewAttachment[]} */
194
+ const attachments = [];
195
+ if (rt === device.backBuffer) return attachments;
196
+
197
+ const count = rt.colorBufferCount ?? 0;
198
+ for (let i = 0; i < count; i++) {
199
+ const texture = (i === 0 && rt.resolveBuffer) || rt.getColorBuffer(i);
200
+ if (texture) attachments.push({ key: `color${i}`, label: count > 1 ? `color ${i}` : 'color', texture });
201
+ }
202
+ if (rt.depthBuffer) attachments.push({ key: 'depth', label: 'depth', texture: rt.depthBuffer });
203
+ return attachments;
204
+ }
205
+
206
+ /**
207
+ * Whether a texture holds its rows bottom-up, as a render target with the bottom origin stores
208
+ * them, or with the native origin on WebGL2. The texture renderer shows row 0 at the top, so such
209
+ * a preview needs flipping to appear upright.
210
+ *
211
+ * @param {Texture} texture - The texture.
212
+ * @param {GraphicsDevice} device - The device.
213
+ * @param {RenderTarget|null} [rt] - The render target it is attached to. Looked up on the device
214
+ * when not given.
215
+ * @returns {boolean} Whether it is stored bottom-up.
216
+ */
217
+ function storedBottomUp(texture, device, rt) {
218
+ rt ??= [...(device.targets ?? [])].find(target => target.depthBuffer === texture ||
219
+ target.depthResolveBuffer === texture ||
220
+ Array.from({ length: target.colorBufferCount ?? 0 }, (_, i) => i)
221
+ .some(i => target.getColorBuffer(i) === texture || target.getResolveBuffer?.(i) === texture)) ?? null;
222
+ if (!rt) return false;
223
+ return rt.origin === RENDERTARGET_ORIGIN_BOTTOM || (rt.origin === RENDERTARGET_ORIGIN_NATIVE && device.isWebGL2);
224
+ }
225
+
226
+ /**
227
+ * @param {number} format - A PIXELFORMAT_* constant.
228
+ * @returns {boolean} Whether it is one of the depth formats, which preview as raw grayscale.
229
+ */
230
+ function isDepthFormat(format) {
231
+ return format === PIXELFORMAT_DEPTH || format === PIXELFORMAT_DEPTH16 || format === PIXELFORMAT_DEPTHSTENCIL;
232
+ }
233
+
234
+ /**
235
+ * Mirrors the checks TextureRenderer applies before drawing, so the panel can say why a texture
236
+ * cannot be shown instead of letting the renderer warn once and draw nothing.
237
+ *
238
+ * @param {Texture|null} texture - The texture.
239
+ * @param {GraphicsDevice} device - The device.
240
+ * @returns {{ ok: boolean, reason: string }} Whether it can be previewed, and if not, why.
241
+ */
242
+ function previewSupport(texture, device) {
243
+ if (!texture) return { ok: false, reason: 'no texture to sample' };
244
+ if (texture.cubemap) return { ok: false, reason: 'cube textures cannot be previewed' };
245
+ if (texture.volume) return { ok: false, reason: 'volume textures cannot be previewed' };
246
+ if (texture.arrayLength) return { ok: false, reason: 'texture arrays cannot be previewed' };
247
+ if (texture.samples > 1) return { ok: false, reason: 'multisampled textures cannot be previewed' };
248
+
249
+ const format = texture.format;
250
+ if (isIntegerPixelFormat(format)) return { ok: false, reason: 'integer formats cannot be previewed' };
251
+
252
+ const depth = isDepthFormat(format);
253
+ if (depth && device.isWebGL2 && texture.compareOnRead) {
254
+ return { ok: false, reason: 'comparison depth textures cannot be previewed on WebGL2' };
255
+ }
256
+
257
+ const unfilterable = !device.textureFloatFilterable &&
258
+ (format === PIXELFORMAT_R32F || format === PIXELFORMAT_RG32F || format === PIXELFORMAT_RGB32F || format === PIXELFORMAT_RGBA32F);
259
+ if (device.isWebGL2 && (depth || unfilterable)) {
260
+ const minFilter = texture.minFilter;
261
+ const nearestMin = minFilter === FILTER_NEAREST || minFilter === FILTER_NEAREST_MIPMAP_NEAREST ||
262
+ (!texture.mipmaps && minFilter === FILTER_NEAREST_MIPMAP_LINEAR);
263
+ if (!nearestMin || texture.magFilter !== FILTER_NEAREST) {
264
+ return { ok: false, reason: `${depth ? 'depth' : 'float'} textures need nearest filtering to preview on WebGL2` };
265
+ }
266
+ }
267
+
268
+ return { ok: true, reason: '' };
269
+ }
270
+
271
+ /**
272
+ * The r, g, b and a channels an uncompressed color format stores, read from its name: R8 stores
273
+ * 'r', RG16F 'rg', SRGB8 'rgb', BGRA8 and RGB10A2 'rgba'. Sampling a channel the format lacks
274
+ * returns a constant (0, or 1 for alpha), so a preview of it shows nothing. Empty when the name
275
+ * carries no channel letters: depth, the packed 111110F and compressed formats.
276
+ *
277
+ * @param {number} format - A PIXELFORMAT_* constant.
278
+ * @returns {string} The stored channels as lower-case letters from 'rgba', or ''.
279
+ */
280
+ function formatChannels(format) {
281
+ const name = pixelFormatInfo.get(format)?.name ?? '';
282
+ const match = /^S?([RGBA]+)(?:\d+(A)\d)?/.exec(name);
283
+ if (!match) return '';
284
+ const letters = (match[1] + (match[2] ?? '')).toLowerCase();
285
+ return [...'rgba'].filter(letter => letters.includes(letter)).join('');
286
+ }
287
+
288
+ export { buildRenderTargetModel, formatChannels, isDepthFormat, previewAttachments, previewSupport, renderTargetRows, storedBottomUp };
@@ -0,0 +1,139 @@
1
+ import { ChunkUtils, SEMANTIC_POSITION } from 'playcanvas';
2
+
3
+ /**
4
+ * @import { ShaderDesc } from 'playcanvas'
5
+ */
6
+
7
+ const vertexGLSL = /* glsl */ `
8
+ attribute vec2 vertex_position;
9
+ uniform mat4 matrix_model;
10
+ uniform float projectionFlipY;
11
+ varying vec2 uv0;
12
+ void main(void) {
13
+ gl_Position = matrix_model * vec4(vertex_position, 0.0, 1.0);
14
+ gl_Position.y *= projectionFlipY;
15
+ uv0 = vertex_position + 0.5;
16
+ }
17
+ `;
18
+
19
+ const vertexWGSL = /* wgsl */ `
20
+ attribute vertex_position: vec2f;
21
+ uniform matrix_model: mat4x4f;
22
+ uniform projectionFlipY: f32;
23
+ varying uv0: vec2f;
24
+ @vertex fn vertexMain(input: VertexInput) -> VertexOutput {
25
+ var output: VertexOutput;
26
+ output.position = uniform.matrix_model * vec4f(input.vertex_position, 0.0, 1.0);
27
+ output.position.y *= uniform.projectionFlipY;
28
+ output.uv0 = input.vertex_position + vec2f(0.5);
29
+ return output;
30
+ }
31
+ `;
32
+
33
+ /**
34
+ * Builds shaders for one debug texture sampling mode.
35
+ *
36
+ * @param {string} mode - Filtered color, unfilterable color, raw depth, or scene depth.
37
+ * @param {string} encoding - The source texture's encoding.
38
+ * @returns {ShaderDesc} Shader description.
39
+ * @ignore
40
+ */
41
+ const createTextureShaderDesc = (mode, encoding) => {
42
+ let fragmentGLSL;
43
+ let fragmentWGSL;
44
+ if (mode === 'scene-depth') {
45
+ // Preview UVs start at the top. Scene depth follows the camera target's orientation,
46
+ // including its projection flip and the graphics backend's native texture origin.
47
+ fragmentGLSL = /* glsl */ `
48
+ #include "screenDepthPS"
49
+ #include "gammaPS"
50
+ varying vec2 uv0;
51
+ uniform float projectionFlipY;
52
+ void main(void) {
53
+ vec2 uv = vec2(uv0.x, 0.5 - (uv0.y - 0.5) * projectionFlipY);
54
+ float depth = getLinearScreenDepth(getImageEffectUV(uv)) * camera_params.x;
55
+ gl_FragColor = vec4(gammaCorrectOutput(vec3(depth)), 1.0);
56
+ }
57
+ `;
58
+ fragmentWGSL = /* wgsl */ `
59
+ #include "screenDepthPS"
60
+ #include "gammaPS"
61
+ varying uv0: vec2f;
62
+ uniform projectionFlipY: f32;
63
+ @fragment fn fragmentMain(input: FragmentInput) -> FragmentOutput {
64
+ var output: FragmentOutput;
65
+ let uv = vec2f(input.uv0.x, 0.5 - (input.uv0.y - 0.5) * uniform.projectionFlipY);
66
+ let depth = getLinearScreenDepth(getImageEffectUV(uv)) * uniform.camera_params.x;
67
+ output.color = vec4f(gammaCorrectOutput(vec3f(depth)), 1.0);
68
+ return output;
69
+ }
70
+ `;
71
+ } else {
72
+ const depth = mode === 'depth';
73
+ const filtered = mode === 'filtered';
74
+ const decode = ChunkUtils.decodeFunc(encoding);
75
+ const raw = encoding === 'raw' || encoding === 'raw-srgb';
76
+ const srgb = encoding === 'raw-srgb';
77
+ // Hardware sampling decodes sRGB RGB channels. Undo that conversion before inspecting
78
+ // stored values; alpha is unaffected. HDR encodings are deliberately not decoded here.
79
+ fragmentGLSL = /* glsl */ `
80
+ #include "gammaPS"
81
+ varying vec2 uv0;
82
+ uniform highp sampler2D colorMap;
83
+ ${raw ? 'uniform ivec3 textureChannels;' : ''}
84
+ void main(void) {
85
+ ${filtered ? 'vec4 sampleColor = texture2D(colorMap, uv0);' : `
86
+ ivec2 size = textureSize(colorMap, 0);
87
+ ivec2 uv = clamp(ivec2(uv0 * vec2(size)), ivec2(0), size - 1);
88
+ vec4 sampleColor = texelFetch(colorMap, uv, 0);
89
+ `}
90
+ ${depth ? 'gl_FragColor = vec4(vec3(sampleColor.r), 1.0);' : raw ? `
91
+ ${srgb ? `
92
+ sampleColor.rgb = mix(1.055 * pow(sampleColor.rgb, vec3(1.0 / 2.4)) - 0.055,
93
+ sampleColor.rgb * 12.92, lessThanEqual(sampleColor.rgb, vec3(0.0031308)));
94
+ ` : ''}
95
+ gl_FragColor = vec4(sampleColor[textureChannels.x], sampleColor[textureChannels.y], sampleColor[textureChannels.z], 1.0);
96
+ ` : `
97
+ gl_FragColor = vec4(gammaCorrectOutput(${decode}(sampleColor)), 1.0);
98
+ `}
99
+ }
100
+ `;
101
+ fragmentWGSL = /* wgsl */ `
102
+ #include "gammaPS"
103
+ varying uv0: vec2f;
104
+ var colorMap: ${depth ? 'texture_depth_2d' : filtered ? 'texture_2d<f32>' : 'texture_2d<uff>'};
105
+ ${filtered ? 'var colorMapSampler: sampler;' : ''}
106
+ ${raw ? 'uniform textureChannels: vec3i;' : ''}
107
+ @fragment fn fragmentMain(input: FragmentInput) -> FragmentOutput {
108
+ var output: FragmentOutput;
109
+ ${filtered ? 'let sampleColor = textureSample(colorMap, colorMapSampler, input.uv0);' : `
110
+ let size = vec2i(textureDimensions(colorMap, 0));
111
+ let uv = clamp(vec2i(input.uv0 * vec2f(size)), vec2i(0), size - vec2i(1));
112
+ let sampleColor = textureLoad(colorMap, uv, 0);
113
+ `}
114
+ ${depth ? 'output.color = vec4f(vec3f(sampleColor), 1.0);' : raw ? `
115
+ ${srgb ? `
116
+ let storedRgb = select(1.055 * pow(sampleColor.rgb, vec3f(1.0 / 2.4)) - vec3f(0.055),
117
+ sampleColor.rgb * 12.92, sampleColor.rgb <= vec3f(0.0031308));
118
+ let storedColor = vec4f(storedRgb, sampleColor.a);
119
+ ` : 'let storedColor = sampleColor;'}
120
+ output.color = vec4f(storedColor[uniform.textureChannels.x], storedColor[uniform.textureChannels.y], storedColor[uniform.textureChannels.z], 1.0);
121
+ ` : `
122
+ output.color = vec4f(gammaCorrectOutput(${decode}(sampleColor)), 1.0);
123
+ `}
124
+ return output;
125
+ }
126
+ `;
127
+ }
128
+
129
+ return {
130
+ uniqueName: `TextureRenderer-${mode}-${encoding}`,
131
+ attributes: { vertex_position: SEMANTIC_POSITION },
132
+ vertexGLSL,
133
+ vertexWGSL,
134
+ fragmentGLSL,
135
+ fragmentWGSL
136
+ };
137
+ };
138
+
139
+ export { createTextureShaderDesc };