// luma.gl // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors import { glsl } from "../../../lib/glsl-utils/highlight.js"; // TODO export const VS_WGSL = /* WGSL */ `\ void dirlight_setNormal(normal: vec3) { dirlight_vNormal = 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, dirlightInputs): vec4 { const d: float = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection))); return vec4(color.rgb * d, color.a); } `; const VS_GLSL = `\ out vec3 dirlight_vNormal; void dirlight_setNormal(vec3 normal) { dirlight_vNormal = normalize(normal); } `; const FS_GLSL = `\ uniform dirlightUniforms { vec3 lightDirection; } dirlight; in vec3 dirlight_vNormal; vec4 dirlight_filterColor(vec4 color) { float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection))); return vec4(color.rgb * d, color.a); } `; /** * Cheap lighting - single directional light, single dot product, one uniform */ export const dirlight = { name: 'dirlight', dependencies: [], vs: VS_GLSL, fs: FS_GLSL, // fragmentInputs: [ // { // name: 'dirlight_vNormal', // type: 'vec3' // } // ], uniformTypes: { lightDirection: 'vec3' }, defaultUniforms: { lightDirection: [1, 1, 2] }, getUniforms }; function getUniforms(opts = dirlight.defaultUniforms) { const uniforms = {}; if (opts.lightDirection) { // eslint-disable-next-line camelcase uniforms.dirlight_uLightDirection = opts.lightDirection; } return uniforms; }