@luma.gl/shadertools 9.0.17 → 9.0.20
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 +115 -210
- package/dist/dist.min.js +94 -147
- package/dist/index.cjs +106 -150
- package/dist/index.cjs.map +4 -4
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +4 -4
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.js +32 -8
- package/dist/modules/lighting/lights/lighting-uniforms.d.ts +14 -6
- package/dist/modules/lighting/lights/lighting-uniforms.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms.js +46 -35
- package/dist/modules/lighting/phong-material/phong-material.js +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +0 -39
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +7 -64
- package/package.json +2 -2
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -4
- package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +35 -12
- package/src/modules/lighting/lights/lighting-uniforms.ts +71 -42
- package/src/modules/lighting/phong-material/phong-material.ts +1 -1
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +8 -87
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts +0 -42
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts.map +0 -1
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.js +0 -108
- package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +0 -139
package/dist/dist.dev.js
CHANGED
|
@@ -408,13 +408,13 @@ ${moduleSource}
|
|
|
408
408
|
return this.defines;
|
|
409
409
|
}
|
|
410
410
|
// Warn about deprecated uniforms or functions
|
|
411
|
-
checkDeprecations(shaderSource,
|
|
411
|
+
checkDeprecations(shaderSource, log3) {
|
|
412
412
|
this.deprecations.forEach((def) => {
|
|
413
413
|
if (def.regex?.test(shaderSource)) {
|
|
414
414
|
if (def.deprecated) {
|
|
415
|
-
|
|
415
|
+
log3.deprecated(def.old, def.new)();
|
|
416
416
|
} else {
|
|
417
|
-
|
|
417
|
+
log3.removed(def.old, def.new)();
|
|
418
418
|
}
|
|
419
419
|
}
|
|
420
420
|
});
|
|
@@ -752,7 +752,7 @@ precision highp float;
|
|
|
752
752
|
// defines = {},
|
|
753
753
|
hookFunctions = [],
|
|
754
754
|
inject = {},
|
|
755
|
-
log:
|
|
755
|
+
log: log3
|
|
756
756
|
} = options;
|
|
757
757
|
assert(typeof source === "string", "shader source must be a string");
|
|
758
758
|
const coreSource = source;
|
|
@@ -782,8 +782,8 @@ precision highp float;
|
|
|
782
782
|
}
|
|
783
783
|
const modulesToInject = platformInfo.type !== "webgpu" ? modules : [];
|
|
784
784
|
for (const module of modulesToInject) {
|
|
785
|
-
if (
|
|
786
|
-
module.checkDeprecations(coreSource,
|
|
785
|
+
if (log3) {
|
|
786
|
+
module.checkDeprecations(coreSource, log3);
|
|
787
787
|
}
|
|
788
788
|
const moduleSource = module.getModuleSource(stage, "wgsl");
|
|
789
789
|
assembledSource += moduleSource;
|
|
@@ -819,7 +819,7 @@ precision highp float;
|
|
|
819
819
|
hookFunctions = [],
|
|
820
820
|
inject = {},
|
|
821
821
|
prologue = true,
|
|
822
|
-
log:
|
|
822
|
+
log: log3
|
|
823
823
|
} = options;
|
|
824
824
|
assert(typeof source === "string", "shader source must be a string");
|
|
825
825
|
const sourceVersion = language === "glsl" ? getShaderInfo(source).version : -1;
|
|
@@ -877,8 +877,8 @@ ${getApplicationDefines(allDefines)}
|
|
|
877
877
|
}
|
|
878
878
|
}
|
|
879
879
|
for (const module of modules) {
|
|
880
|
-
if (
|
|
881
|
-
module.checkDeprecations(coreSource,
|
|
880
|
+
if (log3) {
|
|
881
|
+
module.checkDeprecations(coreSource, log3);
|
|
882
882
|
}
|
|
883
883
|
const moduleSource = module.getModuleSource(stage);
|
|
884
884
|
assembledSource += moduleSource;
|
|
@@ -5112,28 +5112,51 @@ struct DirectionalLight {
|
|
|
5112
5112
|
|
|
5113
5113
|
uniform lightingUniforms {
|
|
5114
5114
|
int enabled;
|
|
5115
|
-
int
|
|
5115
|
+
int lightType;
|
|
5116
|
+
|
|
5116
5117
|
int directionalLightCount;
|
|
5118
|
+
int pointLightCount;
|
|
5117
5119
|
|
|
5118
5120
|
vec3 ambientColor;
|
|
5119
5121
|
|
|
5120
|
-
|
|
5121
|
-
vec3
|
|
5122
|
-
vec3
|
|
5123
|
-
vec3
|
|
5124
|
-
|
|
5122
|
+
vec3 lightColor0;
|
|
5123
|
+
vec3 lightPosition0;
|
|
5124
|
+
vec3 lightDirection0;
|
|
5125
|
+
vec3 lightAttenuation0;
|
|
5126
|
+
|
|
5127
|
+
vec3 lightColor1;
|
|
5128
|
+
vec3 lightPosition1;
|
|
5129
|
+
vec3 lightDirection1;
|
|
5130
|
+
vec3 lightAttenuation1;
|
|
5125
5131
|
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5132
|
+
vec3 lightColor2;
|
|
5133
|
+
vec3 lightPosition2;
|
|
5134
|
+
vec3 lightDirection2;
|
|
5135
|
+
vec3 lightAttenuation2;
|
|
5129
5136
|
} lighting;
|
|
5130
5137
|
|
|
5131
5138
|
PointLight lighting_getPointLight(int index) {
|
|
5132
|
-
|
|
5139
|
+
switch (index) {
|
|
5140
|
+
case 0:
|
|
5141
|
+
return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);
|
|
5142
|
+
case 1:
|
|
5143
|
+
return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);
|
|
5144
|
+
case 2:
|
|
5145
|
+
default:
|
|
5146
|
+
return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
|
|
5147
|
+
}
|
|
5133
5148
|
}
|
|
5134
5149
|
|
|
5135
5150
|
DirectionalLight lighting_getDirectionalLight(int index) {
|
|
5136
|
-
|
|
5151
|
+
switch (index) {
|
|
5152
|
+
case 0:
|
|
5153
|
+
return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);
|
|
5154
|
+
case 1:
|
|
5155
|
+
return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
|
|
5156
|
+
case 2:
|
|
5157
|
+
default:
|
|
5158
|
+
return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
|
|
5159
|
+
}
|
|
5137
5160
|
}
|
|
5138
5161
|
|
|
5139
5162
|
float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
@@ -5146,7 +5169,8 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
|
5146
5169
|
`;
|
|
5147
5170
|
|
|
5148
5171
|
// src/modules/lighting/lights/lighting-uniforms.ts
|
|
5149
|
-
var
|
|
5172
|
+
var import_core2 = __toESM(require_core(), 1);
|
|
5173
|
+
var MAX_LIGHTS = 3;
|
|
5150
5174
|
var COLOR_FACTOR = 255;
|
|
5151
5175
|
var lighting = {
|
|
5152
5176
|
name: "lighting",
|
|
@@ -5160,31 +5184,44 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
|
5160
5184
|
},
|
|
5161
5185
|
uniformTypes: {
|
|
5162
5186
|
enabled: "i32",
|
|
5163
|
-
ambientLightColor: "vec3<f32>",
|
|
5164
|
-
numberOfLights: "i32",
|
|
5165
|
-
// , array: MAX_LIGHTS,
|
|
5166
5187
|
lightType: "i32",
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5188
|
+
directionalLightCount: "i32",
|
|
5189
|
+
pointLightCount: "i32",
|
|
5190
|
+
ambientLightColor: "vec3<f32>",
|
|
5191
|
+
// TODO define as arrays once we have appropriate uniformTypes
|
|
5192
|
+
lightColor0: "vec3<f32>",
|
|
5193
|
+
lightPosition0: "vec3<f32>",
|
|
5172
5194
|
// TODO - could combine direction and attenuation
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5195
|
+
lightDirection0: "vec3<f32>",
|
|
5196
|
+
lightAttenuation0: "vec3<f32>",
|
|
5197
|
+
lightColor1: "vec3<f32>",
|
|
5198
|
+
lightPosition1: "vec3<f32>",
|
|
5199
|
+
lightDirection1: "vec3<f32>",
|
|
5200
|
+
lightAttenuation1: "vec3<f32>",
|
|
5201
|
+
lightColor2: "vec3<f32>",
|
|
5202
|
+
lightPosition2: "vec3<f32>",
|
|
5203
|
+
lightDirection2: "vec3<f32>",
|
|
5204
|
+
lightAttenuation2: "vec3<f32>"
|
|
5177
5205
|
},
|
|
5178
5206
|
defaultUniforms: {
|
|
5179
5207
|
enabled: 1,
|
|
5180
|
-
ambientLightColor: [0.1, 0.1, 0.1],
|
|
5181
|
-
numberOfLights: 0,
|
|
5182
5208
|
lightType: 0 /* POINT */,
|
|
5183
|
-
|
|
5184
|
-
|
|
5209
|
+
directionalLightCount: 0,
|
|
5210
|
+
pointLightCount: 0,
|
|
5211
|
+
ambientLightColor: [0.1, 0.1, 0.1],
|
|
5212
|
+
lightColor0: [1, 1, 1],
|
|
5213
|
+
lightPosition0: [1, 1, 2],
|
|
5185
5214
|
// TODO - could combine direction and attenuation
|
|
5186
|
-
|
|
5187
|
-
|
|
5215
|
+
lightDirection0: [1, 1, 1],
|
|
5216
|
+
lightAttenuation0: [1, 1, 1],
|
|
5217
|
+
lightColor1: [1, 1, 1],
|
|
5218
|
+
lightPosition1: [1, 1, 2],
|
|
5219
|
+
lightDirection1: [1, 1, 1],
|
|
5220
|
+
lightAttenuation1: [1, 1, 1],
|
|
5221
|
+
lightColor2: [1, 1, 1],
|
|
5222
|
+
lightPosition2: [1, 1, 2],
|
|
5223
|
+
lightDirection2: [1, 1, 1],
|
|
5224
|
+
lightAttenuation2: [1, 1, 1]
|
|
5188
5225
|
}
|
|
5189
5226
|
};
|
|
5190
5227
|
function getUniforms2(props, prevUniforms = {}) {
|
|
@@ -5215,30 +5252,29 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
|
5215
5252
|
pointLights = [],
|
|
5216
5253
|
directionalLights = []
|
|
5217
5254
|
}) {
|
|
5218
|
-
const lightSourceUniforms = {
|
|
5219
|
-
// lightType: new Array(MAX_LIGHTS).fill(0),
|
|
5220
|
-
// lightColor: new Array(MAX_LIGHTS).fill([0, 0, 0]),
|
|
5221
|
-
// lightPosition: new Array(MAX_LIGHTS).fill([0, 0, 0]),
|
|
5222
|
-
// lightDirection: new Array(MAX_LIGHTS).fill([0, 0, 0]),
|
|
5223
|
-
// lightAttenuation: new Array(MAX_LIGHTS).fill([0, 0, 0])
|
|
5224
|
-
};
|
|
5255
|
+
const lightSourceUniforms = {};
|
|
5225
5256
|
lightSourceUniforms.ambientLightColor = convertColor(ambientLight);
|
|
5226
5257
|
let currentLight = 0;
|
|
5227
5258
|
for (const pointLight of pointLights) {
|
|
5228
5259
|
lightSourceUniforms.lightType = 0 /* POINT */;
|
|
5229
|
-
|
|
5230
|
-
lightSourceUniforms
|
|
5231
|
-
lightSourceUniforms
|
|
5260
|
+
const i = currentLight;
|
|
5261
|
+
lightSourceUniforms[`lightColor${i}`] = convertColor(pointLight);
|
|
5262
|
+
lightSourceUniforms[`lightPosition${i}`] = pointLight.position;
|
|
5263
|
+
lightSourceUniforms[`lightAttenuation${i}`] = [pointLight.attenuation || 1, 0, 0];
|
|
5232
5264
|
currentLight++;
|
|
5233
5265
|
}
|
|
5234
5266
|
for (const directionalLight of directionalLights) {
|
|
5235
5267
|
lightSourceUniforms.lightType = 1 /* DIRECTIONAL */;
|
|
5236
|
-
|
|
5237
|
-
lightSourceUniforms
|
|
5238
|
-
lightSourceUniforms
|
|
5268
|
+
const i = currentLight;
|
|
5269
|
+
lightSourceUniforms[`lightColor${i}`] = convertColor(directionalLight);
|
|
5270
|
+
lightSourceUniforms[`lightDirection${i}`] = directionalLight.direction;
|
|
5239
5271
|
currentLight++;
|
|
5240
5272
|
}
|
|
5241
|
-
|
|
5273
|
+
if (currentLight > MAX_LIGHTS) {
|
|
5274
|
+
import_core2.log.warn("MAX_LIGHTS exceeded")();
|
|
5275
|
+
}
|
|
5276
|
+
lightSourceUniforms.directionalLightCount = directionalLights.length;
|
|
5277
|
+
lightSourceUniforms.pointLightCount = pointLights.length;
|
|
5242
5278
|
return lightSourceUniforms;
|
|
5243
5279
|
}
|
|
5244
5280
|
function extractLightTypes(lights2) {
|
|
@@ -5312,17 +5348,17 @@ vec4 dirlight_filterColor(vec4 color) {
|
|
|
5312
5348
|
return uniforms;
|
|
5313
5349
|
}
|
|
5314
5350
|
|
|
5315
|
-
// src/modules/lighting/
|
|
5316
|
-
var
|
|
5317
|
-
uniform
|
|
5351
|
+
// src/modules/lighting/phong-material/phong-shaders-glsl.ts
|
|
5352
|
+
var PHONG_VS = glsl`\
|
|
5353
|
+
uniform phongMaterialUniforms {
|
|
5318
5354
|
uniform float ambient;
|
|
5319
5355
|
uniform float diffuse;
|
|
5320
5356
|
uniform float shininess;
|
|
5321
5357
|
uniform vec3 specularColor;
|
|
5322
5358
|
} material;
|
|
5323
5359
|
`;
|
|
5324
|
-
var
|
|
5325
|
-
uniform
|
|
5360
|
+
var PHONG_FS = glsl`\
|
|
5361
|
+
uniform phongMaterialUniforms {
|
|
5326
5362
|
uniform float ambient;
|
|
5327
5363
|
uniform float diffuse;
|
|
5328
5364
|
uniform float shininess;
|
|
@@ -5344,73 +5380,38 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_d
|
|
|
5344
5380
|
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
5345
5381
|
vec3 lightColor = surfaceColor;
|
|
5346
5382
|
|
|
5347
|
-
if (lighting.enabled) {
|
|
5348
|
-
|
|
5349
|
-
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
5350
|
-
|
|
5351
|
-
if (lighting.lightType == 0) {
|
|
5352
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
5353
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
5354
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
5355
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
5356
|
-
} else if (lighting.lightType == 1) {
|
|
5357
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
5358
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
5359
|
-
}
|
|
5360
|
-
/*
|
|
5361
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
5362
|
-
if (i >= lighting.pointLightCount) {
|
|
5363
|
-
break;
|
|
5364
|
-
}
|
|
5365
|
-
PointLight pointLight = lighting.pointLight[i];
|
|
5366
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
5367
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
5368
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
5369
|
-
}
|
|
5370
|
-
|
|
5371
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
5372
|
-
if (i >= lighting.directionalLightCount) {
|
|
5373
|
-
break;
|
|
5374
|
-
}
|
|
5375
|
-
DirectionalLight directionalLight = lighting.directionalLight[i];
|
|
5376
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
5377
|
-
}
|
|
5378
|
-
*/
|
|
5383
|
+
if (lighting.enabled == 0) {
|
|
5384
|
+
return lightColor;
|
|
5379
5385
|
}
|
|
5380
|
-
return lightColor;
|
|
5381
|
-
}
|
|
5382
|
-
|
|
5383
|
-
vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
5384
|
-
vec3 lightColor = vec3(0, 0, 0);
|
|
5385
|
-
vec3 surfaceColor = vec3(0, 0, 0);
|
|
5386
5386
|
|
|
5387
|
-
|
|
5388
|
-
|
|
5387
|
+
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
5388
|
+
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
5389
5389
|
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5390
|
+
for (int i = 0; i < lighting.pointLightCount; i++) {
|
|
5391
|
+
PointLight pointLight = lighting_getPointLight(i);
|
|
5392
|
+
vec3 light_position_worldspace = pointLight.position;
|
|
5393
|
+
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
5394
|
+
float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));
|
|
5395
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation);
|
|
5396
|
+
}
|
|
5397
5397
|
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
}
|
|
5398
|
+
int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);
|
|
5399
|
+
for (int i = lighting.pointLightCount; i < totalLights; i++) {
|
|
5400
|
+
DirectionalLight directionalLight = lighting_getDirectionalLight(i);
|
|
5401
|
+
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
5403
5402
|
}
|
|
5403
|
+
|
|
5404
5404
|
return lightColor;
|
|
5405
5405
|
}
|
|
5406
|
+
|
|
5406
5407
|
`;
|
|
5407
5408
|
|
|
5408
5409
|
// src/modules/lighting/gouraud-material/gouraud-material.ts
|
|
5409
5410
|
var gouraudMaterial = {
|
|
5410
|
-
name: "
|
|
5411
|
+
name: "gouraudMaterial",
|
|
5411
5412
|
// Note these are switched between phong and gouraud
|
|
5412
|
-
vs:
|
|
5413
|
-
fs:
|
|
5413
|
+
vs: PHONG_FS.replace("phongMaterial", "gouraudMaterial"),
|
|
5414
|
+
fs: PHONG_VS.replace("phongMaterial", "gouraudMaterial"),
|
|
5414
5415
|
defines: {
|
|
5415
5416
|
LIGHTING_VERTEX: 1
|
|
5416
5417
|
},
|
|
@@ -5432,105 +5433,9 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
|
|
|
5432
5433
|
}
|
|
5433
5434
|
};
|
|
5434
5435
|
|
|
5435
|
-
// src/modules/lighting/phong-material/phong-shaders-glsl.ts
|
|
5436
|
-
var PHONG_VS = glsl`\
|
|
5437
|
-
uniform phongMaterialUniforms {
|
|
5438
|
-
uniform float ambient;
|
|
5439
|
-
uniform float diffuse;
|
|
5440
|
-
uniform float shininess;
|
|
5441
|
-
uniform vec3 specularColor;
|
|
5442
|
-
} material;
|
|
5443
|
-
`;
|
|
5444
|
-
var PHONG_FS = glsl`\
|
|
5445
|
-
uniform phongMaterialUniforms {
|
|
5446
|
-
uniform float ambient;
|
|
5447
|
-
uniform float diffuse;
|
|
5448
|
-
uniform float shininess;
|
|
5449
|
-
uniform vec3 specularColor;
|
|
5450
|
-
} material;
|
|
5451
|
-
|
|
5452
|
-
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
|
|
5453
|
-
vec3 halfway_direction = normalize(light_direction + view_direction);
|
|
5454
|
-
float lambertian = dot(light_direction, normal_worldspace);
|
|
5455
|
-
float specular = 0.0;
|
|
5456
|
-
if (lambertian > 0.0) {
|
|
5457
|
-
float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
|
|
5458
|
-
specular = pow(specular_angle, material.shininess);
|
|
5459
|
-
}
|
|
5460
|
-
lambertian = max(lambertian, 0.0);
|
|
5461
|
-
return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
|
|
5462
|
-
}
|
|
5463
|
-
|
|
5464
|
-
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
5465
|
-
vec3 lightColor = surfaceColor;
|
|
5466
|
-
|
|
5467
|
-
if (lighting.enabled == 0) {
|
|
5468
|
-
return lightColor;
|
|
5469
|
-
}
|
|
5470
|
-
|
|
5471
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
5472
|
-
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
5473
|
-
|
|
5474
|
-
if (lighting.lightType == 0) {
|
|
5475
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
5476
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
5477
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
5478
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
5479
|
-
} else if (lighting.lightType == 1) {
|
|
5480
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
5481
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
5482
|
-
}
|
|
5483
|
-
|
|
5484
|
-
/*
|
|
5485
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
5486
|
-
if (i >= lighting.pointLightCount) {
|
|
5487
|
-
break;
|
|
5488
|
-
}
|
|
5489
|
-
PointLight pointLight = lighting.pointLight[i];
|
|
5490
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
5491
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
5492
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
5493
|
-
}
|
|
5494
|
-
|
|
5495
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
5496
|
-
if (i >= lighting.directionalLightCount) {
|
|
5497
|
-
break;
|
|
5498
|
-
}
|
|
5499
|
-
DirectionalLight directionalLight = lighting.directionalLight[i];
|
|
5500
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
5501
|
-
}
|
|
5502
|
-
*/
|
|
5503
|
-
return lightColor;
|
|
5504
|
-
}
|
|
5505
|
-
|
|
5506
|
-
vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
5507
|
-
vec3 lightColor = vec3(0, 0, 0);
|
|
5508
|
-
vec3 surfaceColor = vec3(0, 0, 0);
|
|
5509
|
-
|
|
5510
|
-
if (lighting.enabled == 0) {
|
|
5511
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
5512
|
-
|
|
5513
|
-
switch (lighting.lightType) {
|
|
5514
|
-
case 0:
|
|
5515
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
5516
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
5517
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
5518
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
5519
|
-
break;
|
|
5520
|
-
|
|
5521
|
-
case 1:
|
|
5522
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
5523
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
5524
|
-
break;
|
|
5525
|
-
}
|
|
5526
|
-
}
|
|
5527
|
-
return lightColor;
|
|
5528
|
-
}
|
|
5529
|
-
`;
|
|
5530
|
-
|
|
5531
5436
|
// src/modules/lighting/phong-material/phong-material.ts
|
|
5532
5437
|
var phongMaterial = {
|
|
5533
|
-
name: "
|
|
5438
|
+
name: "phongMaterial",
|
|
5534
5439
|
// Note these are switched between phong and gouraud
|
|
5535
5440
|
vs: PHONG_VS,
|
|
5536
5441
|
fs: PHONG_FS,
|