@luma.gl/shadertools 9.0.17 → 9.0.19
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 +87 -75
- package/dist/dist.min.js +21 -18
- package/dist/index.cjs +31 -24
- package/dist/index.cjs.map +2 -2
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.js +15 -13
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.js +3 -3
- package/dist/modules/lighting/lights/lighting-uniforms.d.ts +2 -1
- package/dist/modules/lighting/lights/lighting-uniforms.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms.js +8 -5
- package/dist/modules/lighting/phong-material/phong-material.js +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +2 -1
- package/package.json +2 -2
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +1 -1
- package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +57 -52
- package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +4 -3
- package/src/modules/lighting/lights/lighting-uniforms.ts +14 -6
- package/src/modules/lighting/phong-material/phong-material.ts +1 -1
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +16 -14
package/dist/dist.dev.js
CHANGED
|
@@ -5112,15 +5112,16 @@ 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
|
-
int lightType;
|
|
5121
5122
|
vec3 lightColor;
|
|
5122
|
-
vec3 lightDirection;
|
|
5123
5123
|
vec3 lightPosition;
|
|
5124
|
+
vec3 lightDirection;
|
|
5124
5125
|
vec3 lightAttenuation;
|
|
5125
5126
|
|
|
5126
5127
|
// AmbientLight ambientLight;
|
|
@@ -5160,11 +5161,13 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
|
5160
5161
|
},
|
|
5161
5162
|
uniformTypes: {
|
|
5162
5163
|
enabled: "i32",
|
|
5163
|
-
ambientLightColor: "vec3<f32>",
|
|
5164
|
-
numberOfLights: "i32",
|
|
5165
|
-
// , array: MAX_LIGHTS,
|
|
5166
5164
|
lightType: "i32",
|
|
5167
5165
|
// , array: MAX_LIGHTS,
|
|
5166
|
+
directionalLightCount: "i32",
|
|
5167
|
+
// , array: MAX_LIGHTS,
|
|
5168
|
+
pointLightCount: "i32",
|
|
5169
|
+
// , array: MAX_LIGHTS,
|
|
5170
|
+
ambientLightColor: "vec3<f32>",
|
|
5168
5171
|
lightColor: "vec3<f32>",
|
|
5169
5172
|
// , array: MAX_LIGHTS,
|
|
5170
5173
|
lightPosition: "vec3<f32>",
|
|
@@ -5177,9 +5180,10 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
|
5177
5180
|
},
|
|
5178
5181
|
defaultUniforms: {
|
|
5179
5182
|
enabled: 1,
|
|
5180
|
-
ambientLightColor: [0.1, 0.1, 0.1],
|
|
5181
|
-
numberOfLights: 0,
|
|
5182
5183
|
lightType: 0 /* POINT */,
|
|
5184
|
+
directionalLightCount: 0,
|
|
5185
|
+
pointLightCount: 0,
|
|
5186
|
+
ambientLightColor: [0.1, 0.1, 0.1],
|
|
5183
5187
|
lightColor: [1, 1, 1],
|
|
5184
5188
|
lightPosition: [1, 1, 2],
|
|
5185
5189
|
// TODO - could combine direction and attenuation
|
|
@@ -5238,7 +5242,8 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
|
5238
5242
|
lightSourceUniforms.lightDirection = directionalLight.direction;
|
|
5239
5243
|
currentLight++;
|
|
5240
5244
|
}
|
|
5241
|
-
lightSourceUniforms.
|
|
5245
|
+
lightSourceUniforms.directionalLightCount = directionalLights.length;
|
|
5246
|
+
lightSourceUniforms.pointLightCount = pointLights.length;
|
|
5242
5247
|
return lightSourceUniforms;
|
|
5243
5248
|
}
|
|
5244
5249
|
function extractLightTypes(lights2) {
|
|
@@ -5314,15 +5319,7 @@ vec4 dirlight_filterColor(vec4 color) {
|
|
|
5314
5319
|
|
|
5315
5320
|
// src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts
|
|
5316
5321
|
var GOURAUD_VS = glsl`\
|
|
5317
|
-
uniform
|
|
5318
|
-
uniform float ambient;
|
|
5319
|
-
uniform float diffuse;
|
|
5320
|
-
uniform float shininess;
|
|
5321
|
-
uniform vec3 specularColor;
|
|
5322
|
-
} material;
|
|
5323
|
-
`;
|
|
5324
|
-
var GOURAUD_FS = glsl`\
|
|
5325
|
-
uniform materialUniforms {
|
|
5322
|
+
uniform gouraudMaterialUniforms {
|
|
5326
5323
|
uniform float ambient;
|
|
5327
5324
|
uniform float diffuse;
|
|
5328
5325
|
uniform float shininess;
|
|
@@ -5344,39 +5341,41 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_d
|
|
|
5344
5341
|
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
5345
5342
|
vec3 lightColor = surfaceColor;
|
|
5346
5343
|
|
|
5347
|
-
if (lighting.enabled) {
|
|
5348
|
-
|
|
5349
|
-
|
|
5344
|
+
if (lighting.enabled == 0) {
|
|
5345
|
+
return lightColor;
|
|
5346
|
+
}
|
|
5350
5347
|
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
5368
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
5348
|
+
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
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;
|
|
5369
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
5370
|
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
}
|
|
5375
|
-
DirectionalLight directionalLight = lighting.directionalLight[i];
|
|
5376
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
5371
|
+
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
5372
|
+
if (i >= lighting.directionalLightCount) {
|
|
5373
|
+
break;
|
|
5377
5374
|
}
|
|
5378
|
-
|
|
5375
|
+
DirectionalLight directionalLight = lighting.directionalLight[i];
|
|
5376
|
+
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
5379
5377
|
}
|
|
5378
|
+
*/
|
|
5380
5379
|
return lightColor;
|
|
5381
5380
|
}
|
|
5382
5381
|
|
|
@@ -5384,30 +5383,41 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
|
|
|
5384
5383
|
vec3 lightColor = vec3(0, 0, 0);
|
|
5385
5384
|
vec3 surfaceColor = vec3(0, 0, 0);
|
|
5386
5385
|
|
|
5387
|
-
if (lighting.enabled) {
|
|
5388
|
-
|
|
5386
|
+
if (lighting.enabled == 0) {
|
|
5387
|
+
return lightColor;
|
|
5388
|
+
}
|
|
5389
5389
|
|
|
5390
|
-
|
|
5391
|
-
case 0:
|
|
5392
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
5393
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
5394
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
5395
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
5396
|
-
break;
|
|
5390
|
+
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
5397
5391
|
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5392
|
+
switch (lighting.lightType) {
|
|
5393
|
+
case 0:
|
|
5394
|
+
PointLight pointLight = lighting_getPointLight(0);
|
|
5395
|
+
vec3 light_position_worldspace = pointLight.position;
|
|
5396
|
+
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
5397
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
5398
|
+
break;
|
|
5399
|
+
|
|
5400
|
+
case 1:
|
|
5401
|
+
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
5402
|
+
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
5403
|
+
break;
|
|
5403
5404
|
}
|
|
5405
|
+
|
|
5404
5406
|
return lightColor;
|
|
5405
5407
|
}
|
|
5408
|
+
`;
|
|
5409
|
+
var GOURAUD_FS = glsl`\
|
|
5410
|
+
uniform gouraudMaterialUniforms {
|
|
5411
|
+
uniform float ambient;
|
|
5412
|
+
uniform float diffuse;
|
|
5413
|
+
uniform float shininess;
|
|
5414
|
+
uniform vec3 specularColor;
|
|
5415
|
+
} material;
|
|
5406
5416
|
`;
|
|
5407
5417
|
|
|
5408
5418
|
// src/modules/lighting/gouraud-material/gouraud-material.ts
|
|
5409
5419
|
var gouraudMaterial = {
|
|
5410
|
-
name: "
|
|
5420
|
+
name: "gouraudMaterial",
|
|
5411
5421
|
// Note these are switched between phong and gouraud
|
|
5412
5422
|
vs: GOURAUD_VS,
|
|
5413
5423
|
fs: GOURAUD_FS,
|
|
@@ -5508,21 +5518,23 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
|
|
|
5508
5518
|
vec3 surfaceColor = vec3(0, 0, 0);
|
|
5509
5519
|
|
|
5510
5520
|
if (lighting.enabled == 0) {
|
|
5511
|
-
|
|
5521
|
+
return lightColor;
|
|
5522
|
+
}
|
|
5512
5523
|
|
|
5513
|
-
|
|
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;
|
|
5524
|
+
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
5520
5525
|
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
+
switch (lighting.lightType) {
|
|
5527
|
+
case 0:
|
|
5528
|
+
PointLight pointLight = lighting_getPointLight(0);
|
|
5529
|
+
vec3 light_position_worldspace = pointLight.position;
|
|
5530
|
+
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
5531
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
5532
|
+
break;
|
|
5533
|
+
|
|
5534
|
+
case 1:
|
|
5535
|
+
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
5536
|
+
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
5537
|
+
break;
|
|
5526
5538
|
}
|
|
5527
5539
|
return lightColor;
|
|
5528
5540
|
}
|
|
@@ -5530,7 +5542,7 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
|
|
|
5530
5542
|
|
|
5531
5543
|
// src/modules/lighting/phong-material/phong-material.ts
|
|
5532
5544
|
var phongMaterial = {
|
|
5533
|
-
name: "
|
|
5545
|
+
name: "phongMaterial",
|
|
5534
5546
|
// Note these are switched between phong and gouraud
|
|
5535
5547
|
vs: PHONG_VS,
|
|
5536
5548
|
fs: PHONG_FS,
|
package/dist/dist.min.js
CHANGED
|
@@ -316,13 +316,13 @@ vec3 direction;
|
|
|
316
316
|
};
|
|
317
317
|
uniform lightingUniforms {
|
|
318
318
|
int enabled;
|
|
319
|
-
int
|
|
319
|
+
int lightType;
|
|
320
320
|
int directionalLightCount;
|
|
321
|
+
int pointLightCount;
|
|
321
322
|
vec3 ambientColor;
|
|
322
|
-
int lightType;
|
|
323
323
|
vec3 lightColor;
|
|
324
|
-
vec3 lightDirection;
|
|
325
324
|
vec3 lightPosition;
|
|
325
|
+
vec3 lightDirection;
|
|
326
326
|
vec3 lightAttenuation;
|
|
327
327
|
} lighting;
|
|
328
328
|
PointLight lighting_getPointLight(int index) {
|
|
@@ -336,7 +336,7 @@ return pointLight.attenuation.x
|
|
|
336
336
|
+ pointLight.attenuation.y * distance
|
|
337
337
|
+ pointLight.attenuation.z * distance * distance;
|
|
338
338
|
}
|
|
339
|
-
`;var Oo=5,Uo=255,be;(function(n){n[n.POINT=0]="POINT",n[n.DIRECTIONAL=1]="DIRECTIONAL"})(be||(be={}));var Q={name:"lighting",vs:Gt,fs:Gt,getUniforms(n,e){return zo(n)},defines:{MAX_LIGHTS:Oo},uniformTypes:{enabled:"i32",
|
|
339
|
+
`;var Oo=5,Uo=255,be;(function(n){n[n.POINT=0]="POINT",n[n.DIRECTIONAL=1]="DIRECTIONAL"})(be||(be={}));var Q={name:"lighting",vs:Gt,fs:Gt,getUniforms(n,e){return zo(n)},defines:{MAX_LIGHTS:Oo},uniformTypes:{enabled:"i32",lightType:"i32",directionalLightCount:"i32",pointLightCount:"i32",ambientLightColor:"vec3<f32>",lightColor:"vec3<f32>",lightPosition:"vec3<f32>",lightDirection:"vec3<f32>",lightAttenuation:"vec3<f32>"},defaultUniforms:{enabled:1,lightType:be.POINT,directionalLightCount:0,pointLightCount:0,ambientLightColor:[.1,.1,.1],lightColor:[1,1,1],lightPosition:[1,1,2],lightDirection:[1,1,1],lightAttenuation:[1,1,1]}};function zo(n,e={}){if(n=n&&{...n},!n)return{...Q.defaultUniforms};n.lights&&(n={...n,...Yo(n.lights),lights:void 0});let{ambientLight:t,pointLights:r,directionalLights:o}=n||{};if(!(t||r&&r.length>0||o&&o.length>0))return{...Q.defaultUniforms,enabled:0};let a={...Q.defaultUniforms,...e,...Do({ambientLight:t,pointLights:r,directionalLights:o})};return n.enabled!==void 0&&(a.enabled=n.enabled?1:0),a}function Do({ambientLight:n,pointLights:e=[],directionalLights:t=[]}){let r={};r.ambientLightColor=Ht(n);let o=0;for(let i of e)r.lightType=be.POINT,r.lightColor=Ht(i),r.lightPosition=i.position,r.lightAttenuation=[i.attenuation||1,0,0],o++;for(let i of t)r.lightType=be.DIRECTIONAL,r.lightColor=Ht(i),r.lightPosition=i.position,r.lightDirection=i.direction,o++;return r.directionalLightCount=t.length,r.pointLightCount=e.length,r}function Yo(n){let e={pointLights:[],directionalLights:[]};for(let t of n||[])switch(t.type){case"ambient":e.ambientLight=t;break;case"directional":e.directionalLights?.push(t);break;case"point":e.pointLights?.push(t);break;default:}return e}function Ht(n={}){let{color:e=[0,0,0],intensity:t=1}=n;return e.map(r=>r*t/Uo)}var Xo=`out vec3 dirlight_vNormal;
|
|
340
340
|
void dirlight_setNormal(vec3 normal) {
|
|
341
341
|
dirlight_vNormal = normalize(normal);
|
|
342
342
|
}
|
|
@@ -348,13 +348,7 @@ vec4 dirlight_filterColor(vec4 color) {
|
|
|
348
348
|
float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));
|
|
349
349
|
return vec4(color.rgb * d, color.a);
|
|
350
350
|
}
|
|
351
|
-
`,Wt={name:"dirlight",dependencies:[],vs:Xo,fs:Bo,uniformTypes:{lightDirection:"vec3<f32>"},defaultUniforms:{lightDirection:[1,1,2]},getUniforms:Qo};function Qo(n=Wt.defaultUniforms){let e={};return n.lightDirection&&(e.dirlight_uLightDirection=n.lightDirection),e}var Gn=`uniform
|
|
352
|
-
uniform float ambient;
|
|
353
|
-
uniform float diffuse;
|
|
354
|
-
uniform float shininess;
|
|
355
|
-
uniform vec3 specularColor;
|
|
356
|
-
} material;
|
|
357
|
-
`,Hn=`uniform materialUniforms {
|
|
351
|
+
`,Wt={name:"dirlight",dependencies:[],vs:Xo,fs:Bo,uniformTypes:{lightDirection:"vec3<f32>"},defaultUniforms:{lightDirection:[1,1,2]},getUniforms:Qo};function Qo(n=Wt.defaultUniforms){let e={};return n.lightDirection&&(e.dirlight_uLightDirection=n.lightDirection),e}var Gn=`uniform gouraudMaterialUniforms {
|
|
358
352
|
uniform float ambient;
|
|
359
353
|
uniform float diffuse;
|
|
360
354
|
uniform float shininess;
|
|
@@ -373,7 +367,9 @@ return (lambertian * material.diffuse * surfaceColor + specular * material.specu
|
|
|
373
367
|
}
|
|
374
368
|
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
375
369
|
vec3 lightColor = surfaceColor;
|
|
376
|
-
if (lighting.enabled) {
|
|
370
|
+
if (lighting.enabled == 0) {
|
|
371
|
+
return lightColor;
|
|
372
|
+
}
|
|
377
373
|
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
378
374
|
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
379
375
|
if (lighting.lightType == 0) {
|
|
@@ -385,13 +381,14 @@ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_directi
|
|
|
385
381
|
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
386
382
|
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
387
383
|
}
|
|
388
|
-
}
|
|
389
384
|
return lightColor;
|
|
390
385
|
}
|
|
391
386
|
vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
392
387
|
vec3 lightColor = vec3(0, 0, 0);
|
|
393
388
|
vec3 surfaceColor = vec3(0, 0, 0);
|
|
394
|
-
if (lighting.enabled) {
|
|
389
|
+
if (lighting.enabled == 0) {
|
|
390
|
+
return lightColor;
|
|
391
|
+
}
|
|
395
392
|
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
396
393
|
switch (lighting.lightType) {
|
|
397
394
|
case 0:
|
|
@@ -405,10 +402,15 @@ DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
|
405
402
|
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
406
403
|
break;
|
|
407
404
|
}
|
|
408
|
-
}
|
|
409
405
|
return lightColor;
|
|
410
406
|
}
|
|
411
|
-
|
|
407
|
+
`,Hn=`uniform gouraudMaterialUniforms {
|
|
408
|
+
uniform float ambient;
|
|
409
|
+
uniform float diffuse;
|
|
410
|
+
uniform float shininess;
|
|
411
|
+
uniform vec3 specularColor;
|
|
412
|
+
} material;
|
|
413
|
+
`;var jt={name:"gouraudMaterial",vs:Gn,fs:Hn,defines:{LIGHTING_VERTEX:1},dependencies:[Q],uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(n){return{...jt.defaultUniforms,...n}}};var Wn=`uniform phongMaterialUniforms {
|
|
412
414
|
uniform float ambient;
|
|
413
415
|
uniform float diffuse;
|
|
414
416
|
uniform float shininess;
|
|
@@ -453,6 +455,8 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
|
|
|
453
455
|
vec3 lightColor = vec3(0, 0, 0);
|
|
454
456
|
vec3 surfaceColor = vec3(0, 0, 0);
|
|
455
457
|
if (lighting.enabled == 0) {
|
|
458
|
+
return lightColor;
|
|
459
|
+
}
|
|
456
460
|
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
457
461
|
switch (lighting.lightType) {
|
|
458
462
|
case 0:
|
|
@@ -466,10 +470,9 @@ DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
|
466
470
|
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
467
471
|
break;
|
|
468
472
|
}
|
|
469
|
-
}
|
|
470
473
|
return lightColor;
|
|
471
474
|
}
|
|
472
|
-
`;var $t={name:"
|
|
475
|
+
`;var $t={name:"phongMaterial",vs:Wn,fs:jn,defines:{LIGHTING_FRAGMENT:1},dependencies:[Q],uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(n){return{...$t.defaultUniforms,...n}}};var $n=`uniform projection {
|
|
473
476
|
mat4 u_MVPMatrix;
|
|
474
477
|
mat4 u_ModelMatrix;
|
|
475
478
|
mat4 u_NormalMatrix;
|
package/dist/index.cjs
CHANGED
|
@@ -1523,13 +1523,13 @@ vec3 direction;
|
|
|
1523
1523
|
};
|
|
1524
1524
|
uniform lightingUniforms {
|
|
1525
1525
|
int enabled;
|
|
1526
|
-
int
|
|
1526
|
+
int lightType;
|
|
1527
1527
|
int directionalLightCount;
|
|
1528
|
+
int pointLightCount;
|
|
1528
1529
|
vec3 ambientColor;
|
|
1529
|
-
int lightType;
|
|
1530
1530
|
vec3 lightColor;
|
|
1531
|
-
vec3 lightDirection;
|
|
1532
1531
|
vec3 lightPosition;
|
|
1532
|
+
vec3 lightDirection;
|
|
1533
1533
|
vec3 lightAttenuation;
|
|
1534
1534
|
} lighting;
|
|
1535
1535
|
PointLight lighting_getPointLight(int index) {
|
|
@@ -1565,11 +1565,13 @@ var lighting = {
|
|
|
1565
1565
|
},
|
|
1566
1566
|
uniformTypes: {
|
|
1567
1567
|
enabled: "i32",
|
|
1568
|
-
ambientLightColor: "vec3<f32>",
|
|
1569
|
-
numberOfLights: "i32",
|
|
1570
|
-
// , array: MAX_LIGHTS,
|
|
1571
1568
|
lightType: "i32",
|
|
1572
1569
|
// , array: MAX_LIGHTS,
|
|
1570
|
+
directionalLightCount: "i32",
|
|
1571
|
+
// , array: MAX_LIGHTS,
|
|
1572
|
+
pointLightCount: "i32",
|
|
1573
|
+
// , array: MAX_LIGHTS,
|
|
1574
|
+
ambientLightColor: "vec3<f32>",
|
|
1573
1575
|
lightColor: "vec3<f32>",
|
|
1574
1576
|
// , array: MAX_LIGHTS,
|
|
1575
1577
|
lightPosition: "vec3<f32>",
|
|
@@ -1582,9 +1584,10 @@ var lighting = {
|
|
|
1582
1584
|
},
|
|
1583
1585
|
defaultUniforms: {
|
|
1584
1586
|
enabled: 1,
|
|
1585
|
-
ambientLightColor: [0.1, 0.1, 0.1],
|
|
1586
|
-
numberOfLights: 0,
|
|
1587
1587
|
lightType: LIGHT_TYPE.POINT,
|
|
1588
|
+
directionalLightCount: 0,
|
|
1589
|
+
pointLightCount: 0,
|
|
1590
|
+
ambientLightColor: [0.1, 0.1, 0.1],
|
|
1588
1591
|
lightColor: [1, 1, 1],
|
|
1589
1592
|
lightPosition: [1, 1, 2],
|
|
1590
1593
|
// TODO - could combine direction and attenuation
|
|
@@ -1639,7 +1642,8 @@ function getLightSourceUniforms({ ambientLight, pointLights = [], directionalLig
|
|
|
1639
1642
|
lightSourceUniforms.lightDirection = directionalLight.direction;
|
|
1640
1643
|
currentLight++;
|
|
1641
1644
|
}
|
|
1642
|
-
lightSourceUniforms.
|
|
1645
|
+
lightSourceUniforms.directionalLightCount = directionalLights.length;
|
|
1646
|
+
lightSourceUniforms.pointLightCount = pointLights.length;
|
|
1643
1647
|
return lightSourceUniforms;
|
|
1644
1648
|
}
|
|
1645
1649
|
function extractLightTypes(lights2) {
|
|
@@ -1709,14 +1713,7 @@ function getUniforms3(opts = dirlight.defaultUniforms) {
|
|
|
1709
1713
|
}
|
|
1710
1714
|
|
|
1711
1715
|
// dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.js
|
|
1712
|
-
var GOURAUD_VS = `uniform
|
|
1713
|
-
uniform float ambient;
|
|
1714
|
-
uniform float diffuse;
|
|
1715
|
-
uniform float shininess;
|
|
1716
|
-
uniform vec3 specularColor;
|
|
1717
|
-
} material;
|
|
1718
|
-
`;
|
|
1719
|
-
var GOURAUD_FS = `uniform materialUniforms {
|
|
1716
|
+
var GOURAUD_VS = `uniform gouraudMaterialUniforms {
|
|
1720
1717
|
uniform float ambient;
|
|
1721
1718
|
uniform float diffuse;
|
|
1722
1719
|
uniform float shininess;
|
|
@@ -1735,7 +1732,9 @@ return (lambertian * material.diffuse * surfaceColor + specular * material.specu
|
|
|
1735
1732
|
}
|
|
1736
1733
|
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
1737
1734
|
vec3 lightColor = surfaceColor;
|
|
1738
|
-
if (lighting.enabled) {
|
|
1735
|
+
if (lighting.enabled == 0) {
|
|
1736
|
+
return lightColor;
|
|
1737
|
+
}
|
|
1739
1738
|
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
1740
1739
|
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
1741
1740
|
if (lighting.lightType == 0) {
|
|
@@ -1747,13 +1746,14 @@ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_directi
|
|
|
1747
1746
|
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
1748
1747
|
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
1749
1748
|
}
|
|
1750
|
-
}
|
|
1751
1749
|
return lightColor;
|
|
1752
1750
|
}
|
|
1753
1751
|
vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
1754
1752
|
vec3 lightColor = vec3(0, 0, 0);
|
|
1755
1753
|
vec3 surfaceColor = vec3(0, 0, 0);
|
|
1756
|
-
if (lighting.enabled) {
|
|
1754
|
+
if (lighting.enabled == 0) {
|
|
1755
|
+
return lightColor;
|
|
1756
|
+
}
|
|
1757
1757
|
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
1758
1758
|
switch (lighting.lightType) {
|
|
1759
1759
|
case 0:
|
|
@@ -1767,14 +1767,20 @@ DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
|
1767
1767
|
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
1768
1768
|
break;
|
|
1769
1769
|
}
|
|
1770
|
-
}
|
|
1771
1770
|
return lightColor;
|
|
1772
1771
|
}
|
|
1773
1772
|
`;
|
|
1773
|
+
var GOURAUD_FS = `uniform gouraudMaterialUniforms {
|
|
1774
|
+
uniform float ambient;
|
|
1775
|
+
uniform float diffuse;
|
|
1776
|
+
uniform float shininess;
|
|
1777
|
+
uniform vec3 specularColor;
|
|
1778
|
+
} material;
|
|
1779
|
+
`;
|
|
1774
1780
|
|
|
1775
1781
|
// dist/modules/lighting/gouraud-material/gouraud-material.js
|
|
1776
1782
|
var gouraudMaterial = {
|
|
1777
|
-
name: "
|
|
1783
|
+
name: "gouraudMaterial",
|
|
1778
1784
|
// Note these are switched between phong and gouraud
|
|
1779
1785
|
vs: GOURAUD_VS,
|
|
1780
1786
|
fs: GOURAUD_FS,
|
|
@@ -1846,6 +1852,8 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
|
|
|
1846
1852
|
vec3 lightColor = vec3(0, 0, 0);
|
|
1847
1853
|
vec3 surfaceColor = vec3(0, 0, 0);
|
|
1848
1854
|
if (lighting.enabled == 0) {
|
|
1855
|
+
return lightColor;
|
|
1856
|
+
}
|
|
1849
1857
|
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
1850
1858
|
switch (lighting.lightType) {
|
|
1851
1859
|
case 0:
|
|
@@ -1859,14 +1867,13 @@ DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
|
1859
1867
|
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
1860
1868
|
break;
|
|
1861
1869
|
}
|
|
1862
|
-
}
|
|
1863
1870
|
return lightColor;
|
|
1864
1871
|
}
|
|
1865
1872
|
`;
|
|
1866
1873
|
|
|
1867
1874
|
// dist/modules/lighting/phong-material/phong-material.js
|
|
1868
1875
|
var phongMaterial = {
|
|
1869
|
-
name: "
|
|
1876
|
+
name: "phongMaterial",
|
|
1870
1877
|
// Note these are switched between phong and gouraud
|
|
1871
1878
|
vs: PHONG_VS,
|
|
1872
1879
|
fs: PHONG_FS,
|