Skip to content

Commit cb38afc

Browse files
committed
Performance improvements
Significant performance boost for WebGL (regression v2.0), and additional performance enhancements across all shader variants. Disabling lights by setting light intensity to 0 is no longer advised. The removal of this check within the shader is attributed to its lack of tangible benefits.
1 parent 6081e72 commit cb38afc

5 files changed

Lines changed: 45 additions & 42 deletions

File tree

construct-addon/addon.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"supported-renderers": ["webgl","webgl2","webgpu"],
55
"name": "NormalMap32",
66
"id": "normalmap32",
7-
"version": "2.0.0.0",
7+
"version": "2.1.0.0",
88
"author": "Everade",
99
"website": "https://www.construct.net/make-games/addons/898/normalmap32",
1010
"documentation": "https://www.construct.net/make-games/addons/898/normalmap32/documentation",

construct-addon/effect.fx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,15 +464,16 @@ void main(void) {
464464
normal.xy /= vec2(normalScaleX,normalScaleY);
465465
normal.xy = rotate(normal.xy, -normalAngle * PI180);
466466

467+
vec2 fragCoord = gl_FragCoord.xy / iResolution;
468+
float aspectRatio = iResolution.x / iResolution.y;
467469
int lightMax = int(clamp(lightMaxID, 0.0, 32.0));
468470
vec3 ambient = ambientColor * ambientIntensity * 2.0;
469471
vec3 sum = vec3(back.rgb * ambient);
470472

471473
for (int i = 0; i < 32; i++) {
472474
if (i >= lightMax) break;
473-
if (lightIntensity[i] == 0.0) continue;
474-
vec3 lightDir = vec3(lightPos[i].xy - gl_FragCoord.xy / iResolution, lightPos[i].z);
475-
lightDir.x *= iResolution.x / iResolution.y;
475+
vec3 lightDir = vec3(lightPos[i].xy - fragCoord, lightPos[i].z);
476+
lightDir.x *= aspectRatio;
476477
float D = length(lightDir);
477478
D = mix(D, 1000.0, step(lightClamp[i], D));
478479
vec3 L = normalize(lightDir);

construct-addon/effect.webgl2.fx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,15 +472,16 @@ void main(void) {
472472
normal.xy /= vec2(normalScaleX,normalScaleY);
473473
normal.xy = rotate(normal.xy, -normalAngle * PI180);
474474

475+
vec2 fragCoord = gl_FragCoord.xy / iResolution;
476+
float aspectRatio = iResolution.x / iResolution.y;
475477
int lightMax = int(clamp(lightMaxID, 0.0, 32.0));
476478
vec3 ambient = ambientColor * ambientIntensity * 2.0;
477479
vec3 sum = vec3(back.rgb * ambient);
478480

479481
for (int i = 0; i < 32; i++) {
480482
if (i >= lightMax) break;
481-
if (lightIntensity[i] == 0.0) continue;
482-
vec3 lightDir = vec3(lightPos[i].xy - gl_FragCoord.xy / iResolution, lightPos[i].z);
483-
lightDir.x *= iResolution.x / iResolution.y;
483+
vec3 lightDir = vec3(lightPos[i].xy - fragCoord, lightPos[i].z);
484+
lightDir.x *= aspectRatio;
484485
float D = length(lightDir);
485486
D = mix(D, 1000.0, step(lightClamp[i], D));
486487
vec3 L = normalize(lightDir);

construct-addon/effect.wgsl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,15 +477,16 @@ fn main(input : FragmentInput) -> FragmentOutput {
477477
normal = vec3<f32>(normal.x / shaderParams.normalScaleX, normal.y / shaderParams.normalScaleY, normal.z);
478478
normal = vec3<f32>(rotate(normal.xy, -shaderParams.normalAngle * PI180), normal.z);
479479

480+
let fragCoord: vec2<f32> = input.fragPos.xy / iResolution;
481+
let aspectRatio: f32 = iResolution.x / iResolution.y;
480482
let lightMax: i32 = i32(clamp(shaderParams.lightMaxID, 0.0, 32.0));
481483
let ambient: vec3<f32> = shaderParams.ambientColor * shaderParams.ambientIntensity * 2.0;
482484
var sum : vec3<f32> = vec3<f32>(back.rgb * ambient);
483485

484486
for (var i : i32 = 0; i < 32; i++) {
485487
if (i >= lightMax) { break; }
486-
if (lightIntensity[i] == 0.0) { continue; }
487-
var light : vec3<f32> = vec3<f32>(lightPos[i].xy - input.fragPos.xy / iResolution, lightPos[i].z);
488-
light.x *= iResolution.x / iResolution.y;
488+
var light : vec3<f32> = vec3<f32>(lightPos[i].xy - fragCoord, lightPos[i].z);
489+
light.x *= aspectRatio;
489490
var D : f32 = length(light);
490491
D = mix(D, 1000.0, step(lightClamp[i], D));
491492
var L : vec3<f32> = normalize(light);

construct-addon/lang/en-US.json

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
},
4343
"light-1-intensity-01":{
4444
"name": "Light 1 Intensity [008]",
45-
"desc": "Light 1 Intensity. OFF (0) improves shader performance"
45+
"desc": "Light 1 Intensity. OFF (0)"
4646
},
4747
"light-1-pos-x":{
4848
"name": "Light 1 X Position [009]",
@@ -74,7 +74,7 @@
7474
},
7575
"light-2-intensity-01":{
7676
"name": "Light 2 Intensity [016]",
77-
"desc": "Light 2 Intensity. OFF (0) improves shader performance"
77+
"desc": "Light 2 Intensity. OFF (0)"
7878
},
7979
"light-2-pos-x":{
8080
"name": "Light 2 X Position [017]",
@@ -106,7 +106,7 @@
106106
},
107107
"light-3-intensity-01":{
108108
"name": "Light 3 Intensity [024]",
109-
"desc": "Light 3 Intensity. OFF (0) improves shader performance"
109+
"desc": "Light 3 Intensity. OFF (0)"
110110
},
111111
"light-3-pos-x":{
112112
"name": "Light 3 X Position [025]",
@@ -138,7 +138,7 @@
138138
},
139139
"light-4-intensity-01":{
140140
"name": "Light 4 Intensity [032]",
141-
"desc": "Light 4 Intensity. OFF (0) improves shader performance"
141+
"desc": "Light 4 Intensity. OFF (0)"
142142
},
143143
"light-4-pos-x":{
144144
"name": "Light 4 X Position [033]",
@@ -170,7 +170,7 @@
170170
},
171171
"light-5-intensity-01":{
172172
"name": "Light 5 Intensity [040]",
173-
"desc": "Light 5 Intensity. OFF (0) improves shader performance"
173+
"desc": "Light 5 Intensity. OFF (0)"
174174
},
175175
"light-5-pos-x":{
176176
"name": "Light 5 X Position [041]",
@@ -202,7 +202,7 @@
202202
},
203203
"light-6-intensity-01":{
204204
"name": "Light 6 Intensity [048]",
205-
"desc": "Light 6 Intensity. OFF (0) improves shader performance"
205+
"desc": "Light 6 Intensity. OFF (0)"
206206
},
207207
"light-6-pos-x":{
208208
"name": "Light 6 X Position [049]",
@@ -234,7 +234,7 @@
234234
},
235235
"light-7-intensity-01":{
236236
"name": "Light 7 Intensity [056]",
237-
"desc": "Light 7 Intensity. OFF (0) improves shader performance"
237+
"desc": "Light 7 Intensity. OFF (0)"
238238
},
239239
"light-7-pos-x":{
240240
"name": "Light 7 X Position [057]",
@@ -266,7 +266,7 @@
266266
},
267267
"light-8-intensity-01":{
268268
"name": "Light 8 Intensity [064]",
269-
"desc": "Light 8 Intensity. OFF (0) improves shader performance"
269+
"desc": "Light 8 Intensity. OFF (0)"
270270
},
271271
"light-8-pos-x":{
272272
"name": "Light 8 X Position [065]",
@@ -298,7 +298,7 @@
298298
},
299299
"light-9-intensity-01":{
300300
"name": "Light 9 Intensity [072]",
301-
"desc": "Light 9 Intensity. OFF (0) improves shader performance"
301+
"desc": "Light 9 Intensity. OFF (0)"
302302
},
303303
"light-9-pos-x":{
304304
"name": "Light 9 X Position [073]",
@@ -330,7 +330,7 @@
330330
},
331331
"light-10-intensity-01":{
332332
"name": "Light 10 Intensity [080]",
333-
"desc": "Light 10 Intensity. OFF (0) improves shader performance"
333+
"desc": "Light 10 Intensity. OFF (0)"
334334
},
335335
"light-10-pos-x":{
336336
"name": "Light 10 X Position [081]",
@@ -362,7 +362,7 @@
362362
},
363363
"light-11-intensity-01":{
364364
"name": "Light 11 Intensity [088]",
365-
"desc": "Light 11 Intensity. OFF (0) improves shader performance"
365+
"desc": "Light 11 Intensity. OFF (0)"
366366
},
367367
"light-11-pos-x":{
368368
"name": "Light 11 X Position [089]",
@@ -394,7 +394,7 @@
394394
},
395395
"light-12-intensity-01":{
396396
"name": "Light 12 Intensity [096]",
397-
"desc": "Light 12 Intensity. OFF (0) improves shader performance"
397+
"desc": "Light 12 Intensity. OFF (0)"
398398
},
399399
"light-12-pos-x":{
400400
"name": "Light 12 X Position [097]",
@@ -426,7 +426,7 @@
426426
},
427427
"light-13-intensity-01":{
428428
"name": "Light 13 Intensity [104]",
429-
"desc": "Light 13 Intensity. OFF (0) improves shader performance"
429+
"desc": "Light 13 Intensity. OFF (0)"
430430
},
431431
"light-13-pos-x":{
432432
"name": "Light 13 X Position [105]",
@@ -458,7 +458,7 @@
458458
},
459459
"light-14-intensity-01":{
460460
"name": "Light 14 Intensity [112]",
461-
"desc": "Light 14 Intensity. OFF (0) improves shader performance"
461+
"desc": "Light 14 Intensity. OFF (0)"
462462
},
463463
"light-14-pos-x":{
464464
"name": "Light 14 X Position [113]",
@@ -490,7 +490,7 @@
490490
},
491491
"light-15-intensity-01":{
492492
"name": "Light 15 Intensity [120]",
493-
"desc": "Light 15 Intensity. OFF (0) improves shader performance"
493+
"desc": "Light 15 Intensity. OFF (0)"
494494
},
495495
"light-15-pos-x":{
496496
"name": "Light 15 X Position [121]",
@@ -522,7 +522,7 @@
522522
},
523523
"light-16-intensity-01":{
524524
"name": "Light 16 Intensity [128]",
525-
"desc": "Light 16 Intensity. OFF (0) improves shader performance"
525+
"desc": "Light 16 Intensity. OFF (0)"
526526
},
527527
"light-16-pos-x":{
528528
"name": "Light 16 X Position [129]",
@@ -554,7 +554,7 @@
554554
},
555555
"light-17-intensity-01":{
556556
"name": "Light 17 Intensity [136]",
557-
"desc": "Light 17 Intensity. OFF (0) improves shader performance"
557+
"desc": "Light 17 Intensity. OFF (0)"
558558
},
559559
"light-17-pos-x":{
560560
"name": "Light 17 X Position [137]",
@@ -586,7 +586,7 @@
586586
},
587587
"light-18-intensity-01":{
588588
"name": "Light 18 Intensity [144]",
589-
"desc": "Light 18 Intensity. OFF (0) improves shader performance"
589+
"desc": "Light 18 Intensity. OFF (0)"
590590
},
591591
"light-18-pos-x":{
592592
"name": "Light 18 X Position [145]",
@@ -618,7 +618,7 @@
618618
},
619619
"light-19-intensity-01":{
620620
"name": "Light 19 Intensity [152]",
621-
"desc": "Light 19 Intensity. OFF (0) improves shader performance"
621+
"desc": "Light 19 Intensity. OFF (0)"
622622
},
623623
"light-19-pos-x":{
624624
"name": "Light 19 X Position [153]",
@@ -650,7 +650,7 @@
650650
},
651651
"light-20-intensity-01":{
652652
"name": "Light 20 Intensity [160]",
653-
"desc": "Light 20 Intensity. OFF (0) improves shader performance"
653+
"desc": "Light 20 Intensity. OFF (0)"
654654
},
655655
"light-20-pos-x":{
656656
"name": "Light 20 X Position [161]",
@@ -682,7 +682,7 @@
682682
},
683683
"light-21-intensity-01":{
684684
"name": "Light 21 Intensity [168]",
685-
"desc": "Light 21 Intensity. OFF (0) improves shader performance"
685+
"desc": "Light 21 Intensity. OFF (0)"
686686
},
687687
"light-21-pos-x":{
688688
"name": "Light 21 X Position [169]",
@@ -714,7 +714,7 @@
714714
},
715715
"light-22-intensity-01":{
716716
"name": "Light 22 Intensity [176]",
717-
"desc": "Light 22 Intensity. OFF (0) improves shader performance"
717+
"desc": "Light 22 Intensity. OFF (0)"
718718
},
719719
"light-22-pos-x":{
720720
"name": "Light 22 X Position [177]",
@@ -746,7 +746,7 @@
746746
},
747747
"light-23-intensity-01":{
748748
"name": "Light 23 Intensity [184]",
749-
"desc": "Light 23 Intensity. OFF (0) improves shader performance"
749+
"desc": "Light 23 Intensity. OFF (0)"
750750
},
751751
"light-23-pos-x":{
752752
"name": "Light 23 X Position [185]",
@@ -778,7 +778,7 @@
778778
},
779779
"light-24-intensity-01":{
780780
"name": "Light 24 Intensity [192]",
781-
"desc": "Light 24 Intensity. OFF (0) improves shader performance"
781+
"desc": "Light 24 Intensity. OFF (0)"
782782
},
783783
"light-24-pos-x":{
784784
"name": "Light 24 X Position [193]",
@@ -810,7 +810,7 @@
810810
},
811811
"light-25-intensity-01":{
812812
"name": "Light 25 Intensity [200]",
813-
"desc": "Light 25 Intensity. OFF (0) improves shader performance"
813+
"desc": "Light 25 Intensity. OFF (0)"
814814
},
815815
"light-25-pos-x":{
816816
"name": "Light 25 X Position [201]",
@@ -842,7 +842,7 @@
842842
},
843843
"light-26-intensity-01":{
844844
"name": "Light 26 Intensity [208]",
845-
"desc": "Light 26 Intensity. OFF (0) improves shader performance"
845+
"desc": "Light 26 Intensity. OFF (0)"
846846
},
847847
"light-26-pos-x":{
848848
"name": "Light 26 X Position [209]",
@@ -874,7 +874,7 @@
874874
},
875875
"light-27-intensity-01":{
876876
"name": "Light 27 Intensity [216]",
877-
"desc": "Light 27 Intensity. OFF (0) improves shader performance"
877+
"desc": "Light 27 Intensity. OFF (0)"
878878
},
879879
"light-27-pos-x":{
880880
"name": "Light 27 X Position [217]",
@@ -906,7 +906,7 @@
906906
},
907907
"light-28-intensity-01":{
908908
"name": "Light 28 Intensity [224]",
909-
"desc": "Light 28 Intensity. OFF (0) improves shader performance"
909+
"desc": "Light 28 Intensity. OFF (0)"
910910
},
911911
"light-28-pos-x":{
912912
"name": "Light 28 X Position [225]",
@@ -938,7 +938,7 @@
938938
},
939939
"light-29-intensity-01":{
940940
"name": "Light 29 Intensity [232]",
941-
"desc": "Light 29 Intensity. OFF (0) improves shader performance"
941+
"desc": "Light 29 Intensity. OFF (0)"
942942
},
943943
"light-29-pos-x":{
944944
"name": "Light 29 X Position [233]",
@@ -970,7 +970,7 @@
970970
},
971971
"light-30-intensity-01":{
972972
"name": "Light 30 Intensity [240]",
973-
"desc": "Light 30 Intensity. OFF (0) improves shader performance"
973+
"desc": "Light 30 Intensity. OFF (0)"
974974
},
975975
"light-30-pos-x":{
976976
"name": "Light 30 X Position [241]",
@@ -1002,7 +1002,7 @@
10021002
},
10031003
"light-31-intensity-01":{
10041004
"name": "Light 31 Intensity [248]",
1005-
"desc": "Light 31 Intensity. OFF (0) improves shader performance"
1005+
"desc": "Light 31 Intensity. OFF (0)"
10061006
},
10071007
"light-31-pos-x":{
10081008
"name": "Light 31 X Position [249]",
@@ -1034,7 +1034,7 @@
10341034
},
10351035
"light-32-intensity-01":{
10361036
"name": "Light 32 Intensity [256]",
1037-
"desc": "Light 32 Intensity. OFF (0) improves shader performance"
1037+
"desc": "Light 32 Intensity. OFF (0)"
10381038
},
10391039
"light-32-pos-x":{
10401040
"name": "Light 32 X Position [257]",

0 commit comments

Comments
 (0)