Skip to content

Commit

Permalink
chore(shadertools): Remove glsl string template (#2091)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Apr 30, 2024
1 parent 24241da commit 30be1e2
Show file tree
Hide file tree
Showing 80 changed files with 196 additions and 275 deletions.
23 changes: 16 additions & 7 deletions docs/upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,27 @@ luma.gl largely follows [SEMVER](https://semver.org) conventions. Breaking chang

## Upgrading to v9.1

Some deprectations and minor breaking changes are necessary as WebGPU support is built out.

**@luma.gl/core**

- `RenderPipeline.topology`: `line-loop-webgl` and `triangle-fan-webgl` topologies are no longer supported. Rebuild your geometries using `triangle-strip` and `line-list`.
- New [`luma.registerAdapters()`](/docs/api-reference/core/luma#lumaregisteradapters) method - Now register adapters rather than devices.
- `Texture`: Textures no longer accept promises, use `AsyncTexture` class instead.
| Updated API | Status | Replacement |
| ------------------------------ | ---------- | -------------------------------------------------------------------------------------------- |
| `luma.registerDevices()` | Deprecated | Use [`luma.registerAdapters()`](/docs/api-reference/core/luma#lumaregisteradapters) instead. |
| `Texture.props.data` (Promise) | Changed | Textures no longer accept promises, use `AsyncTexture` class instead. |
| `triangle-fan-webgl` | Removed | Rebuild your geometries using `triangle-strip`. |
| `line-loop-webgl` | Removed | Rebuild your geometries`line-list`. |
| `glsl` template string | Removed | Enable syntax highlighting in vscode using `/* glsl */` comment instead |

**@luma.gl/shadertools**

- `ShaderModuleInstance` type has been removed. Use `ShaderModule` instead.
- `initializeShaderModule()` now store initialized information on the original shader module structure, and can be called multiple times.
- `moduleInstance.getUniforms()` is removed. Use `getShaderModuleUniforms(module, ...)` instead.
- `getDependencyGraph()` is private. Use `getShaderModuleDependencies(module)` instead.
| Updated API | Status | Replacement |
| ------------------------------------ | -------- | ----------------------------------------------------------------------- |
| `ShaderModuleInstance` | Removed | Type has been removed. Use `ShaderModule` instead. |
| `initializeShaderModule()` | Changed | Stores initialized information on the original shader module object. |
| `ShaderModuleInstance.getUniforms()` | Removed | Use `getShaderModuleUniforms(module, ...)` instead. |
| `getDependencyGraph()` | Removed | Use `getShaderModuleDependencies(module)` instead. |
| `glsl` template string | Removed | Enable syntax highlighting in vscode using `/* glsl */` comment instead |

## Upgrading to v9.0

Expand Down
6 changes: 1 addition & 5 deletions docs/whats-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ Target Date: Q2 2024

**@luma.gl/core**

| Updated API | Status | Replacement |
| ------------------------ | ---------- | -------------------------------------------------------------------------------------------- |
| `luma.registerDevices()` | Deprecated | Use [`luma.registerAdapters()`](/docs/api-reference/core/luma#lumaregisteradapters) instead. |
| `WebGLDevice.attach()` | Deprecated | Use [`luma.attachDevice()`](/docs/api-reference/core/luma#lumaattachdevice) instead . |
| `Texture` promise data | Removed | Use `AsyncTexture` class instead. |
- New [`luma.registerAdapters()`](/docs/api-reference/core/luma#lumaregisteradapters) method - Register adapters for WebGL and WebGPU.

**@luma.gl/engine**

Expand Down
6 changes: 3 additions & 3 deletions examples/api/animation/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {glsl, UniformStore, ShaderUniformType} from '@luma.gl/core';
import {UniformStore, ShaderUniformType} from '@luma.gl/core';
import {
AnimationLoopTemplate,
AnimationProps,
Expand Down Expand Up @@ -40,7 +40,7 @@ const app: {uniformTypes: Record<string, ShaderUniformType>} = {
}
};

const vs = glsl`\
const vs = /* glsl */ `\
#version 300 es
in vec3 positions;
Expand All @@ -65,7 +65,7 @@ void main(void) {
}
`;

const fs = glsl`\
const fs = /* glsl */ `\
#version 300 es
precision highp float;
Expand Down
10 changes: 5 additions & 5 deletions examples/api/cubemap/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Device, glsl} from '@luma.gl/core';
import {Device} from '@luma.gl/core';
import {
AnimationLoopTemplate,
AnimationProps,
Expand All @@ -21,7 +21,7 @@ surface

class RoomCube extends Model {
constructor(device: Device, props: Omit<ModelProps, 'vs' | 'fs'>) {
const vs = glsl`\
const vs = /* glsl */ `\
#version 300 es
in vec3 positions;
Expand All @@ -36,7 +36,7 @@ void main(void) {
vPosition = positions;
}
`;
const fs = glsl`\
const fs = /* glsl */ `\
#version 300 es
precision highp float;
Expand All @@ -56,7 +56,7 @@ void main(void) {

class Prism extends Model {
constructor(device: Device, props: Omit<ModelProps, 'vs' | 'fs'>) {
const vs = glsl`\
const vs = /* glsl */ `\
#version 300 es
in vec3 positions;
in vec3 normals;
Expand All @@ -77,7 +77,7 @@ void main(void) {
vUV = texCoords;
}
`;
const fs = glsl`\
const fs = /* glsl */ `\
#version 300 es
precision highp float;
Expand Down
5 changes: 2 additions & 3 deletions examples/api/texture-3d/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Ported from PicoGL.js example: https://tsherif.github.io/picogl.js/examples/3Dtexture.html

import {glsl} from '@luma.gl/core';
import type {AnimationProps} from '@luma.gl/engine';
import {AnimationLoopTemplate, Model, makeRandomGenerator} from '@luma.gl/engine';
import {Matrix4, radians} from '@math.gl/core';
Expand All @@ -15,7 +14,7 @@ Volumetric 3D noise visualized using a <b>3D texture</b>.
Uses the luma.gl <code>Texture3D</code> class.
`;

const vs = glsl`\
const vs = /* glsl */ `\
#version 300 es
in vec3 position;
Expand All @@ -28,7 +27,7 @@ void main() {
gl_PointSize = 2.0;
}`;

const fs = glsl`\
const fs = /* glsl */ `\
#version 300 es
precision highp float;
precision lowp sampler3D;
Expand Down
4 changes: 2 additions & 2 deletions examples/script/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

const colors = new Float32Array(SIDE * SIDE * 3).map(() => Math.random() * 0.75 + 0.25);

const vs = glsl`\
const vs = /* glsl */`\
in float instanceSizes;
in vec3 positions;
in vec3 normals;
Expand Down Expand Up @@ -87,7 +87,7 @@
gl_Position = uProjection * uView * (uModel * vec4(positions * instanceSizes, 1.0) + offset);
}
`;
const fs = glsl`\
const fs = /* glsl */`\
precision highp float;
in vec3 color;
Expand Down
8 changes: 4 additions & 4 deletions examples/script/webgl/transform-feedback/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {glsl, Buffer} from '@luma.gl/core';
import {Buffer} from '@luma.gl/core';
import {AnimationLoopTemplate, AnimationProps, Model} from '@luma.gl/engine';
import {BufferTransform} from '@luma.gl/engine';

Expand All @@ -8,7 +8,7 @@ Animation via transform feedback.

const ALT_TEXT = "THIS DEMO REQUIRES WEBGL 2, BUT YOUR BROWSER DOESN'T SUPPORT IT";

const transformVs = glsl`\
const transformVs = /* glsl */ `\
#version 300 es
#define SIN2 0.03489949
#define COS2 0.99939082
Expand All @@ -25,7 +25,7 @@ void main() {
}
`;

const renderVs = glsl`\
const renderVs = /* glsl */ `\
#version 300 es
in vec2 position;
Expand All @@ -38,7 +38,7 @@ void main() {
}
`;

const renderFs = glsl`\
const renderFs = /* glsl */ `\
#version 300 es
precision highp float;
Expand Down
6 changes: 3 additions & 3 deletions examples/showcase/instancing/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
import type {ShaderUniformType, NumberArray} from '@luma.gl/core';
import {Device, Framebuffer, glsl} from '@luma.gl/core';
import {Device, Framebuffer} from '@luma.gl/core';
import type {AnimationProps, ModelProps} from '@luma.gl/engine';
import {AnimationLoopTemplate, CubeGeometry, Timeline, Model, _ShaderInputs} from '@luma.gl/engine';
import {makeRandomGenerator} from '@luma.gl/engine';
Expand Down Expand Up @@ -95,7 +95,7 @@ fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {

// GLSL

const VS_GLSL = glsl`\
const VS_GLSL = /* glsl */ `\
#version 300 es
in vec3 positions;
Expand Down Expand Up @@ -130,7 +130,7 @@ void main(void) {
}
`;

const FS_GLSL = glsl`\
const FS_GLSL = /* glsl */ `\
#version 300 es
precision highp float;
Expand Down
12 changes: 6 additions & 6 deletions examples/showcase/persistence/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {NumberArray, ShaderUniformType} from '@luma.gl/core';
import {UniformStore, Framebuffer, glsl} from '@luma.gl/core';
import {UniformStore, Framebuffer} from '@luma.gl/core';
import type {AnimationProps} from '@luma.gl/engine';
import {
AnimationLoopTemplate,
Expand Down Expand Up @@ -79,7 +79,7 @@ fn fragmentMain(inputs: FragmentInputs) -> [[location(0)]] vec4<f32> {
}
`;

const SPHERE_VS = glsl`\
const SPHERE_VS = /* glsl */ `\
#version 300 es
in vec3 positions;
Expand All @@ -102,7 +102,7 @@ void main(void) {
}
`;

const SPHERE_FS = glsl`\
const SPHERE_FS = /* glsl */ `\
#version 300 es
precision highp float;
Expand Down Expand Up @@ -183,7 +183,7 @@ struct FragmentInputs {
}
`;

const SCREEN_QUAD_VS = glsl`\
const SCREEN_QUAD_VS = /* glsl */ `\
#version 300 es
in vec2 aPosition;
Expand All @@ -193,7 +193,7 @@ void main(void) {
}
`;

const SCREEN_QUAD_FS = glsl`\
const SCREEN_QUAD_FS = /* glsl */ `\
#version 300 es
precision highp float;
Expand Down Expand Up @@ -253,7 +253,7 @@ fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {
}
`;

const PERSISTENCE_FS = glsl`\
const PERSISTENCE_FS = /* glsl */ `\
#version 300 es
precision highp float;
Expand Down
6 changes: 3 additions & 3 deletions examples/tutorials/hello-cube/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright (c) vis.gl contributors

import type {NumberArray, ShaderUniformType} from '@luma.gl/core';
import {glsl, Texture, UniformStore} from '@luma.gl/core';
import {Texture, UniformStore} from '@luma.gl/core';
import type {AnimationProps} from '@luma.gl/engine';
import {AnimationLoopTemplate, Model, CubeGeometry, loadImage, AsyncTexture} from '@luma.gl/engine';
import {Matrix4} from '@math.gl/core';
Expand Down Expand Up @@ -53,7 +53,7 @@ fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {

// GLSL

export const VS_GLSL = glsl`\
export const VS_GLSL = /* glsl */ `\
#version 300 es
#define SHADER_NAME cube-vs
Expand All @@ -74,7 +74,7 @@ void main() {
}
`;

export const FS_GLSL = glsl`\
export const FS_GLSL = /* glsl */ `\
#version 300 es
#define SHADER_NAME cube-fs
precision highp float;
Expand Down
6 changes: 3 additions & 3 deletions examples/tutorials/hello-instanced-cubes/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Buffer, glsl} from '@luma.gl/core';
import {Buffer} from '@luma.gl/core';
import {AnimationLoopTemplate, AnimationProps, Model, CubeGeometry} from '@luma.gl/engine';
import {Matrix4} from '@math.gl/core';

Expand Down Expand Up @@ -44,7 +44,7 @@ fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {

// GLSL

const VS_GLSL = glsl`\
const VS_GLSL = /* glsl */ `\
#version 300 es
#define SHADER_NAME cube-vs
Expand All @@ -66,7 +66,7 @@ void main() {
}
`;

const FS_GLSL = glsl`\
const FS_GLSL = /* glsl */ `\
#version 300 es
#define SHADER_NAME cube-fs
precision highp float;
Expand Down
10 changes: 5 additions & 5 deletions examples/tutorials/hello-instancing/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {glsl, Buffer} from '@luma.gl/core';
import {Buffer} from '@luma.gl/core';
import {AnimationLoopTemplate, AnimationProps, Model} from '@luma.gl/engine';

const INFO_HTML = `
Expand All @@ -7,14 +7,14 @@ Instanced triangles using luma.gl's high-level API

const colorShaderModule = {
name: 'color',
vs: glsl`\
vs: /* glsl */ `\
out vec3 color_vColor;
void color_setColor(vec3 color) {
color_vColor = color;
}
`,
fs: glsl`\
fs: /* glsl */ `\
in vec3 color_vColor;
vec3 color_getColor() {
Expand Down Expand Up @@ -43,7 +43,7 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate {
);

this.model = new Model(device, {
vs: glsl`\
vs: /* glsl */ `\
#version 300 es
in vec2 position;
in vec3 instanceColor;
Expand All @@ -54,7 +54,7 @@ void main() {
gl_Position = vec4(position + instanceOffset, 0.0, 1.0);
}
`,
fs: glsl`\
fs: /* glsl */ `\
#version 300 es
out vec4 fragColor;
void main() {
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorials/hello-triangle-geometry/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {glsl, Buffer} from '@luma.gl/core';
import {Buffer} from '@luma.gl/core';
import {AnimationLoopTemplate, AnimationProps, Model} from '@luma.gl/engine';

const INFO_HTML = `
Expand All @@ -19,7 +19,7 @@ void main() {
}
`;

const fs = glsl`\
const fs = /* glsl */ `\
#version 300 es
in vec3 vColor;
Expand Down
5 changes: 2 additions & 3 deletions examples/tutorials/hello-triangle/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {glsl} from '@luma.gl/core';
import {AnimationLoopTemplate, AnimationProps, Model} from '@luma.gl/engine';

export const title = 'Hello Triangle';
Expand All @@ -18,15 +17,15 @@ fn fragmentMain() -> @location(0) vec4<f32> {
`;

/** Provide both GLSL and WGSL shaders */
const VS_GLSL = glsl`\
const VS_GLSL = /* glsl */ `\
#version 300 es
const vec2 pos[3] = vec2[3](vec2(0.0f, 0.5f), vec2(-0.5f, -0.5f), vec2(0.5f, -0.5f));
void main() {
gl_Position = vec4(pos[gl_VertexID], 0.0, 1.0);
}
`;

const FS_GLSL = glsl`\
const FS_GLSL = /* glsl */ `\
#version 300 es
precision highp float;
layout(location = 0) out vec4 outColor;
Expand Down

0 comments on commit 30be1e2

Please sign in to comment.