@luma.gl/shadertools 9.1.0-alpha.10 → 9.1.0-alpha.13
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.
- package/dist/dist.dev.js +195 -10
- package/dist/dist.min.js +241 -80
- package/dist/index.cjs +196 -10
- package/dist/index.cjs.map +3 -3
- package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.js +9 -8
- package/dist/lib/shader-module/shader-module-dependencies.d.ts.map +1 -1
- package/dist/lib/shader-module/shader-module-dependencies.js +1 -1
- package/dist/lib/shader-module/shader-module.d.ts +2 -2
- package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.d.ts +5 -5
- package/dist/modules/engine/picking/picking.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +1 -0
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.js +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-wgsl.d.ts +2 -0
- package/dist/modules/lighting/lights/lighting-uniforms-wgsl.d.ts.map +1 -0
- package/dist/modules/lighting/lights/lighting-uniforms-wgsl.js +56 -0
- package/dist/modules/lighting/lights/lighting.d.ts +1 -0
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting.js +5 -3
- package/dist/modules/lighting/no-material/dirlight.d.ts +4 -4
- package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.js +22 -11
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +1 -0
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.d.ts +2 -0
- package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js +2 -0
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +41 -0
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -0
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +130 -0
- package/dist/modules/math/fp64/fp64-utils.d.ts +3 -3
- package/dist/modules/math/fp64/fp64-utils.d.ts.map +1 -1
- package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts +2 -2
- package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/lib/shader-assembly/assemble-shaders.ts +9 -8
- package/src/lib/shader-module/shader-module-dependencies.ts +1 -2
- package/src/lib/shader-module/shader-module.ts +10 -6
- package/src/modules/engine/picking/picking.ts +5 -5
- package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +1 -1
- package/src/modules/lighting/lights/lighting-uniforms-wgsl.ts +57 -0
- package/src/modules/lighting/lights/lighting.ts +5 -3
- package/src/modules/lighting/no-material/dirlight.ts +24 -14
- package/src/modules/lighting/phong-material/phong-material.ts +2 -0
- package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +132 -0
- package/src/modules/math/fp64/fp64-utils.ts +3 -3
- package/src/modules-webgl1/lighting/dirlight/dirlight.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assemble-shaders.d.ts","sourceRoot":"","sources":["../../../src/lib/shader-assembly/assemble-shaders.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,YAAY,EAAC,2BAAwB;AAK7C,OAAO,KAAK,EAAC,eAAe,EAAC,+BAA4B;AACzD,OAAO,KAAK,EAAC,YAAY,EAAC,0CAAuC;AACjE,OAAO,EAAC,UAAU,EAAuC,0BAAuB;AAIhF,iBAAiB;AACjB,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,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B,CACpC,OAAO,EAAE,qBAAqB,GAAG;IAC/B,oBAAoB;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,sBAAsB;IACtB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,GACA;IACD,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,eAAe,CAAC;CAC9B,CAoBA;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,oBAAoB,UA6G3F;AA8JD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,YAAY,EAAE,UACvB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAU5E;AAgCD,gGAAgG;AAChG,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,GACpC,MAAM,CA6BR"}
|
|
@@ -120,15 +120,15 @@ export function assembleShaderWGSL(platformInfo, options) {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
// TODO - hack until shadertool modules support WebGPU
|
|
123
|
-
const modulesToInject =
|
|
123
|
+
const modulesToInject = modules;
|
|
124
124
|
for (const module of modulesToInject) {
|
|
125
125
|
if (log) {
|
|
126
126
|
checkShaderModuleDeprecations(module, coreSource, log);
|
|
127
127
|
}
|
|
128
|
-
const moduleSource = getShaderModuleSource(module,
|
|
128
|
+
const moduleSource = getShaderModuleSource(module, 'wgsl');
|
|
129
129
|
// Add the module source, and a #define that declares it presence
|
|
130
130
|
assembledSource += moduleSource;
|
|
131
|
-
const injections = module.injections[stage];
|
|
131
|
+
const injections = module.injections?.[stage] || {};
|
|
132
132
|
for (const key in injections) {
|
|
133
133
|
const match = /^(v|f)s:#([\w-]+)$/.exec(key);
|
|
134
134
|
if (match) {
|
|
@@ -331,14 +331,15 @@ export function getShaderModuleSource(module, stage) {
|
|
|
331
331
|
throw new Error('Shader module must have a name');
|
|
332
332
|
}
|
|
333
333
|
const moduleName = module.name.toUpperCase().replace(/[^0-9a-z]/gi, '_');
|
|
334
|
-
|
|
334
|
+
let source = `\
|
|
335
335
|
// ----- MODULE ${module.name} ---------------
|
|
336
336
|
|
|
337
|
-
#define MODULE_${moduleName}
|
|
338
|
-
${moduleSource}\
|
|
339
|
-
|
|
340
|
-
|
|
341
337
|
`;
|
|
338
|
+
if (stage !== 'wgsl') {
|
|
339
|
+
source += `#define MODULE_${moduleName}\n`;
|
|
340
|
+
}
|
|
341
|
+
source += `${moduleSource}\n`;
|
|
342
|
+
return source;
|
|
342
343
|
}
|
|
343
344
|
/*
|
|
344
345
|
function getHookFunctions(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shader-module-dependencies.d.ts","sourceRoot":"","sources":["../../../src/lib/shader-module/shader-module-dependencies.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"shader-module-dependencies.d.ts","sourceRoot":"","sources":["../../../src/lib/shader-module/shader-module-dependencies.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAA0B,2BAAwB;AAItE,KAAK,cAAc,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,cAAc,EAAE,CAAC;CACjC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,cAAc,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAYvF;AAED;;;;;;;;GAQG;AAEH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,cAAc,EAAE,OAAO,EAAE;IACpE,OAAO,EAAE,CAAC,EAAE,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC,QAoBA;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,YAAY,EAAE,CAY7E;AAID;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,YAAY,EAAE,CAEtE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { initializeShaderModules } from "
|
|
4
|
+
import { initializeShaderModules } from "./shader-module.js";
|
|
5
5
|
/**
|
|
6
6
|
* Takes a list of shader module names and returns a new list of
|
|
7
7
|
* shader module names that includes all dependencies, sorted so
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NumericArray } from '@math.gl/types';
|
|
2
2
|
import { Sampler, Texture } from '@luma.gl/core';
|
|
3
3
|
import type { UniformFormat } from "../../types.js";
|
|
4
4
|
import { PropType, PropValidator } from "../filters/prop-types.js";
|
|
5
5
|
import { ShaderInjection } from "../shader-assembly/shader-injections.js";
|
|
6
6
|
export type BindingValue = Buffer | Texture | Sampler;
|
|
7
|
-
export type UniformValue = number | boolean | Readonly<
|
|
7
|
+
export type UniformValue = number | boolean | Readonly<NumericArray>;
|
|
8
8
|
export type UniformInfo = {
|
|
9
9
|
format?: UniformFormat;
|
|
10
10
|
} & PropType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shader-module.d.ts","sourceRoot":"","sources":["../../../src/lib/shader-module/shader-module.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,
|
|
1
|
+
{"version":3,"file":"shader-module.d.ts","sourceRoot":"","sources":["../../../src/lib/shader-module/shader-module.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AACj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AE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAIF,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,IAAI,CAErE;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAwBjE;AAED,uCAAuC;AACvC,wBAAgB,uBAAuB,CACrC,aAAa,SAAS,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,EAEzF,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAC7B,WAAW,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,GACtC,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAAC,CAY7C;AAwBD,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,GAAG,GACP,IAAI,CAUN"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NumericArray } from "../../../types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Props for the picking module, which depending on mode renders picking colors or highlighted item.
|
|
4
4
|
* When active, renders picking colors, assumed to be rendered to off-screen "picking" buffer.
|
|
@@ -10,9 +10,9 @@ export type PickingProps = {
|
|
|
10
10
|
/** Set to true when picking an attribute value instead of object index */
|
|
11
11
|
isAttribute?: boolean;
|
|
12
12
|
/** Set to a picking color to visually highlight that item, or `null` to explicitly clear **/
|
|
13
|
-
highlightedObjectColor?:
|
|
13
|
+
highlightedObjectColor?: NumericArray | null;
|
|
14
14
|
/** Color of visual highlight of "selected" item */
|
|
15
|
-
highlightColor?:
|
|
15
|
+
highlightColor?: NumericArray;
|
|
16
16
|
/** Color range 0-1 or 0-255 */
|
|
17
17
|
useFloatColors?: boolean;
|
|
18
18
|
};
|
|
@@ -34,9 +34,9 @@ export type PickingUniforms = {
|
|
|
34
34
|
/** Do we have a highlighted item? */
|
|
35
35
|
isHighlightActive?: boolean;
|
|
36
36
|
/** Set to a picking color to visually highlight that item */
|
|
37
|
-
highlightedObjectColor?:
|
|
37
|
+
highlightedObjectColor?: NumericArray;
|
|
38
38
|
/** Color of visual highlight of "selected" item */
|
|
39
|
-
highlightColor?:
|
|
39
|
+
highlightColor?: NumericArray;
|
|
40
40
|
};
|
|
41
41
|
/**
|
|
42
42
|
* Provides support for color-coding-based picking and highlighting.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picking.d.ts","sourceRoot":"","sources":["../../../../src/modules/engine/picking/picking.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"picking.d.ts","sourceRoot":"","sources":["../../../../src/modules/engine/picking/picking.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,0BAAuB;AAM5C;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,0EAA0E;IAC1E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,6FAA6F;IAC7F,sBAAsB,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAC7C,mDAAmD;IACnD,cAAc,CAAC,EAAE,YAAY,CAAC;IAC9B,+BAA+B;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,0EAA0E;IAC1E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,+BAA+B;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,qCAAqC;IACrC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,6DAA6D;IAC7D,sBAAsB,CAAC,EAAE,YAAY,CAAC;IACtC,mDAAmD;IACnD,cAAc,CAAC,EAAE,YAAY,CAAC;CAC/B,CAAC;AAuIF;;;;;;GAMG;AACH,eAAO,MAAM,OAAO;oBACL,YAAY;uBACT,eAAe;;;;;;;;;;;;;;;;;;;;;CAwB+B,CAAC;AAEjE,iBAAS,WAAW,CAAC,IAAI,GAAE,YAAiB,EAAE,YAAY,CAAC,EAAE,eAAe,GAAG,eAAe,CA+B7F"}
|
|
@@ -43,6 +43,7 @@ export declare const gouraudMaterial: {
|
|
|
43
43
|
readonly lightDirection: readonly [1, 1, 1];
|
|
44
44
|
readonly lightAttenuation: readonly [1, 1, 1];
|
|
45
45
|
};
|
|
46
|
+
readonly source: "// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n color: vec3<f32>,\n};\n\nstruct PointLight {\n color: vec3<f32>,\n position: vec3<f32>,\n attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n color: vec3<f32>,\n direction: vec3<f32>,\n};\n\nstruct lightingUniforms {\n enabled: i32,\n poightCount: i32,\n directionalLightCount: i32,\n\n ambientColor: vec3<f32>,\n\n // TODO - support multiple lights by uncommenting arrays below\n lightType: i32,\n lightColor: vec3<f32>,\n lightDirection: vec3<f32>,\n lightPosition: vec3<f32>,\n lightAttenuation: vec3<f32>,\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n};\n\n// Binding 0:1 is reserved for lighting (Note: could go into separate bind group as it is stable across draw calls)\n@binding(1) @group(0) var<uniform> lighting : lightingUniforms;\n\nfn lighting_getPointLight(index: i32) -> PointLight {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nfn lighting_getDirectionalLight(index: i32) -> DirectionalLight {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n";
|
|
46
47
|
readonly vs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int pointLightCount;\n int directionalLightCount;\n\n vec3 ambientColor;\n\n int lightType;\n vec3 lightColor;\n vec3 lightDirection;\n vec3 lightPosition;\n vec3 lightAttenuation;\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";
|
|
47
48
|
readonly fs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int pointLightCount;\n int directionalLightCount;\n\n vec3 ambientColor;\n\n int lightType;\n vec3 lightColor;\n vec3 lightDirection;\n vec3 lightPosition;\n vec3 lightAttenuation;\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";
|
|
48
49
|
readonly getUniforms: (props?: import("../lights/lighting").LightingProps, prevUniforms?: Partial<import("../lights/lighting").LightingUniforms>) => import("../lights/lighting").LightingUniforms;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gouraud-material.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/gouraud-material/gouraud-material.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AAE3D,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C,CAAC;AAEF,yIAAyI;AACzI,eAAO,MAAM,eAAe;oBACb,oBAAoB;uBACjB,uBAAuB
|
|
1
|
+
{"version":3,"file":"gouraud-material.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/gouraud-material/gouraud-material.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AAE3D,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C,CAAC;AAEF,yIAAyI;AACzI,eAAO,MAAM,eAAe;oBACb,oBAAoB;uBACjB,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAuBpB,oBAAoB,KAAG,uBAAuB;CAGa,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const lightingUniformsGLSL = "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int pointLightCount;\n int directionalLightCount;\n\n vec3 ambientColor;\n\n int lightType;\n vec3 lightColor;\n vec3 lightDirection;\n vec3 lightPosition;\n vec3 lightAttenuation;\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";
|
|
2
2
|
//# sourceMappingURL=lighting-uniforms-glsl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lighting-uniforms-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-uniforms-glsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"lighting-uniforms-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-uniforms-glsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB,6wCAoDhC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
export const
|
|
4
|
+
export const lightingUniformsGLSL = /* glsl */ `\
|
|
5
5
|
precision highp int;
|
|
6
6
|
|
|
7
7
|
// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const lightingUniformsWGSL = "// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n color: vec3<f32>,\n};\n\nstruct PointLight {\n color: vec3<f32>,\n position: vec3<f32>,\n attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n color: vec3<f32>,\n direction: vec3<f32>,\n};\n\nstruct lightingUniforms {\n enabled: i32,\n poightCount: i32,\n directionalLightCount: i32,\n\n ambientColor: vec3<f32>,\n\n // TODO - support multiple lights by uncommenting arrays below\n lightType: i32,\n lightColor: vec3<f32>,\n lightDirection: vec3<f32>,\n lightPosition: vec3<f32>,\n lightAttenuation: vec3<f32>,\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n};\n\n// Binding 0:1 is reserved for lighting (Note: could go into separate bind group as it is stable across draw calls)\n@binding(1) @group(0) var<uniform> lighting : lightingUniforms;\n\nfn lighting_getPointLight(index: i32) -> PointLight {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nfn lighting_getDirectionalLight(index: i32) -> DirectionalLight {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n";
|
|
2
|
+
//# sourceMappingURL=lighting-uniforms-wgsl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lighting-uniforms-wgsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-uniforms-wgsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB,4iDAoDhC,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
export const lightingUniformsWGSL = /* wgsl */ `\
|
|
5
|
+
// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
6
|
+
struct AmbientLight {
|
|
7
|
+
color: vec3<f32>,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
struct PointLight {
|
|
11
|
+
color: vec3<f32>,
|
|
12
|
+
position: vec3<f32>,
|
|
13
|
+
attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
struct DirectionalLight {
|
|
17
|
+
color: vec3<f32>,
|
|
18
|
+
direction: vec3<f32>,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
struct lightingUniforms {
|
|
22
|
+
enabled: i32,
|
|
23
|
+
poightCount: i32,
|
|
24
|
+
directionalLightCount: i32,
|
|
25
|
+
|
|
26
|
+
ambientColor: vec3<f32>,
|
|
27
|
+
|
|
28
|
+
// TODO - support multiple lights by uncommenting arrays below
|
|
29
|
+
lightType: i32,
|
|
30
|
+
lightColor: vec3<f32>,
|
|
31
|
+
lightDirection: vec3<f32>,
|
|
32
|
+
lightPosition: vec3<f32>,
|
|
33
|
+
lightAttenuation: vec3<f32>,
|
|
34
|
+
|
|
35
|
+
// AmbientLight ambientLight;
|
|
36
|
+
// PointLight pointLight[MAX_LIGHTS];
|
|
37
|
+
// DirectionalLight directionalLight[MAX_LIGHTS];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Binding 0:1 is reserved for lighting (Note: could go into separate bind group as it is stable across draw calls)
|
|
41
|
+
@binding(1) @group(0) var<uniform> lighting : lightingUniforms;
|
|
42
|
+
|
|
43
|
+
fn lighting_getPointLight(index: i32) -> PointLight {
|
|
44
|
+
return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fn lighting_getDirectionalLight(index: i32) -> DirectionalLight {
|
|
48
|
+
return DirectionalLight(lighting.lightColor, lighting.lightDirection);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
|
|
52
|
+
return pointLight.attenuation.x
|
|
53
|
+
+ pointLight.attenuation.y * distance
|
|
54
|
+
+ pointLight.attenuation.z * distance * distance;
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
@@ -73,6 +73,7 @@ export declare const lighting: {
|
|
|
73
73
|
readonly lightDirection: readonly [1, 1, 1];
|
|
74
74
|
readonly lightAttenuation: readonly [1, 1, 1];
|
|
75
75
|
};
|
|
76
|
+
readonly source: "// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n color: vec3<f32>,\n};\n\nstruct PointLight {\n color: vec3<f32>,\n position: vec3<f32>,\n attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n color: vec3<f32>,\n direction: vec3<f32>,\n};\n\nstruct lightingUniforms {\n enabled: i32,\n poightCount: i32,\n directionalLightCount: i32,\n\n ambientColor: vec3<f32>,\n\n // TODO - support multiple lights by uncommenting arrays below\n lightType: i32,\n lightColor: vec3<f32>,\n lightDirection: vec3<f32>,\n lightPosition: vec3<f32>,\n lightAttenuation: vec3<f32>,\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n};\n\n// Binding 0:1 is reserved for lighting (Note: could go into separate bind group as it is stable across draw calls)\n@binding(1) @group(0) var<uniform> lighting : lightingUniforms;\n\nfn lighting_getPointLight(index: i32) -> PointLight {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nfn lighting_getDirectionalLight(index: i32) -> DirectionalLight {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n";
|
|
76
77
|
readonly vs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int pointLightCount;\n int directionalLightCount;\n\n vec3 ambientColor;\n\n int lightType;\n vec3 lightColor;\n vec3 lightDirection;\n vec3 lightPosition;\n vec3 lightAttenuation;\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";
|
|
77
78
|
readonly fs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int pointLightCount;\n int directionalLightCount;\n\n vec3 ambientColor;\n\n int lightType;\n vec3 lightColor;\n vec3 lightDirection;\n vec3 lightPosition;\n vec3 lightAttenuation;\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";
|
|
78
79
|
readonly getUniforms: typeof getUniforms;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lighting.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"lighting.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAWhD,mCAAmC;AACnC,oBAAY,UAAU;IACpB,KAAK,IAAI;IACT,WAAW,IAAI;CAChB;AAED,4BAA4B;AAE5B,MAAM,MAAM,KAAK,GAAG,YAAY,GAAG,UAAU,GAAG,gBAAgB,CAAC;AAEjE,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAChC,KAAK,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAChC,SAAS,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IACjB,kBAAkB;IAClB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,kBAAkB;IAClB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,kBAAkB;IAClB,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACzC,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAClC,aAAa,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACrC,cAAc,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACtC,gBAAgB,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;CACzC,CAAC;AAEF,gCAAgC;AAChC,eAAO,MAAM,QAAQ;oBACN,aAAa;uBACV,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCgC,CAAC;AAEnE,iBAAS,WAAW,CAClB,KAAK,CAAC,EAAE,aAAa,EACrB,YAAY,GAAE,OAAO,CAAC,gBAAgB,CAAM,GAC3C,gBAAgB,CAoClB"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import {
|
|
4
|
+
import { lightingUniformsGLSL } from "./lighting-uniforms-glsl.js";
|
|
5
|
+
import { lightingUniformsWGSL } from "./lighting-uniforms-wgsl.js";
|
|
5
6
|
/** Max number of supported lights (in addition to ambient light */
|
|
6
7
|
const MAX_LIGHTS = 5;
|
|
7
8
|
/** Whether to divide */
|
|
@@ -42,8 +43,9 @@ export const lighting = {
|
|
|
42
43
|
lightDirection: [1, 1, 1],
|
|
43
44
|
lightAttenuation: [1, 1, 1]
|
|
44
45
|
},
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
source: lightingUniformsWGSL,
|
|
47
|
+
vs: lightingUniformsGLSL,
|
|
48
|
+
fs: lightingUniformsGLSL,
|
|
47
49
|
getUniforms
|
|
48
50
|
};
|
|
49
51
|
function getUniforms(props, prevUniforms = {}) {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Vector3Like, TypedArray } from '@math.gl/core';
|
|
2
2
|
export type DirlightProps = {
|
|
3
|
-
lightDirection?:
|
|
3
|
+
lightDirection?: Vector3Like | TypedArray;
|
|
4
4
|
};
|
|
5
5
|
export type DirlightUniforms = DirlightProps;
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const FS_WGSL = "uniform dirlightUniforms {\n vec3 lightDirection;\n} dirlight;\n\n// Returns color attenuated by angle from light source\nfn dirlight_filterColor(color: vec4<f32>, dirlightInputs): vec4<f32> {\n const d: float = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));\n return vec4<f32>(color.rgb * d, color.a);\n}\n";
|
|
6
|
+
export declare const SOURCE_WGSL = " \nstruct dirlightUniforms {\n lightDirection: vec3<f32>,\n};\n\nalias DirlightNormal = vec3<f32>;\n\nstruct DirlightInputs {\n normal: DirlightNormal,\n};\n\n@binding(1) @group(0) var<uniform> dirlight : dirlightUniforms;\n\n// For vertex\nfn dirlight_setNormal(normal: vec3<f32>) -> DirlightNormal {\n return normalize(normal);\n}\n\n// Returns color attenuated by angle from light source\nfn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {\n // TODO - fix default light direction\n // let lightDirection = dirlight.lightDirection;\n let lightDirection = vec3<f32>(1, 1, 1);\n let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));\n return vec4<f32>(color.rgb * d, color.a);\n}\n";
|
|
8
7
|
/**
|
|
9
8
|
* Cheap lighting - single directional light, single dot product, one uniform
|
|
10
9
|
*/
|
|
@@ -13,6 +12,7 @@ export declare const dirlight: {
|
|
|
13
12
|
readonly uniforms: DirlightUniforms;
|
|
14
13
|
readonly name: "dirlight";
|
|
15
14
|
readonly dependencies: [];
|
|
15
|
+
readonly source: " \nstruct dirlightUniforms {\n lightDirection: vec3<f32>,\n};\n\nalias DirlightNormal = vec3<f32>;\n\nstruct DirlightInputs {\n normal: DirlightNormal,\n};\n\n@binding(1) @group(0) var<uniform> dirlight : dirlightUniforms;\n\n// For vertex\nfn dirlight_setNormal(normal: vec3<f32>) -> DirlightNormal {\n return normalize(normal);\n}\n\n// Returns color attenuated by angle from light source\nfn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {\n // TODO - fix default light direction\n // let lightDirection = dirlight.lightDirection;\n let lightDirection = vec3<f32>(1, 1, 1);\n let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));\n return vec4<f32>(color.rgb * d, color.a);\n}\n";
|
|
16
16
|
readonly vs: "out vec3 dirlight_vNormal;\n\nvoid dirlight_setNormal(vec3 normal) {\n dirlight_vNormal = normalize(normal);\n}\n";
|
|
17
17
|
readonly fs: "uniform dirlightUniforms {\n vec3 lightDirection;\n} dirlight;\n\nin vec3 dirlight_vNormal;\n\n// Returns color attenuated by angle from light source\nvec4 dirlight_filterColor(vec4 color) {\n float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));\n return vec4(color.rgb * d, color.a);\n}\n";
|
|
18
18
|
readonly uniformTypes: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dirlight.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/no-material/dirlight.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"dirlight.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/no-material/dirlight.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAE,UAAU,EAAC,MAAM,eAAe,CAAC;AAG3D,MAAM,MAAM,aAAa,GAAG;IAC1B,cAAc,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAG7C,eAAO,MAAM,WAAW,guBA0BvB,CAAC;AAwBF;;GAEG;AACH,eAAO,MAAM,QAAQ;oBACN,aAAa;uBACV,gBAAgB;;;;;;;;;;;;;CAqBgC,CAAC;AAEnE,iBAAS,WAAW,CAAC,IAAI,GAAE,aAAwC,GAAG,gBAAgB,CAOrF"}
|
|
@@ -2,20 +2,30 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
// TODO
|
|
5
|
-
export const
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export const SOURCE_WGSL = /* WGSL */ `\
|
|
6
|
+
struct dirlightUniforms {
|
|
7
|
+
lightDirection: vec3<f32>,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
alias DirlightNormal = vec3<f32>;
|
|
11
|
+
|
|
12
|
+
struct DirlightInputs {
|
|
13
|
+
normal: DirlightNormal,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
@binding(1) @group(0) var<uniform> dirlight : dirlightUniforms;
|
|
17
|
+
|
|
18
|
+
// For vertex
|
|
19
|
+
fn dirlight_setNormal(normal: vec3<f32>) -> DirlightNormal {
|
|
20
|
+
return normalize(normal);
|
|
8
21
|
}
|
|
9
|
-
`;
|
|
10
|
-
// TODO
|
|
11
|
-
export const FS_WGSL = /* WGSL */ `\
|
|
12
|
-
uniform dirlightUniforms {
|
|
13
|
-
vec3 lightDirection;
|
|
14
|
-
} dirlight;
|
|
15
22
|
|
|
16
23
|
// Returns color attenuated by angle from light source
|
|
17
|
-
fn dirlight_filterColor(color: vec4<f32>,
|
|
18
|
-
|
|
24
|
+
fn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {
|
|
25
|
+
// TODO - fix default light direction
|
|
26
|
+
// let lightDirection = dirlight.lightDirection;
|
|
27
|
+
let lightDirection = vec3<f32>(1, 1, 1);
|
|
28
|
+
let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));
|
|
19
29
|
return vec4<f32>(color.rgb * d, color.a);
|
|
20
30
|
}
|
|
21
31
|
`;
|
|
@@ -47,6 +57,7 @@ export const dirlight = {
|
|
|
47
57
|
uniforms: {},
|
|
48
58
|
name: 'dirlight',
|
|
49
59
|
dependencies: [],
|
|
60
|
+
source: SOURCE_WGSL,
|
|
50
61
|
vs: VS_GLSL,
|
|
51
62
|
fs: FS_GLSL,
|
|
52
63
|
// fragmentInputs: [
|
|
@@ -85,6 +85,7 @@ export declare const pbrMaterial: {
|
|
|
85
85
|
readonly lightDirection: readonly [1, 1, 1];
|
|
86
86
|
readonly lightAttenuation: readonly [1, 1, 1];
|
|
87
87
|
};
|
|
88
|
+
readonly source: "// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n color: vec3<f32>,\n};\n\nstruct PointLight {\n color: vec3<f32>,\n position: vec3<f32>,\n attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n color: vec3<f32>,\n direction: vec3<f32>,\n};\n\nstruct lightingUniforms {\n enabled: i32,\n poightCount: i32,\n directionalLightCount: i32,\n\n ambientColor: vec3<f32>,\n\n // TODO - support multiple lights by uncommenting arrays below\n lightType: i32,\n lightColor: vec3<f32>,\n lightDirection: vec3<f32>,\n lightPosition: vec3<f32>,\n lightAttenuation: vec3<f32>,\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n};\n\n// Binding 0:1 is reserved for lighting (Note: could go into separate bind group as it is stable across draw calls)\n@binding(1) @group(0) var<uniform> lighting : lightingUniforms;\n\nfn lighting_getPointLight(index: i32) -> PointLight {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nfn lighting_getDirectionalLight(index: i32) -> DirectionalLight {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n";
|
|
88
89
|
readonly vs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int pointLightCount;\n int directionalLightCount;\n\n vec3 ambientColor;\n\n int lightType;\n vec3 lightColor;\n vec3 lightDirection;\n vec3 lightPosition;\n vec3 lightAttenuation;\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";
|
|
89
90
|
readonly fs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int pointLightCount;\n int directionalLightCount;\n\n vec3 ambientColor;\n\n int lightType;\n vec3 lightColor;\n vec3 lightDirection;\n vec3 lightPosition;\n vec3 lightAttenuation;\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";
|
|
90
91
|
readonly getUniforms: (props?: import("../lights/lighting").LightingProps, prevUniforms?: Partial<import("../lights/lighting").LightingUniforms>) => import("../lights/lighting").LightingUniforms;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbr-material.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-material.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,EAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAQ7D,MAAM,MAAM,gBAAgB,GAAG,mBAAmB,GAAG;IACnD,KAAK,CAAC,EAAE,OAAO,CAAC;IAGhB,mBAAmB,CAAC,EAAE,OAA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@ export declare const phongMaterial: {
|
|
|
38
38
|
readonly lightDirection: readonly [1, 1, 1];
|
|
39
39
|
readonly lightAttenuation: readonly [1, 1, 1];
|
|
40
40
|
};
|
|
41
|
+
readonly source: "// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n color: vec3<f32>,\n};\n\nstruct PointLight {\n color: vec3<f32>,\n position: vec3<f32>,\n attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n color: vec3<f32>,\n direction: vec3<f32>,\n};\n\nstruct lightingUniforms {\n enabled: i32,\n poightCount: i32,\n directionalLightCount: i32,\n\n ambientColor: vec3<f32>,\n\n // TODO - support multiple lights by uncommenting arrays below\n lightType: i32,\n lightColor: vec3<f32>,\n lightDirection: vec3<f32>,\n lightPosition: vec3<f32>,\n lightAttenuation: vec3<f32>,\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n};\n\n// Binding 0:1 is reserved for lighting (Note: could go into separate bind group as it is stable across draw calls)\n@binding(1) @group(0) var<uniform> lighting : lightingUniforms;\n\nfn lighting_getPointLight(index: i32) -> PointLight {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nfn lighting_getDirectionalLight(index: i32) -> DirectionalLight {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n";
|
|
41
42
|
readonly vs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int pointLightCount;\n int directionalLightCount;\n\n vec3 ambientColor;\n\n int lightType;\n vec3 lightColor;\n vec3 lightDirection;\n vec3 lightPosition;\n vec3 lightAttenuation;\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";
|
|
42
43
|
readonly fs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int pointLightCount;\n int directionalLightCount;\n\n vec3 ambientColor;\n\n int lightType;\n vec3 lightColor;\n vec3 lightDirection;\n vec3 lightPosition;\n vec3 lightAttenuation;\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";
|
|
43
44
|
readonly getUniforms: (props?: import("../lights/lighting").LightingProps, prevUniforms?: Partial<import("../lights/lighting").LightingUniforms>) => import("../lights/lighting").LightingUniforms;
|
|
44
45
|
}];
|
|
46
|
+
readonly source: "struct phongMaterialUniforms {\n ambient: f32,\n diffuse: f32,\n shininess: f32,\n specularColor: vec3<f32>,\n};\n\n@binding(2) @group(0) var<uniform> material : phongMaterialUniforms;\n\nfn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, view_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {\n let halfway_direction: vec3<f32> = normalize(light_direction + view_direction);\n var lambertian: f32 = dot(light_direction, normal_worldspace);\n var specular: f32 = 0.0;\n if (lambertian > 0.0) {\n let specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);\n specular = pow(specular_angle, material.shininess);\n }\n lambertian = max(lambertian, 0.0);\n return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;\n}\n\nfn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {\n var lightColor: vec3<f32> = surfaceColor;\n\n if (lighting.enabled == 0) {\n return lightColor;\n }\n\n let view_direction: vec3<f32> = normalize(cameraPosition - position_worldspace);\n lightColor = material.ambient * surfaceColor * lighting.ambientColor;\n\n if (lighting.lightType == 0) {\n let pointLight: PointLight = lighting_getPointLight(0);\n let light_position_worldspace: vec3<f32> = pointLight.position;\n let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n } else if (lighting.lightType == 1) {\n var directionalLight: DirectionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n \n return lightColor;\n /*\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= lighting.pointLightCount) {\n break;\n }\n PointLight pointLight = lighting.pointLight[i];\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n }\n\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= lighting.directionalLightCount) {\n break;\n }\n DirectionalLight directionalLight = lighting.directionalLight[i];\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n */\n}\n\nfn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32>{\n var lightColor = vec3<f32>(0, 0, 0);\n let surfaceColor = vec3<f32>(0, 0, 0);\n\n if (lighting.enabled == 0) {\n let view_direction = normalize(cameraPosition - position_worldspace);\n\n switch (lighting.lightType) {\n case 0, default: {\n let pointLight: PointLight = lighting_getPointLight(0);\n let light_position_worldspace: vec3<f32> = pointLight.position;\n let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n }\n case 1: {\n let directionalLight: DirectionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n }\n }\n return lightColor;\n}\n";
|
|
45
47
|
readonly vs: "uniform phongMaterialUniforms {\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n";
|
|
46
48
|
readonly fs: "uniform phongMaterialUniforms {\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n\nvec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {\n vec3 halfway_direction = normalize(light_direction + view_direction);\n float lambertian = dot(light_direction, normal_worldspace);\n float specular = 0.0;\n if (lambertian > 0.0) {\n float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);\n specular = pow(specular_angle, material.shininess);\n }\n lambertian = max(lambertian, 0.0);\n return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;\n}\n\nvec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {\n vec3 lightColor = surfaceColor;\n\n if (lighting.enabled == 0) {\n return lightColor;\n }\n\n vec3 view_direction = normalize(cameraPosition - position_worldspace);\n lightColor = material.ambient * surfaceColor * lighting.ambientColor;\n\n if (lighting.lightType == 0) {\n PointLight pointLight = lighting_getPointLight(0);\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n } else if (lighting.lightType == 1) {\n DirectionalLight directionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n \n /*\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= lighting.pointLightCount) {\n break;\n }\n PointLight pointLight = lighting.pointLight[i];\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n }\n\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= lighting.directionalLightCount) {\n break;\n }\n DirectionalLight directionalLight = lighting.directionalLight[i];\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n */\n return lightColor;\n}\n\nvec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {\n vec3 lightColor = vec3(0, 0, 0);\n vec3 surfaceColor = vec3(0, 0, 0);\n\n if (lighting.enabled == 0) {\n vec3 view_direction = normalize(cameraPosition - position_worldspace);\n\n switch (lighting.lightType) {\n case 0:\n PointLight pointLight = lighting_getPointLight(0);\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n break;\n\n case 1:\n DirectionalLight directionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n break;\n }\n }\n return lightColor;\n}\n";
|
|
47
49
|
readonly defines: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phong-material.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-material.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"phong-material.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-material.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,kBAAkB,GAAG,qBAAqB,CAAC;AAEvD,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C,CAAC;AAEF,wIAAwI;AACxI,eAAO,MAAM,aAAa;oBACX,kBAAkB;uBACf,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mCAuBjB,kBAAkB,KAAG,qBAAqB;CAGY,CAAC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
import { lighting } from "../lights/lighting.js";
|
|
5
|
+
import { PHONG_WGSL } from "./phong-shaders-wgsl.js";
|
|
5
6
|
import { PHONG_VS, PHONG_FS } from "./phong-shaders-glsl.js";
|
|
6
7
|
/** In Phong shading, the normal vector is linearly interpolated across the surface of the polygon from the polygon's vertex normals. */
|
|
7
8
|
export const phongMaterial = {
|
|
@@ -10,6 +11,7 @@ export const phongMaterial = {
|
|
|
10
11
|
name: 'phong-lighting',
|
|
11
12
|
dependencies: [lighting],
|
|
12
13
|
// Note these are switched between phong and gouraud
|
|
14
|
+
source: PHONG_WGSL,
|
|
13
15
|
vs: PHONG_VS,
|
|
14
16
|
fs: PHONG_FS,
|
|
15
17
|
defines: {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare const PHONG_WGSL = "struct phongMaterialUniforms {\n ambient: f32,\n diffuse: f32,\n shininess: f32,\n specularColor: vec3<f32>,\n};\n\n@binding(2) @group(0) var<uniform> material : phongMaterialUniforms;\n\nfn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, view_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {\n let halfway_direction: vec3<f32> = normalize(light_direction + view_direction);\n var lambertian: f32 = dot(light_direction, normal_worldspace);\n var specular: f32 = 0.0;\n if (lambertian > 0.0) {\n let specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);\n specular = pow(specular_angle, material.shininess);\n }\n lambertian = max(lambertian, 0.0);\n return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;\n}\n\nfn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {\n var lightColor: vec3<f32> = surfaceColor;\n\n if (lighting.enabled == 0) {\n return lightColor;\n }\n\n let view_direction: vec3<f32> = normalize(cameraPosition - position_worldspace);\n lightColor = material.ambient * surfaceColor * lighting.ambientColor;\n\n if (lighting.lightType == 0) {\n let pointLight: PointLight = lighting_getPointLight(0);\n let light_position_worldspace: vec3<f32> = pointLight.position;\n let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n } else if (lighting.lightType == 1) {\n var directionalLight: DirectionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n \n return lightColor;\n /*\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= lighting.pointLightCount) {\n break;\n }\n PointLight pointLight = lighting.pointLight[i];\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n }\n\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= lighting.directionalLightCount) {\n break;\n }\n DirectionalLight directionalLight = lighting.directionalLight[i];\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n */\n}\n\nfn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32>{\n var lightColor = vec3<f32>(0, 0, 0);\n let surfaceColor = vec3<f32>(0, 0, 0);\n\n if (lighting.enabled == 0) {\n let view_direction = normalize(cameraPosition - position_worldspace);\n\n switch (lighting.lightType) {\n case 0, default: {\n let pointLight: PointLight = lighting_getPointLight(0);\n let light_position_worldspace: vec3<f32> = pointLight.position;\n let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n }\n case 1: {\n let directionalLight: DirectionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n }\n }\n return lightColor;\n}\n";
|
|
2
|
+
/**
|
|
3
|
+
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
4
|
+
if (i >= lighting.pointLightCount) {
|
|
5
|
+
break;
|
|
6
|
+
}
|
|
7
|
+
PointLight pointLight = lighting_getPointLight(i);
|
|
8
|
+
vec3 light_position_worldspace = pointLight.position;
|
|
9
|
+
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
10
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
14
|
+
if (i >= lighting.directionalLightCount) {
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
PointLight pointLight = lighting_getDirectionalLight(i);
|
|
18
|
+
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
23
|
+
if (i >= lighting.pointLightCount) {
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
PointLight pointLight = lighting_getPointLight(i);
|
|
27
|
+
vec3 light_position_worldspace = pointLight.position;
|
|
28
|
+
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
29
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
33
|
+
if (i >= lighting.directionalLightCount) {
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
PointLight pointLight = lighting_getDirectionalLight(i);
|
|
37
|
+
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
*/
|
|
41
|
+
//# sourceMappingURL=phong-shaders-wgsl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phong-shaders-wgsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-shaders-wgsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,gvHAsFtB,CAAC;AAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsCI"}
|