// luma.gl // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors export const LAMBERT_WGSL = /* wgsl */ `\ struct lambertMaterialUniforms { unlit: u32, ambient: f32, diffuse: f32, }; @group(3) @binding(auto) var lambertMaterial : lambertMaterialUniforms; fn lighting_getLightColor(surfaceColor: vec3, light_direction: vec3, normal_worldspace: vec3, color: vec3) -> vec3 { let lambertian: f32 = max(dot(light_direction, normal_worldspace), 0.0); return lambertian * lambertMaterial.diffuse * surfaceColor * color; } fn lighting_getLightColor2(surfaceColor: vec3, cameraPosition: vec3, position_worldspace: vec3, normal_worldspace: vec3) -> vec3 { var lightColor: vec3 = surfaceColor; if (lambertMaterial.unlit != 0u) { return surfaceColor; } if (lighting.enabled == 0) { return lightColor; } lightColor = lambertMaterial.ambient * surfaceColor * lighting.ambientColor; for (var i: i32 = 0; i < lighting.pointLightCount; i++) { let pointLight: PointLight = lighting_getPointLight(i); let light_position_worldspace: vec3 = pointLight.position; let light_direction: vec3 = normalize(light_position_worldspace - position_worldspace); let light_attenuation = getPointLightAttenuation( pointLight, distance(light_position_worldspace, position_worldspace) ); lightColor += lighting_getLightColor( surfaceColor, light_direction, normal_worldspace, pointLight.color / light_attenuation ); } for (var i: i32 = 0; i < lighting.spotLightCount; i++) { let spotLight: SpotLight = lighting_getSpotLight(i); let light_position_worldspace: vec3 = spotLight.position; let light_direction: vec3 = normalize(light_position_worldspace - position_worldspace); let light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace); lightColor += lighting_getLightColor( surfaceColor, light_direction, normal_worldspace, spotLight.color / light_attenuation ); } for (var i: i32 = 0; i < lighting.directionalLightCount; i++) { let directionalLight: DirectionalLight = lighting_getDirectionalLight(i); lightColor += lighting_getLightColor( surfaceColor, -directionalLight.direction, normal_worldspace, directionalLight.color ); } return lightColor; } `;