Skip to content

Commit 8514907

Browse files
committed
32 lights plus fstring correction
1 parent eb8024b commit 8514907

16 files changed

+66
-134
lines changed

GlowScriptOffline/glowscript_libraries/RScompiler.3.2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GlowScriptOffline/glowscript_libraries/compiler.3.2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GlowScriptOffline/glowscript_libraries/glow.3.2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GlowScriptOffline3.2.zip

-79 Bytes
Binary file not shown.

lib/compiling/GScompiler.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ where compile() was called, in untrusted/run.js.
335335
backquote = false // ` used in JavaScript
336336
var backslash = false
337337
var previouscontinuedline = continuedline
338-
var processedtriplequote = false
338+
var fstring = false
339339
for (var i=0; i<line.length; i++) { // inspect each character in the line
340340
var previousquote = singlequote || doublequote || triplequote
341341
// If there are triple quotes we stay in this loop to collect the entire string
@@ -361,25 +361,32 @@ where compile() was called, in untrusted/run.js.
361361
break
362362
case "(":
363363
if (singlequote || doublequote || triplequote || (backquote && lang == 'javascript') ) {
364+
if (braces == 1) break
364365
line = line.slice(0,i)+string_insert+line.slice(i+1)
365366
i += string_insert.length-1
366367
}
367368
break
369+
case "{":
370+
if (fstring) braces++
371+
break
372+
case "}":
373+
if (fstring && braces) braces--
374+
break
368375
case "'":
369376
case '"':
377+
if (i > 0 && line[i-1] == 'f') fstring = true
370378
if (i <= line.length-3 && line[i+1] == char && line[i+2] == char) { // ''' or """
371379
if (lang == 'javascript') throw new Error("JavaScript doesn't recognize triple quotes.")
372380
triplequote = !triplequote
373-
processedtriplequote = true
374381
i += 2
375382
} else if (char == "'") {
376-
if (!doublequote && !triplequote) {
377-
singlequote = !singlequote
378-
}
383+
if (!doublequote && !triplequote) {
384+
singlequote = !singlequote
385+
} else fstring = false
379386
} else if (char == '"') { // "
380387
if (!singlequote && !triplequote) {
381388
doublequote = !doublequote
382-
}
389+
} else fstring = false
383390
} else if (char == "`") { // ` used in JavaScript
384391
if (backquote) backquote = !backquote
385392
}
@@ -879,7 +886,7 @@ where compile() was called, in untrusted/run.js.
879886
'cone', 'pyramid', 'sphere', 'simple_sphere', 'arrow', 'curve', 'points', 'paths',
880887
'shapes', 'helix', 'ring', 'compound', 'vertex', 'triangle', 'quad', 'label',
881888
'distant_light', 'local_light', 'attach_trail', 'attach_arrow', 'text', 'extrusion',
882-
'wtext', 'winput', 'radio', 'checkbox', 'button', 'slider', 'menu', 'input',
889+
'wtext', 'winput', 'radio', 'checkbox', 'button', 'slider', 'menu', 'input', 'js_generator', 'yield',
883890
'mag', 'mag2', 'norm', 'hat', 'dot', 'cross', 'proj', 'diff_angle', 'abs', 'filter',
884891
'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'atan2', 'exp', 'log', 'pow', 'sqrt',
885892
'ceil', 'floor', 'sign', 'round', 'max', 'min', 'random', "factorial", "combin"]
@@ -1178,11 +1185,9 @@ where compile() was called, in untrusted/run.js.
11781185
program = program.slice(0,sc)+s+program.slice(sc,program.length)
11791186
}
11801187

1181-
// October 2021: Safari gives a CORS error when attempting to call input() in primitives.js,
1182-
// and it looks like Chrome will also start doing this. For now (version 3.1), we leave the
1183-
// copy of input() in primitives.js, to cater to existing exported programs that call input(),
1184-
// though those exported programs will eventually break, lacking the copy we now insert into
1185-
// exported code.
1188+
// October 2021: Safari gave a CORS error when attempting to call input() when it was in primitives.js,
1189+
// and it looks like Chrome will also start doing this. So starting with version 3.2, we insert the
1190+
// input function into the user's program:
11861191
if (program.indexOf('input') >= 0) { // if user code invokes input(), insert the function:
11871192
let s = "scene = canvas();\n"
11881193
let sc = program.indexOf(s) + s.length

lib/glow/WebGLRenderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
// Place these statements here rather than inside the render function,
3737
// to avoid repeated garbage collection. However, seemed to make little difference.
38-
var MAX_LIGHTS = 8 // Apparently this is the maximum number of lights supported by WebGL 1
38+
var MAX_LIGHTS = 32
3939
var light_pos = new Float32Array( MAX_LIGHTS*4 )
4040
var light_color = new Float32Array( MAX_LIGHTS*3 )
4141
var light_ambient = new Float32Array( 3 )
@@ -608,7 +608,7 @@
608608

609609
// Transform lights into eye space
610610
for (var i=0; i<light_color.length; i++) light_color[i] = 0 // initialize lights to black
611-
var light_count = Math.min(cvs.lights.length, MAX_LIGHTS)
611+
var light_count = cvs.lights.length
612612
for(var i=0; i<light_count; i++) {
613613
var light = cvs.lights[i]
614614
if (!light.visible) continue

lib/glow/primitives.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,6 +2340,7 @@
23402340
if (!(this instanceof distant_light)) return new distant_light(args) // so distant_light() is like new distant_light()
23412341
if (args.direction === undefined) throw new Error("Must specify the distant_light direction.")
23422342
init(this, args)
2343+
if (this.canvas.lights.length === 32) throw new Error('The number of lights is limited to 32.')
23432344
this.canvas.lights.push(this)
23442345
}
23452346
property.declare( distant_light.prototype, {
@@ -2354,6 +2355,7 @@
23542355
if (!(this instanceof local_light)) return new local_light(args) // so local_light() is like new local_light()
23552356
if (args.pos === undefined) throw new Error("Must specify the local_light position.")
23562357
init(this, args)
2358+
if (this.canvas.lights.length === 32) throw new Error('The number of lights is limited to 32.')
23572359
this.canvas.lights.push(this)
23582360
}
23592361
property.declare( local_light.prototype, {

lib/glow/shaders.gen.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/RScompiler.3.2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/compiler.3.2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/glow.3.2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shaders/opaque_render_fragment.shader

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ precision mediump float;
77
#endif
88

99
uniform int light_count;
10-
uniform vec4 light_pos[8];
11-
uniform vec3 light_color[8];
10+
uniform vec4 light_pos[32];
11+
uniform vec3 light_color[32];
1212
uniform vec3 light_ambient;
1313
#define LP(i) light_pos[i]
1414
#define LC(i) light_color[i]
@@ -69,26 +69,11 @@ void lightAt()
6969
}
7070

7171
color = light_ambient * diffuse_color;
72-
73-
// It was necessary to restructure this shader completely in order to
74-
// run on the Samsung Galaxy S3 smartphone. Apparently its compiler
75-
// does not handle for loops correctly. An Asus Android tablet was ok.
76-
if (light_count == 0) return;
77-
calc_color(LP(0), LC(0));
78-
if (light_count == 1) return;
79-
calc_color(LP(1), LC(1));
80-
if (light_count == 2) return;
81-
calc_color(LP(2), LC(2));
82-
if (light_count == 3) return;
83-
calc_color(LP(3), LC(3));
84-
if (light_count == 4) return;
85-
calc_color(LP(4), LC(4));
86-
if (light_count == 5) return;
87-
calc_color(LP(5), LC(5));
88-
if (light_count == 6) return;
89-
calc_color(LP(6), LC(6));
90-
if (light_count == 7) return;
91-
calc_color(LP(7), LC(7));
72+
73+
for (int i=0; i<100; i++) { // for cannot test against a variable
74+
if (i == light_count) break;
75+
calc_color(LP(i), LC(i));
76+
}
9277
}
9378

9479
void main(void) {

shaders/peel_color_fragmentC1.shader

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ precision mediump float;
77
#endif
88

99
uniform int light_count;
10-
uniform vec4 light_pos[8];
11-
uniform vec3 light_color[8];
10+
uniform vec4 light_pos[32];
11+
uniform vec3 light_color[32];
1212
uniform vec3 light_ambient;
1313
#define LP(i) light_pos[i]
1414
#define LC(i) light_color[i]
@@ -70,26 +70,11 @@ void lightAt()
7070
}
7171

7272
color = light_ambient * diffuse_color;
73-
74-
// It was necessary to restructure this shader completely in order to
75-
// run on the Samsung Galaxy S3 smartphone. Apparently its compiler
76-
// does not handle for loops correctly. An Asus Android tablet was ok.
77-
if (light_count == 0) return;
78-
calc_color(LP(0), LC(0));
79-
if (light_count == 1) return;
80-
calc_color(LP(1), LC(1));
81-
if (light_count == 2) return;
82-
calc_color(LP(2), LC(2));
83-
if (light_count == 3) return;
84-
calc_color(LP(3), LC(3));
85-
if (light_count == 4) return;
86-
calc_color(LP(4), LC(4));
87-
if (light_count == 5) return;
88-
calc_color(LP(5), LC(5));
89-
if (light_count == 6) return;
90-
calc_color(LP(6), LC(6));
91-
if (light_count == 7) return;
92-
calc_color(LP(7), LC(7));
73+
74+
for (int i=0; i<100; i++) { // for cannot test against a variable
75+
if (i == light_count) break;
76+
calc_color(LP(i), LC(i));
77+
}
9378
}
9479

9580
ivec4 encode(float k) { // assumes k is >= 0

shaders/peel_color_fragmentC2.shader

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ precision mediump float;
77
#endif
88

99
uniform int light_count;
10-
uniform vec4 light_pos[8];
11-
uniform vec3 light_color[8];
10+
uniform vec4 light_pos[32];
11+
uniform vec3 light_color[32];
1212
uniform vec3 light_ambient;
1313
#define LP(i) light_pos[i]
1414
#define LC(i) light_color[i]
@@ -73,25 +73,10 @@ void lightAt()
7373

7474
color = light_ambient * diffuse_color;
7575

76-
// It was necessary to restructure this shader completely in order to
77-
// run on the Samsung Galaxy S3 smartphone. Apparently its compiler
78-
// does not handle for loops correctly. An Asus Android tablet was ok.
79-
if (light_count == 0) return;
80-
calc_color(LP(0), LC(0));
81-
if (light_count == 1) return;
82-
calc_color(LP(1), LC(1));
83-
if (light_count == 2) return;
84-
calc_color(LP(2), LC(2));
85-
if (light_count == 3) return;
86-
calc_color(LP(3), LC(3));
87-
if (light_count == 4) return;
88-
calc_color(LP(4), LC(4));
89-
if (light_count == 5) return;
90-
calc_color(LP(5), LC(5));
91-
if (light_count == 6) return;
92-
calc_color(LP(6), LC(6));
93-
if (light_count == 7) return;
94-
calc_color(LP(7), LC(7));
76+
for (int i=0; i<100; i++) { // for cannot test against a variable
77+
if (i == light_count) break;
78+
calc_color(LP(i), LC(i));
79+
}
9580
}
9681

9782
ivec4 encode(float k) { // assumes k is >= 0

shaders/peel_color_fragmentC3.shader

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ precision mediump float;
77
#endif
88

99
uniform int light_count;
10-
uniform vec4 light_pos[8];
11-
uniform vec3 light_color[8];
10+
uniform vec4 light_pos[32];
11+
uniform vec3 light_color[32];
1212
uniform vec3 light_ambient;
1313
#define LP(i) light_pos[i]
1414
#define LC(i) light_color[i]
@@ -72,26 +72,11 @@ void lightAt()
7272
}
7373

7474
color = light_ambient * diffuse_color;
75-
76-
// It was necessary to restructure this shader completely in order to
77-
// run on the Samsung Galaxy S3 smartphone. Apparently its compiler
78-
// does not handle for loops correctly. An Asus Android tablet was ok.
79-
if (light_count == 0) return;
80-
calc_color(LP(0), LC(0));
81-
if (light_count == 1) return;
82-
calc_color(LP(1), LC(1));
83-
if (light_count == 2) return;
84-
calc_color(LP(2), LC(2));
85-
if (light_count == 3) return;
86-
calc_color(LP(3), LC(3));
87-
if (light_count == 4) return;
88-
calc_color(LP(4), LC(4));
89-
if (light_count == 5) return;
90-
calc_color(LP(5), LC(5));
91-
if (light_count == 6) return;
92-
calc_color(LP(6), LC(6));
93-
if (light_count == 7) return;
94-
calc_color(LP(7), LC(7));
75+
76+
for (int i=0; i<100; i++) { // for cannot test against a variable
77+
if (i == light_count) break;
78+
calc_color(LP(i), LC(i));
79+
}
9580
}
9681

9782
ivec4 encode(float k) { // assumes k is >= 0

shaders/peel_color_fragmentC4.shader

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ precision mediump float;
77
#endif
88

99
uniform int light_count;
10-
uniform vec4 light_pos[8];
11-
uniform vec3 light_color[8];
10+
uniform vec4 light_pos[32];
11+
uniform vec3 light_color[32];
1212
uniform vec3 light_ambient;
1313
#define LP(i) light_pos[i]
1414
#define LC(i) light_color[i]
@@ -71,26 +71,11 @@ void lightAt()
7171
}
7272

7373
color = light_ambient * diffuse_color;
74-
75-
// It was necessary to restructure this shader completely in order to
76-
// run on the Samsung Galaxy S3 smartphone. Apparently its compiler
77-
// does not handle for loops correctly. An Asus Android tablet was ok.
78-
if (light_count == 0) return;
79-
calc_color(LP(0), LC(0));
80-
if (light_count == 1) return;
81-
calc_color(LP(1), LC(1));
82-
if (light_count == 2) return;
83-
calc_color(LP(2), LC(2));
84-
if (light_count == 3) return;
85-
calc_color(LP(3), LC(3));
86-
if (light_count == 4) return;
87-
calc_color(LP(4), LC(4));
88-
if (light_count == 5) return;
89-
calc_color(LP(5), LC(5));
90-
if (light_count == 6) return;
91-
calc_color(LP(6), LC(6));
92-
if (light_count == 7) return;
93-
calc_color(LP(7), LC(7));
74+
75+
for (int i=0; i<100; i++) { // for cannot test against a variable
76+
if (i == light_count) break;
77+
calc_color(LP(i), LC(i));
78+
}
9479
}
9580

9681
ivec4 encode(float k) { // assumes k is >= 0

0 commit comments

Comments
 (0)