@luma.gl/shadertools
Advanced tools
Comparing version 9.1.0-alpha.10 to 9.1.0-alpha.12
@@ -123,3 +123,3 @@ // luma.gl | ||
// TODO - hack until shadertool modules support WebGPU | ||
const modulesToInject = platformInfo.type !== 'webgpu' ? modules : []; | ||
const modulesToInject = modules; | ||
for (const module of modulesToInject) { | ||
@@ -129,6 +129,6 @@ if (log) { | ||
} | ||
const moduleSource = getShaderModuleSource(module, stage); | ||
const moduleSource = getShaderModuleSource(module, 'wgsl'); | ||
// Add the module source, and a #define that declares it presence | ||
assembledSource += moduleSource; | ||
const injections = module.injections[stage]; | ||
const injections = module.injections?.[stage] || {}; | ||
for (const key in injections) { | ||
@@ -336,10 +336,11 @@ const match = /^(v|f)s:#([\w-]+)$/.exec(key); | ||
const moduleName = module.name.toUpperCase().replace(/[^0-9a-z]/gi, '_'); | ||
return `\ | ||
let source = `\ | ||
// ----- MODULE ${module.name} --------------- | ||
#define MODULE_${moduleName} | ||
${moduleSource}\ | ||
`; | ||
if (stage !== 'wgsl') { | ||
source += `#define MODULE_${moduleName}\n`; | ||
} | ||
source += `${moduleSource}\n`; | ||
return source; | ||
} | ||
@@ -346,0 +347,0 @@ /* |
// luma.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { initializeShaderModules } from "../shader-module/shader-module.js"; | ||
import { initializeShaderModules } from "./shader-module.js"; | ||
/** | ||
@@ -6,0 +6,0 @@ * Takes a list of shader module names and returns a new list of |
@@ -1,2 +0,2 @@ | ||
import type { NumberArray } from '@math.gl/types'; | ||
import type { NumericArray } from '@math.gl/types'; | ||
import { Sampler, Texture } from '@luma.gl/core'; | ||
@@ -7,3 +7,3 @@ import type { UniformFormat } from "../../types.js"; | ||
export type BindingValue = Buffer | Texture | Sampler; | ||
export type UniformValue = number | boolean | Readonly<NumberArray>; | ||
export type UniformValue = number | boolean | Readonly<NumericArray>; | ||
export type UniformInfo = { | ||
@@ -10,0 +10,0 @@ format?: UniformFormat; |
import { ShaderModule } from "../../../lib/shader-module/shader-module.js"; | ||
import type { NumberArray } from "../../../types.js"; | ||
import type { NumericArray } from "../../../types.js"; | ||
export type DirlightOptions = { | ||
lightDirection?: NumberArray; | ||
lightDirection?: NumericArray; | ||
}; | ||
@@ -6,0 +6,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import { NumberArray } from "../../../types.js"; | ||
import { NumericArray } from "../../../types.js"; | ||
/** | ||
@@ -13,5 +13,5 @@ * Props for the picking module, which depending on mode renders picking colors or highlighted item. | ||
/** Set to a picking color to visually highlight that item, or `null` to explicitly clear **/ | ||
highlightedObjectColor?: NumberArray | null; | ||
highlightedObjectColor?: NumericArray | null; | ||
/** Color of visual highlight of "selected" item */ | ||
highlightColor?: NumberArray; | ||
highlightColor?: NumericArray; | ||
/** Color range 0-1 or 0-255 */ | ||
@@ -38,5 +38,5 @@ useFloatColors?: boolean; | ||
/** Set to a picking color to visually highlight that item */ | ||
highlightedObjectColor?: NumberArray; | ||
highlightedObjectColor?: NumericArray; | ||
/** Color of visual highlight of "selected" item */ | ||
highlightColor?: NumberArray; | ||
highlightColor?: NumericArray; | ||
}; | ||
@@ -43,0 +43,0 @@ /** |
@@ -46,2 +46,3 @@ export type GouraudMaterialProps = GouraudMaterialUniforms; | ||
}; | ||
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"; | ||
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"; | ||
@@ -48,0 +49,0 @@ 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"; |
@@ -1,2 +0,2 @@ | ||
export declare const lightingUniforms = "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"; | ||
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"; | ||
//# sourceMappingURL=lighting-uniforms-glsl.d.ts.map |
// luma.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
export const lightingUniforms = /* glsl */ `\ | ||
export const lightingUniformsGLSL = /* glsl */ `\ | ||
precision highp int; | ||
@@ -6,0 +6,0 @@ |
@@ -76,2 +76,3 @@ import type { NumberArray } from '@math.gl/types'; | ||
}; | ||
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"; | ||
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"; | ||
@@ -78,0 +79,0 @@ 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"; |
// luma.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
import { lightingUniforms } from "./lighting-uniforms-glsl.js"; | ||
import { lightingUniformsGLSL } from "./lighting-uniforms-glsl.js"; | ||
import { lightingUniformsWGSL } from "./lighting-uniforms-wgsl.js"; | ||
/** Max number of supported lights (in addition to ambient light */ | ||
@@ -45,4 +46,5 @@ const MAX_LIGHTS = 5; | ||
}, | ||
vs: lightingUniforms, | ||
fs: lightingUniforms, | ||
source: lightingUniformsWGSL, | ||
vs: lightingUniformsGLSL, | ||
fs: lightingUniformsGLSL, | ||
getUniforms | ||
@@ -49,0 +51,0 @@ }; |
@@ -1,8 +0,7 @@ | ||
import type { NumberArray } from '@math.gl/types'; | ||
import type { Vector3Like, TypedArray } from '@math.gl/core'; | ||
export type DirlightProps = { | ||
lightDirection?: NumberArray | [number, number, number]; | ||
lightDirection?: Vector3Like | TypedArray; | ||
}; | ||
export type DirlightUniforms = DirlightProps; | ||
export declare const VS_WGSL = " \nvoid dirlight_setNormal(normal: vec3<f32>) {\n dirlight_vNormal = normalize(normal);\n}\n"; | ||
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"; | ||
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"; | ||
/** | ||
@@ -16,2 +15,3 @@ * Cheap lighting - single directional light, single dot product, one uniform | ||
readonly dependencies: []; | ||
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"; | ||
readonly vs: "out vec3 dirlight_vNormal;\n\nvoid dirlight_setNormal(vec3 normal) {\n dirlight_vNormal = normalize(normal);\n}\n"; | ||
@@ -18,0 +18,0 @@ 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"; |
@@ -5,16 +5,26 @@ // luma.gl | ||
// TODO | ||
export const VS_WGSL = /* WGSL */ `\ | ||
void dirlight_setNormal(normal: vec3<f32>) { | ||
dirlight_vNormal = normalize(normal); | ||
export const SOURCE_WGSL = /* WGSL */ `\ | ||
struct dirlightUniforms { | ||
lightDirection: vec3<f32>, | ||
}; | ||
alias DirlightNormal = vec3<f32>; | ||
struct DirlightInputs { | ||
normal: DirlightNormal, | ||
}; | ||
@binding(1) @group(0) var<uniform> dirlight : dirlightUniforms; | ||
// For vertex | ||
fn dirlight_setNormal(normal: vec3<f32>) -> DirlightNormal { | ||
return normalize(normal); | ||
} | ||
`; | ||
// TODO | ||
export const FS_WGSL = /* WGSL */ `\ | ||
uniform dirlightUniforms { | ||
vec3 lightDirection; | ||
} dirlight; | ||
// Returns color attenuated by angle from light source | ||
fn dirlight_filterColor(color: vec4<f32>, dirlightInputs): vec4<f32> { | ||
const d: float = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection))); | ||
fn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> { | ||
// TODO - fix default light direction | ||
// let lightDirection = dirlight.lightDirection; | ||
let lightDirection = vec3<f32>(1, 1, 1); | ||
let d: f32 = abs(dot(inputs.normal, normalize(lightDirection))); | ||
return vec4<f32>(color.rgb * d, color.a); | ||
@@ -51,2 +61,3 @@ } | ||
dependencies: [], | ||
source: SOURCE_WGSL, | ||
vs: VS_GLSL, | ||
@@ -53,0 +64,0 @@ fs: FS_GLSL, |
@@ -88,2 +88,3 @@ import type { NumberArray } from '@math.gl/types'; | ||
}; | ||
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"; | ||
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"; | ||
@@ -90,0 +91,0 @@ 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"; |
@@ -41,2 +41,3 @@ export type PhongMaterialProps = PhongMaterialUniforms; | ||
}; | ||
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"; | ||
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"; | ||
@@ -46,2 +47,3 @@ 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"; | ||
}]; | ||
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"; | ||
readonly vs: "uniform phongMaterialUniforms {\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n"; | ||
@@ -48,0 +50,0 @@ 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"; |
@@ -5,2 +5,3 @@ // luma.gl | ||
import { lighting } from "../lights/lighting.js"; | ||
import { PHONG_WGSL } from "./phong-shaders-wgsl.js"; | ||
import { PHONG_VS, PHONG_FS } from "./phong-shaders-glsl.js"; | ||
@@ -14,2 +15,3 @@ /** In Phong shading, the normal vector is linearly interpolated across the surface of the polygon from the polygon's vertex normals. */ | ||
// Note these are switched between phong and gouraud | ||
source: PHONG_WGSL, | ||
vs: PHONG_VS, | ||
@@ -16,0 +18,0 @@ fs: PHONG_FS, |
@@ -1,2 +0,2 @@ | ||
import type { NumberArray } from '@math.gl/types'; | ||
import type { NumericArray } from '@math.gl/types'; | ||
/** | ||
@@ -9,3 +9,3 @@ * Calculate WebGL 64 bit float | ||
*/ | ||
export declare function fp64ify(a: number, out?: NumberArray, startIndex?: number): NumberArray; | ||
export declare function fp64ify(a: number, out?: NumericArray, startIndex?: number): NumericArray; | ||
/** | ||
@@ -22,3 +22,3 @@ * Calculate the low part of a WebGL 64 bit float | ||
*/ | ||
export declare function fp64ifyMatrix4(matrix: NumberArray): Float32Array; | ||
export declare function fp64ifyMatrix4(matrix: NumericArray): Float32Array; | ||
//# sourceMappingURL=fp64-utils.d.ts.map |
{ | ||
"name": "@luma.gl/shadertools", | ||
"version": "9.1.0-alpha.10", | ||
"version": "9.1.0-alpha.12", | ||
"description": "Shader module system for luma.gl", | ||
@@ -49,10 +49,10 @@ "type": "module", | ||
"peerDependencies": { | ||
"@luma.gl/core": "^9.0.0-beta" | ||
"@luma.gl/core": "9.1.0-alpha.10" | ||
}, | ||
"dependencies": { | ||
"@math.gl/core": "^4.0.0", | ||
"@math.gl/types": "^4.0.0", | ||
"@math.gl/core": "4.1.0-alpha.3", | ||
"@math.gl/types": "4.1.0-alpha.3", | ||
"wgsl_reflect": "^1.0.1" | ||
}, | ||
"gitHead": "f419cdc284e87b553df60af49d2888ac7dbbf288" | ||
"gitHead": "61b0080d5beb5284b8bdcec5cf59e13cda65295a" | ||
} |
@@ -227,3 +227,3 @@ // luma.gl | ||
// TODO - hack until shadertool modules support WebGPU | ||
const modulesToInject = platformInfo.type !== 'webgpu' ? modules : []; | ||
const modulesToInject = modules; | ||
@@ -234,7 +234,7 @@ for (const module of modulesToInject) { | ||
} | ||
const moduleSource = getShaderModuleSource(module, stage); | ||
const moduleSource = getShaderModuleSource(module, 'wgsl'); | ||
// Add the module source, and a #define that declares it presence | ||
assembledSource += moduleSource; | ||
const injections = module.injections[stage]; | ||
const injections = module.injections?.[stage] || {}; | ||
for (const key in injections) { | ||
@@ -501,10 +501,11 @@ const match = /^(v|f)s:#([\w-]+)$/.exec(key); | ||
const moduleName = module.name.toUpperCase().replace(/[^0-9a-z]/gi, '_'); | ||
return `\ | ||
let source = `\ | ||
// ----- MODULE ${module.name} --------------- | ||
#define MODULE_${moduleName} | ||
${moduleSource}\ | ||
`; | ||
if (stage !== 'wgsl') { | ||
source += `#define MODULE_${moduleName}\n`; | ||
} | ||
source += `${moduleSource}\n`; | ||
return source; | ||
} | ||
@@ -511,0 +512,0 @@ |
@@ -5,4 +5,3 @@ // luma.gl | ||
import {ShaderModule} from './shader-module'; | ||
import {initializeShaderModules} from '../shader-module/shader-module'; | ||
import {ShaderModule, initializeShaderModules} from './shader-module'; | ||
@@ -9,0 +8,0 @@ // import type {ShaderModule} from '../shader-module/shader-module'; |
@@ -5,12 +5,16 @@ // luma.gl | ||
import type {NumberArray} from '@math.gl/types'; | ||
import type {NumericArray} from '@math.gl/types'; | ||
import {Sampler, Texture} from '@luma.gl/core'; | ||
import type {UniformFormat} from '../../types'; | ||
import {PropType, PropValidator} from '../filters/prop-types'; | ||
import {ShaderInjection} from '../shader-assembly/shader-injections'; | ||
import {makePropValidators, getValidatedProperties} from '../filters/prop-types'; | ||
import {normalizeInjections} from '../shader-assembly/shader-injections'; | ||
import { | ||
PropType, | ||
PropValidator, | ||
makePropValidators, | ||
getValidatedProperties | ||
} from '../filters/prop-types'; | ||
import {ShaderInjection, normalizeInjections} from '../shader-assembly/shader-injections'; | ||
export type BindingValue = Buffer | Texture | Sampler; | ||
export type UniformValue = number | boolean | Readonly<NumberArray>; // Float32Array> | Readonly<Int32Array> | Readonly<Uint32Array> | Readonly<number[]>; | ||
export type UniformValue = number | boolean | Readonly<NumericArray>; | ||
// Float32Array> | Readonly<Int32Array> | Readonly<Uint32Array> | Readonly<number[]>; | ||
@@ -17,0 +21,0 @@ export type UniformInfo = { |
@@ -6,3 +6,3 @@ // luma.gl | ||
import {ShaderModule} from '../../../lib/shader-module/shader-module'; | ||
import type {NumberArray} from '../../../types'; | ||
import type {NumericArray} from '../../../types'; | ||
import {project} from '../../project/project'; | ||
@@ -13,3 +13,3 @@ | ||
export type DirlightOptions = { | ||
lightDirection?: NumberArray; | ||
lightDirection?: NumericArray; | ||
}; | ||
@@ -16,0 +16,0 @@ |
@@ -5,3 +5,3 @@ // luma.gl | ||
import {NumberArray} from '../../../types'; | ||
import {NumericArray} from '../../../types'; | ||
import {ShaderModule} from '../../../lib/shader-module/shader-module'; | ||
@@ -23,5 +23,5 @@ | ||
/** Set to a picking color to visually highlight that item, or `null` to explicitly clear **/ | ||
highlightedObjectColor?: NumberArray | null; | ||
highlightedObjectColor?: NumericArray | null; | ||
/** Color of visual highlight of "selected" item */ | ||
highlightColor?: NumberArray; | ||
highlightColor?: NumericArray; | ||
/** Color range 0-1 or 0-255 */ | ||
@@ -49,5 +49,5 @@ useFloatColors?: boolean; | ||
/** Set to a picking color to visually highlight that item */ | ||
highlightedObjectColor?: NumberArray; | ||
highlightedObjectColor?: NumericArray; | ||
/** Color of visual highlight of "selected" item */ | ||
highlightColor?: NumberArray; | ||
highlightColor?: NumericArray; | ||
}; | ||
@@ -54,0 +54,0 @@ |
@@ -5,3 +5,3 @@ // luma.gl | ||
export const lightingUniforms = /* glsl */ `\ | ||
export const lightingUniformsGLSL = /* glsl */ `\ | ||
precision highp int; | ||
@@ -8,0 +8,0 @@ |
@@ -7,3 +7,4 @@ // luma.gl | ||
import {ShaderModule} from '../../../lib/shader-module/shader-module'; | ||
import {lightingUniforms} from './lighting-uniforms-glsl'; | ||
import {lightingUniformsGLSL} from './lighting-uniforms-glsl'; | ||
import {lightingUniformsWGSL} from './lighting-uniforms-wgsl'; | ||
@@ -104,4 +105,5 @@ /** Max number of supported lights (in addition to ambient light */ | ||
}, | ||
vs: lightingUniforms, | ||
fs: lightingUniforms, | ||
source: lightingUniformsWGSL, | ||
vs: lightingUniformsGLSL, | ||
fs: lightingUniformsGLSL, | ||
@@ -108,0 +110,0 @@ getUniforms |
@@ -5,7 +5,7 @@ // luma.gl | ||
import type {NumberArray} from '@math.gl/types'; | ||
import type {Vector3Like, TypedArray} from '@math.gl/core'; | ||
import {ShaderModule} from '../../../lib/shader-module/shader-module'; | ||
export type DirlightProps = { | ||
lightDirection?: NumberArray | [number, number, number]; | ||
lightDirection?: Vector3Like | TypedArray; | ||
}; | ||
@@ -16,17 +16,26 @@ | ||
// TODO | ||
export const VS_WGSL = /* WGSL */ `\ | ||
void dirlight_setNormal(normal: vec3<f32>) { | ||
dirlight_vNormal = normalize(normal); | ||
export const SOURCE_WGSL = /* WGSL */ `\ | ||
struct dirlightUniforms { | ||
lightDirection: vec3<f32>, | ||
}; | ||
alias DirlightNormal = vec3<f32>; | ||
struct DirlightInputs { | ||
normal: DirlightNormal, | ||
}; | ||
@binding(1) @group(0) var<uniform> dirlight : dirlightUniforms; | ||
// For vertex | ||
fn dirlight_setNormal(normal: vec3<f32>) -> DirlightNormal { | ||
return normalize(normal); | ||
} | ||
`; | ||
// TODO | ||
export const FS_WGSL = /* WGSL */ `\ | ||
uniform dirlightUniforms { | ||
vec3 lightDirection; | ||
} dirlight; | ||
// Returns color attenuated by angle from light source | ||
fn dirlight_filterColor(color: vec4<f32>, dirlightInputs): vec4<f32> { | ||
const d: float = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection))); | ||
fn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> { | ||
// TODO - fix default light direction | ||
// let lightDirection = dirlight.lightDirection; | ||
let lightDirection = vec3<f32>(1, 1, 1); | ||
let d: f32 = abs(dot(inputs.normal, normalize(lightDirection))); | ||
return vec4<f32>(color.rgb * d, color.a); | ||
@@ -67,2 +76,3 @@ } | ||
dependencies: [], | ||
source: SOURCE_WGSL, | ||
vs: VS_GLSL, | ||
@@ -69,0 +79,0 @@ fs: FS_GLSL, |
@@ -7,2 +7,3 @@ // luma.gl | ||
import {lighting} from '../lights/lighting'; | ||
import {PHONG_WGSL} from './phong-shaders-wgsl'; | ||
import {PHONG_VS, PHONG_FS} from './phong-shaders-glsl'; | ||
@@ -28,2 +29,3 @@ | ||
// Note these are switched between phong and gouraud | ||
source: PHONG_WGSL, | ||
vs: PHONG_VS, | ||
@@ -30,0 +32,0 @@ fs: PHONG_FS, |
@@ -5,3 +5,3 @@ // luma.gl | ||
import type {NumberArray} from '@math.gl/types'; | ||
import type {NumericArray} from '@math.gl/types'; | ||
@@ -15,3 +15,3 @@ /** | ||
*/ | ||
export function fp64ify(a: number, out: NumberArray = [], startIndex: number = 0): NumberArray { | ||
export function fp64ify(a: number, out: NumericArray = [], startIndex: number = 0): NumericArray { | ||
const hiPart = Math.fround(a); | ||
@@ -38,3 +38,3 @@ const loPart = a - hiPart; | ||
*/ | ||
export function fp64ifyMatrix4(matrix: NumberArray): Float32Array { | ||
export function fp64ifyMatrix4(matrix: NumericArray): Float32Array { | ||
// Transpose the projection matrix to column major for GLSL. | ||
@@ -41,0 +41,0 @@ const matrixFP64 = new Float32Array(32); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1908165
322
37247
+ Added@luma.gl/core@9.1.0-alpha.10(transitive)
+ Added@math.gl/core@4.1.0-alpha.3(transitive)
+ Added@math.gl/types@4.1.0-alpha.3(transitive)
- Removed@luma.gl/core@9.0.27(transitive)
- Removed@math.gl/core@4.1.0(transitive)
Updated@math.gl/core@4.1.0-alpha.3
Updated@math.gl/types@4.1.0-alpha.3