@luma.gl/shadertools
Advanced tools
Comparing version 9.0.19 to 9.0.20
@@ -5,3 +5,3 @@ // luma.gl | ||
import { lighting } from "../lights/lighting-uniforms.js"; | ||
import { GOURAUD_VS, GOURAUD_FS } from "./gouraud-shaders-glsl.js"; | ||
import { PHONG_VS, PHONG_FS } from "../phong-material/phong-shaders-glsl.js"; | ||
/** In Gouraud shading, color is calculated for each triangle vertex normal, and then color is interpolated colors across the triangle */ | ||
@@ -11,4 +11,4 @@ export const gouraudMaterial = { | ||
// Note these are switched between phong and gouraud | ||
vs: GOURAUD_VS, | ||
fs: GOURAUD_FS, | ||
vs: PHONG_FS.replace('phongMaterial', 'gouraudMaterial'), | ||
fs: PHONG_VS.replace('phongMaterial', 'gouraudMaterial'), | ||
defines: { | ||
@@ -15,0 +15,0 @@ LIGHTING_VERTEX: 1 |
@@ -25,13 +25,37 @@ // luma.gl | ||
vec3 ambientColor; | ||
vec3 lightColor; | ||
vec3 lightPosition; | ||
vec3 lightDirection; | ||
vec3 lightAttenuation; | ||
vec3 lightColor0; | ||
vec3 lightPosition0; | ||
vec3 lightDirection0; | ||
vec3 lightAttenuation0; | ||
vec3 lightColor1; | ||
vec3 lightPosition1; | ||
vec3 lightDirection1; | ||
vec3 lightAttenuation1; | ||
vec3 lightColor2; | ||
vec3 lightPosition2; | ||
vec3 lightDirection2; | ||
vec3 lightAttenuation2; | ||
} lighting; | ||
PointLight lighting_getPointLight(int index) { | ||
return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation); | ||
switch (index) { | ||
case 0: | ||
return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0); | ||
case 1: | ||
return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1); | ||
case 2: | ||
default: | ||
return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2); | ||
} | ||
} | ||
DirectionalLight lighting_getDirectionalLight(int index) { | ||
return DirectionalLight(lighting.lightColor, lighting.lightDirection); | ||
switch (index) { | ||
case 0: | ||
return DirectionalLight(lighting.lightColor0, lighting.lightDirection0); | ||
case 1: | ||
return DirectionalLight(lighting.lightColor1, lighting.lightDirection1); | ||
case 2: | ||
default: | ||
return DirectionalLight(lighting.lightColor2, lighting.lightDirection2); | ||
} | ||
} | ||
float getPointLightAttenuation(PointLight pointLight, float distance) { | ||
@@ -38,0 +62,0 @@ return pointLight.attenuation.x |
@@ -19,3 +19,2 @@ import { ShaderModule } from "../../../lib/shader-module/shader-module.js"; | ||
type: 'directional'; | ||
position: Readonly<NumberArray3>; | ||
direction: Readonly<NumberArray3>; | ||
@@ -41,6 +40,14 @@ color?: Readonly<NumberArray3>; | ||
lightType: number; | ||
lightColor: Readonly<NumberArray3>; | ||
lightPosition: Readonly<NumberArray3>; | ||
lightDirection: Readonly<NumberArray3>; | ||
lightAttenuation: Readonly<NumberArray3>; | ||
lightColor0: Readonly<NumberArray3>; | ||
lightPosition0: Readonly<NumberArray3>; | ||
lightDirection0: Readonly<NumberArray3>; | ||
lightAttenuation0: Readonly<NumberArray3>; | ||
lightColor1: Readonly<NumberArray3>; | ||
lightPosition1: Readonly<NumberArray3>; | ||
lightDirection1: Readonly<NumberArray3>; | ||
lightAttenuation1: Readonly<NumberArray3>; | ||
lightColor2: Readonly<NumberArray3>; | ||
lightPosition2: Readonly<NumberArray3>; | ||
lightDirection2: Readonly<NumberArray3>; | ||
lightAttenuation2: Readonly<NumberArray3>; | ||
}; | ||
@@ -47,0 +54,0 @@ /** UBO ready lighting module */ |
@@ -5,4 +5,5 @@ // luma.gl | ||
import { lightingUniforms } from "./lighting-uniforms-glsl.js"; | ||
import { log } from '@luma.gl/core'; | ||
/** Max number of supported lights (in addition to ambient light */ | ||
const MAX_LIGHTS = 5; | ||
const MAX_LIGHTS = 3; | ||
/** Whether to divide */ | ||
@@ -29,11 +30,20 @@ const COLOR_FACTOR = 255.0; | ||
enabled: 'i32', | ||
lightType: 'i32', // , array: MAX_LIGHTS, | ||
directionalLightCount: 'i32', // , array: MAX_LIGHTS, | ||
pointLightCount: 'i32', // , array: MAX_LIGHTS, | ||
lightType: 'i32', | ||
directionalLightCount: 'i32', | ||
pointLightCount: 'i32', | ||
ambientLightColor: 'vec3<f32>', | ||
lightColor: 'vec3<f32>', // , array: MAX_LIGHTS, | ||
lightPosition: 'vec3<f32>', // , array: MAX_LIGHTS, | ||
// TODO define as arrays once we have appropriate uniformTypes | ||
lightColor0: 'vec3<f32>', | ||
lightPosition0: 'vec3<f32>', | ||
// TODO - could combine direction and attenuation | ||
lightDirection: 'vec3<f32>', // , array: MAX_LIGHTS, | ||
lightAttenuation: 'vec3<f32>' // , array: MAX_LIGHTS}, | ||
lightDirection0: 'vec3<f32>', | ||
lightAttenuation0: 'vec3<f32>', | ||
lightColor1: 'vec3<f32>', | ||
lightPosition1: 'vec3<f32>', | ||
lightDirection1: 'vec3<f32>', | ||
lightAttenuation1: 'vec3<f32>', | ||
lightColor2: 'vec3<f32>', | ||
lightPosition2: 'vec3<f32>', | ||
lightDirection2: 'vec3<f32>', | ||
lightAttenuation2: 'vec3<f32>' | ||
}, | ||
@@ -46,7 +56,15 @@ defaultUniforms: { | ||
ambientLightColor: [0.1, 0.1, 0.1], | ||
lightColor: [1, 1, 1], | ||
lightPosition: [1, 1, 2], | ||
lightColor0: [1, 1, 1], | ||
lightPosition0: [1, 1, 2], | ||
// TODO - could combine direction and attenuation | ||
lightDirection: [1, 1, 1], | ||
lightAttenuation: [1, 1, 1] | ||
lightDirection0: [1, 1, 1], | ||
lightAttenuation0: [1, 1, 1], | ||
lightColor1: [1, 1, 1], | ||
lightPosition1: [1, 1, 2], | ||
lightDirection1: [1, 1, 1], | ||
lightAttenuation1: [1, 1, 1], | ||
lightColor2: [1, 1, 1], | ||
lightPosition2: [1, 1, 2], | ||
lightDirection2: [1, 1, 1], | ||
lightAttenuation2: [1, 1, 1] | ||
} | ||
@@ -85,33 +103,23 @@ }; | ||
function getLightSourceUniforms({ ambientLight, pointLights = [], directionalLights = [] }) { | ||
const lightSourceUniforms = { | ||
// lightType: new Array(MAX_LIGHTS).fill(0), | ||
// lightColor: new Array(MAX_LIGHTS).fill([0, 0, 0]), | ||
// lightPosition: new Array(MAX_LIGHTS).fill([0, 0, 0]), | ||
// lightDirection: new Array(MAX_LIGHTS).fill([0, 0, 0]), | ||
// lightAttenuation: new Array(MAX_LIGHTS).fill([0, 0, 0]) | ||
}; | ||
const lightSourceUniforms = {}; | ||
lightSourceUniforms.ambientLightColor = convertColor(ambientLight); | ||
let currentLight = 0; | ||
for (const pointLight of pointLights) { | ||
// lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.POINT; | ||
// lightSourceUniforms.lightColor[currentLight] = convertColor(pointLight); | ||
// lightSourceUniforms.lightPosition[currentLight] = pointLight.position; | ||
// lightSourceUniforms.lightAttenuation[currentLight] = [pointLight.attenuation || 1, 0, 0]; | ||
lightSourceUniforms.lightType = LIGHT_TYPE.POINT; | ||
lightSourceUniforms.lightColor = convertColor(pointLight); | ||
lightSourceUniforms.lightPosition = pointLight.position; | ||
lightSourceUniforms.lightAttenuation = [pointLight.attenuation || 1, 0, 0]; | ||
const i = currentLight; | ||
lightSourceUniforms[`lightColor${i}`] = convertColor(pointLight); | ||
lightSourceUniforms[`lightPosition${i}`] = pointLight.position; | ||
lightSourceUniforms[`lightAttenuation${i}`] = [pointLight.attenuation || 1, 0, 0]; | ||
currentLight++; | ||
} | ||
for (const directionalLight of directionalLights) { | ||
// lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.DIRECTIONAL; | ||
// lightSourceUniforms.lightColor[currentLight] = convertColor(directionalLight); | ||
// lightSourceUniforms.lightPosition[currentLight] = directionalLight.position; | ||
// lightSourceUniforms.lightDirection[currentLight] = directionalLight.direction; | ||
lightSourceUniforms.lightType = LIGHT_TYPE.DIRECTIONAL; | ||
lightSourceUniforms.lightColor = convertColor(directionalLight); | ||
lightSourceUniforms.lightPosition = directionalLight.position; | ||
lightSourceUniforms.lightDirection = directionalLight.direction; | ||
const i = currentLight; | ||
lightSourceUniforms[`lightColor${i}`] = convertColor(directionalLight); | ||
lightSourceUniforms[`lightDirection${i}`] = directionalLight.direction; | ||
currentLight++; | ||
} | ||
if (currentLight > MAX_LIGHTS) { | ||
log.warn('MAX_LIGHTS exceeded')(); | ||
} | ||
lightSourceUniforms.directionalLightCount = directionalLights.length; | ||
@@ -118,0 +126,0 @@ lightSourceUniforms.pointLightCount = pointLights.length; |
export declare const PHONG_VS: string; | ||
export declare const PHONG_FS: string; | ||
/** | ||
for (int i = 0; i < MAX_LIGHTS; i++) { | ||
if (i >= lighting.pointLightCount) { | ||
break; | ||
} | ||
PointLight pointLight = lighting_getPointLight(i); | ||
vec3 light_position_worldspace = pointLight.position; | ||
vec3 light_direction = normalize(light_position_worldspace - position_worldspace); | ||
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color); | ||
} | ||
for (int i = 0; i < MAX_LIGHTS; i++) { | ||
if (i >= lighting.directionalLightCount) { | ||
break; | ||
} | ||
PointLight pointLight = lighting_getDirectionalLight(i); | ||
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color); | ||
} | ||
} | ||
/** | ||
for (int i = 0; i < MAX_LIGHTS; i++) { | ||
if (i >= lighting.pointLightCount) { | ||
break; | ||
} | ||
PointLight pointLight = lighting_getPointLight(i); | ||
vec3 light_position_worldspace = pointLight.position; | ||
vec3 light_direction = normalize(light_position_worldspace - position_worldspace); | ||
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color); | ||
} | ||
for (int i = 0; i < MAX_LIGHTS; i++) { | ||
if (i >= lighting.directionalLightCount) { | ||
break; | ||
} | ||
PointLight pointLight = lighting_getDirectionalLight(i); | ||
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color); | ||
} | ||
} | ||
*/ | ||
//# sourceMappingURL=phong-shaders-glsl.d.ts.map |
@@ -38,31 +38,13 @@ // luma.gl | ||
lightColor = material.ambient * surfaceColor * lighting.ambientColor; | ||
if (lighting.lightType == 0) { | ||
PointLight pointLight = lighting_getPointLight(0); | ||
for (int i = 0; i < lighting.pointLightCount; i++) { | ||
PointLight pointLight = lighting_getPointLight(i); | ||
vec3 light_position_worldspace = pointLight.position; | ||
vec3 light_direction = normalize(light_position_worldspace - position_worldspace); | ||
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color); | ||
} else if (lighting.lightType == 1) { | ||
DirectionalLight directionalLight = lighting_getDirectionalLight(0); | ||
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color); | ||
float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace)); | ||
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation); | ||
} | ||
return lightColor; | ||
} | ||
vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) { | ||
vec3 lightColor = vec3(0, 0, 0); | ||
vec3 surfaceColor = vec3(0, 0, 0); | ||
if (lighting.enabled == 0) { | ||
return lightColor; | ||
} | ||
vec3 view_direction = normalize(cameraPosition - position_worldspace); | ||
switch (lighting.lightType) { | ||
case 0: | ||
PointLight pointLight = lighting_getPointLight(0); | ||
vec3 light_position_worldspace = pointLight.position; | ||
vec3 light_direction = normalize(light_position_worldspace - position_worldspace); | ||
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color); | ||
break; | ||
case 1: | ||
DirectionalLight directionalLight = lighting_getDirectionalLight(0); | ||
int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount); | ||
for (int i = lighting.pointLightCount; i < totalLights; i++) { | ||
DirectionalLight directionalLight = lighting_getDirectionalLight(i); | ||
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color); | ||
break; | ||
} | ||
@@ -72,41 +54,1 @@ return lightColor; | ||
`; | ||
// TODO - handle multiple lights | ||
/** | ||
for (int i = 0; i < MAX_LIGHTS; i++) { | ||
if (i >= lighting.pointLightCount) { | ||
break; | ||
} | ||
PointLight pointLight = lighting_getPointLight(i); | ||
vec3 light_position_worldspace = pointLight.position; | ||
vec3 light_direction = normalize(light_position_worldspace - position_worldspace); | ||
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color); | ||
} | ||
for (int i = 0; i < MAX_LIGHTS; i++) { | ||
if (i >= lighting.directionalLightCount) { | ||
break; | ||
} | ||
PointLight pointLight = lighting_getDirectionalLight(i); | ||
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color); | ||
} | ||
} | ||
/** | ||
for (int i = 0; i < MAX_LIGHTS; i++) { | ||
if (i >= lighting.pointLightCount) { | ||
break; | ||
} | ||
PointLight pointLight = lighting_getPointLight(i); | ||
vec3 light_position_worldspace = pointLight.position; | ||
vec3 light_direction = normalize(light_position_worldspace - position_worldspace); | ||
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color); | ||
} | ||
for (int i = 0; i < MAX_LIGHTS; i++) { | ||
if (i >= lighting.directionalLightCount) { | ||
break; | ||
} | ||
PointLight pointLight = lighting_getDirectionalLight(i); | ||
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color); | ||
} | ||
} | ||
*/ |
{ | ||
"name": "@luma.gl/shadertools", | ||
"version": "9.0.19", | ||
"version": "9.0.20", | ||
"description": "Shader module system for luma.gl", | ||
@@ -56,3 +56,3 @@ "type": "module", | ||
}, | ||
"gitHead": "5e1ede7bdaf2c9ccdbd167804601537e93dc4225" | ||
"gitHead": "fa850b5d4b398f7168529543a24662bf9df4c68e" | ||
} |
@@ -7,3 +7,3 @@ // luma.gl | ||
import {lighting} from '../lights/lighting-uniforms'; | ||
import {GOURAUD_VS, GOURAUD_FS} from './gouraud-shaders-glsl'; | ||
import {PHONG_VS, PHONG_FS} from '../phong-material/phong-shaders-glsl'; | ||
@@ -24,4 +24,4 @@ export type GouraudMaterialProps = GouraudMaterialUniforms; | ||
// Note these are switched between phong and gouraud | ||
vs: GOURAUD_VS, | ||
fs: GOURAUD_FS, | ||
vs: PHONG_FS.replace('phongMaterial', 'gouraudMaterial'), | ||
fs: PHONG_VS.replace('phongMaterial', 'gouraudMaterial'), | ||
defines: { | ||
@@ -28,0 +28,0 @@ LIGHTING_VERTEX: 1 |
@@ -35,18 +35,40 @@ // luma.gl | ||
vec3 lightColor; | ||
vec3 lightPosition; | ||
vec3 lightDirection; | ||
vec3 lightAttenuation; | ||
vec3 lightColor0; | ||
vec3 lightPosition0; | ||
vec3 lightDirection0; | ||
vec3 lightAttenuation0; | ||
// AmbientLight ambientLight; | ||
// PointLight pointLight[MAX_LIGHTS]; | ||
// DirectionalLight directionalLight[MAX_LIGHTS]; | ||
vec3 lightColor1; | ||
vec3 lightPosition1; | ||
vec3 lightDirection1; | ||
vec3 lightAttenuation1; | ||
vec3 lightColor2; | ||
vec3 lightPosition2; | ||
vec3 lightDirection2; | ||
vec3 lightAttenuation2; | ||
} lighting; | ||
PointLight lighting_getPointLight(int index) { | ||
return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation); | ||
switch (index) { | ||
case 0: | ||
return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0); | ||
case 1: | ||
return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1); | ||
case 2: | ||
default: | ||
return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2); | ||
} | ||
} | ||
DirectionalLight lighting_getDirectionalLight(int index) { | ||
return DirectionalLight(lighting.lightColor, lighting.lightDirection); | ||
switch (index) { | ||
case 0: | ||
return DirectionalLight(lighting.lightColor0, lighting.lightDirection0); | ||
case 1: | ||
return DirectionalLight(lighting.lightColor1, lighting.lightDirection1); | ||
case 2: | ||
default: | ||
return DirectionalLight(lighting.lightColor2, lighting.lightDirection2); | ||
} | ||
} | ||
@@ -53,0 +75,0 @@ |
@@ -8,5 +8,6 @@ // luma.gl | ||
import type {NumberArray3} from '../../../lib/utils/uniform-types'; | ||
import {log} from '@luma.gl/core'; | ||
/** Max number of supported lights (in addition to ambient light */ | ||
const MAX_LIGHTS = 5; | ||
const MAX_LIGHTS = 3; | ||
@@ -42,3 +43,2 @@ /** Whether to divide */ | ||
type: 'directional'; | ||
position: Readonly<NumberArray3>; | ||
direction: Readonly<NumberArray3>; | ||
@@ -66,6 +66,14 @@ color?: Readonly<NumberArray3>; | ||
lightType: number; // []; | ||
lightColor: Readonly<NumberArray3>; // []; | ||
lightPosition: Readonly<NumberArray3>; // []; | ||
lightDirection: Readonly<NumberArray3>; // []; | ||
lightAttenuation: Readonly<NumberArray3>; // []; | ||
lightColor0: Readonly<NumberArray3>; | ||
lightPosition0: Readonly<NumberArray3>; | ||
lightDirection0: Readonly<NumberArray3>; | ||
lightAttenuation0: Readonly<NumberArray3>; | ||
lightColor1: Readonly<NumberArray3>; | ||
lightPosition1: Readonly<NumberArray3>; | ||
lightDirection1: Readonly<NumberArray3>; | ||
lightAttenuation1: Readonly<NumberArray3>; | ||
lightColor2: Readonly<NumberArray3>; | ||
lightPosition2: Readonly<NumberArray3>; | ||
lightDirection2: Readonly<NumberArray3>; | ||
lightAttenuation2: Readonly<NumberArray3>; | ||
}; | ||
@@ -89,13 +97,24 @@ | ||
enabled: 'i32', | ||
lightType: 'i32', // , array: MAX_LIGHTS, | ||
lightType: 'i32', | ||
directionalLightCount: 'i32', // , array: MAX_LIGHTS, | ||
pointLightCount: 'i32', // , array: MAX_LIGHTS, | ||
directionalLightCount: 'i32', | ||
pointLightCount: 'i32', | ||
ambientLightColor: 'vec3<f32>', | ||
lightColor: 'vec3<f32>', // , array: MAX_LIGHTS, | ||
lightPosition: 'vec3<f32>', // , array: MAX_LIGHTS, | ||
// TODO define as arrays once we have appropriate uniformTypes | ||
lightColor0: 'vec3<f32>', | ||
lightPosition0: 'vec3<f32>', | ||
// TODO - could combine direction and attenuation | ||
lightDirection: 'vec3<f32>', // , array: MAX_LIGHTS, | ||
lightAttenuation: 'vec3<f32>' // , array: MAX_LIGHTS}, | ||
lightDirection0: 'vec3<f32>', | ||
lightAttenuation0: 'vec3<f32>', | ||
lightColor1: 'vec3<f32>', | ||
lightPosition1: 'vec3<f32>', | ||
lightDirection1: 'vec3<f32>', | ||
lightAttenuation1: 'vec3<f32>', | ||
lightColor2: 'vec3<f32>', | ||
lightPosition2: 'vec3<f32>', | ||
lightDirection2: 'vec3<f32>', | ||
lightAttenuation2: 'vec3<f32>' | ||
}, | ||
@@ -111,7 +130,16 @@ | ||
ambientLightColor: [0.1, 0.1, 0.1], | ||
lightColor: [1, 1, 1], | ||
lightPosition: [1, 1, 2], | ||
lightColor0: [1, 1, 1], | ||
lightPosition0: [1, 1, 2], | ||
// TODO - could combine direction and attenuation | ||
lightDirection: [1, 1, 1], | ||
lightAttenuation: [1, 1, 1] | ||
lightDirection0: [1, 1, 1], | ||
lightAttenuation0: [1, 1, 1], | ||
lightColor1: [1, 1, 1], | ||
lightPosition1: [1, 1, 2], | ||
lightDirection1: [1, 1, 1], | ||
lightAttenuation1: [1, 1, 1], | ||
lightColor2: [1, 1, 1], | ||
lightPosition2: [1, 1, 2], | ||
lightDirection2: [1, 1, 1], | ||
lightAttenuation2: [1, 1, 1] | ||
} | ||
@@ -166,23 +194,15 @@ }; | ||
}: LightingProps): Partial<LightingUniforms> { | ||
const lightSourceUniforms: Partial<LightingUniforms> = { | ||
// lightType: new Array(MAX_LIGHTS).fill(0), | ||
// lightColor: new Array(MAX_LIGHTS).fill([0, 0, 0]), | ||
// lightPosition: new Array(MAX_LIGHTS).fill([0, 0, 0]), | ||
// lightDirection: new Array(MAX_LIGHTS).fill([0, 0, 0]), | ||
// lightAttenuation: new Array(MAX_LIGHTS).fill([0, 0, 0]) | ||
}; | ||
const lightSourceUniforms: Partial<LightingUniforms> = {}; | ||
lightSourceUniforms.ambientLightColor = convertColor(ambientLight); | ||
let currentLight = 0; | ||
let currentLight: 0 | 1 | 2 = 0; | ||
for (const pointLight of pointLights) { | ||
// lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.POINT; | ||
// lightSourceUniforms.lightColor[currentLight] = convertColor(pointLight); | ||
// lightSourceUniforms.lightPosition[currentLight] = pointLight.position; | ||
// lightSourceUniforms.lightAttenuation[currentLight] = [pointLight.attenuation || 1, 0, 0]; | ||
lightSourceUniforms.lightType = LIGHT_TYPE.POINT; | ||
lightSourceUniforms.lightColor = convertColor(pointLight); | ||
lightSourceUniforms.lightPosition = pointLight.position; | ||
lightSourceUniforms.lightAttenuation = [pointLight.attenuation || 1, 0, 0]; | ||
const i = currentLight as 0 | 1 | 2; | ||
lightSourceUniforms[`lightColor${i}`] = convertColor(pointLight); | ||
lightSourceUniforms[`lightPosition${i}`] = pointLight.position; | ||
lightSourceUniforms[`lightAttenuation${i}`] = [pointLight.attenuation || 1, 0, 0]; | ||
currentLight++; | ||
@@ -192,13 +212,14 @@ } | ||
for (const directionalLight of directionalLights) { | ||
// lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.DIRECTIONAL; | ||
// lightSourceUniforms.lightColor[currentLight] = convertColor(directionalLight); | ||
// lightSourceUniforms.lightPosition[currentLight] = directionalLight.position; | ||
// lightSourceUniforms.lightDirection[currentLight] = directionalLight.direction; | ||
lightSourceUniforms.lightType = LIGHT_TYPE.DIRECTIONAL; | ||
lightSourceUniforms.lightColor = convertColor(directionalLight); | ||
lightSourceUniforms.lightPosition = directionalLight.position; | ||
lightSourceUniforms.lightDirection = directionalLight.direction; | ||
const i = currentLight as 0 | 1 | 2; | ||
lightSourceUniforms[`lightColor${i}`] = convertColor(directionalLight); | ||
lightSourceUniforms[`lightDirection${i}`] = directionalLight.direction; | ||
currentLight++; | ||
} | ||
if (currentLight > MAX_LIGHTS) { | ||
log.warn('MAX_LIGHTS exceeded')(); | ||
} | ||
lightSourceUniforms.directionalLightCount = directionalLights.length; | ||
@@ -205,0 +226,0 @@ lightSourceUniforms.pointLightCount = pointLights.length; |
@@ -46,100 +46,19 @@ // luma.gl | ||
if (lighting.lightType == 0) { | ||
PointLight pointLight = lighting_getPointLight(0); | ||
for (int i = 0; i < lighting.pointLightCount; i++) { | ||
PointLight pointLight = lighting_getPointLight(i); | ||
vec3 light_position_worldspace = pointLight.position; | ||
vec3 light_direction = normalize(light_position_worldspace - position_worldspace); | ||
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color); | ||
} else if (lighting.lightType == 1) { | ||
DirectionalLight directionalLight = lighting_getDirectionalLight(0); | ||
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color); | ||
float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace)); | ||
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation); | ||
} | ||
/* | ||
for (int i = 0; i < MAX_LIGHTS; i++) { | ||
if (i >= lighting.pointLightCount) { | ||
break; | ||
} | ||
PointLight pointLight = lighting.pointLight[i]; | ||
vec3 light_position_worldspace = pointLight.position; | ||
vec3 light_direction = normalize(light_position_worldspace - position_worldspace); | ||
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color); | ||
} | ||
for (int i = 0; i < MAX_LIGHTS; i++) { | ||
if (i >= lighting.directionalLightCount) { | ||
break; | ||
} | ||
DirectionalLight directionalLight = lighting.directionalLight[i]; | ||
int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount); | ||
for (int i = lighting.pointLightCount; i < totalLights; i++) { | ||
DirectionalLight directionalLight = lighting_getDirectionalLight(i); | ||
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color); | ||
} | ||
*/ | ||
return lightColor; | ||
} | ||
vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) { | ||
vec3 lightColor = vec3(0, 0, 0); | ||
vec3 surfaceColor = vec3(0, 0, 0); | ||
if (lighting.enabled == 0) { | ||
return lightColor; | ||
} | ||
vec3 view_direction = normalize(cameraPosition - position_worldspace); | ||
switch (lighting.lightType) { | ||
case 0: | ||
PointLight pointLight = lighting_getPointLight(0); | ||
vec3 light_position_worldspace = pointLight.position; | ||
vec3 light_direction = normalize(light_position_worldspace - position_worldspace); | ||
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color); | ||
break; | ||
case 1: | ||
DirectionalLight directionalLight = lighting_getDirectionalLight(0); | ||
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color); | ||
break; | ||
} | ||
return lightColor; | ||
} | ||
`; | ||
// TODO - handle multiple lights | ||
/** | ||
for (int i = 0; i < MAX_LIGHTS; i++) { | ||
if (i >= lighting.pointLightCount) { | ||
break; | ||
} | ||
PointLight pointLight = lighting_getPointLight(i); | ||
vec3 light_position_worldspace = pointLight.position; | ||
vec3 light_direction = normalize(light_position_worldspace - position_worldspace); | ||
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color); | ||
} | ||
for (int i = 0; i < MAX_LIGHTS; i++) { | ||
if (i >= lighting.directionalLightCount) { | ||
break; | ||
} | ||
PointLight pointLight = lighting_getDirectionalLight(i); | ||
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color); | ||
} | ||
} | ||
/** | ||
for (int i = 0; i < MAX_LIGHTS; i++) { | ||
if (i >= lighting.pointLightCount) { | ||
break; | ||
} | ||
PointLight pointLight = lighting_getPointLight(i); | ||
vec3 light_position_worldspace = pointLight.position; | ||
vec3 light_direction = normalize(light_position_worldspace - position_worldspace); | ||
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color); | ||
} | ||
for (int i = 0; i < MAX_LIGHTS; i++) { | ||
if (i >= lighting.directionalLightCount) { | ||
break; | ||
} | ||
PointLight pointLight = lighting_getDirectionalLight(i); | ||
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color); | ||
} | ||
} | ||
*/ |
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
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
1529027
322
33210